Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Add compatibility with android-9 #33211

Merged
merged 1 commit into from
Apr 28, 2016

Conversation

alexcrichton
Copy link
Member

The Gecko folks currently use Android API level 9 for their builds, so they're
requesting that we move back our minimum supported API level from 18 to 9. Turns
out, ABI-wise at least, there's not that many changes we need to take care of.
The ftruncate64 API appeared in android-12 and the log2 and log2f APIs
appeared in android-18. We can have a simple shim for ftruncate64 which falls
back on ftruncate and the log2 function can be approximated with just
ln(f) / ln(2).

This should at least get the standard library building on API level 9, although
the tests aren't quite happening there just yet. As we seem to be growing a
number of Android compatibility shims, they're now centralized in a common
sys::android module.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

// but hopefully that should be enough for now...

pub fn log2f32(f: f32) -> f32 {
f.ln() / 2.0f32.ln()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ln(2) can be precalculated and its value put into a constant to be as accurate as possible. I doubt the compiler does that for us (and certainly doesn’t in the debug builds).

Here’s a way more than enough digits of ln(2) to cover f64:

0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps std::f64::consts::LN_2 might help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, instead of dividing by std::f64::consts::LN_2 it would be possible to multiply by std::f64::consts::LOG2_E

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt the compiler does that for us (and certainly doesn’t in the debug builds).

FWIW, it does in release builds (using one of the constants is nicer of course).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, it does in release builds (using one of the constants is nicer of course).

Might not do it in the cross-compiling case, since I think it actually uses the host's (!) libm to do the calculation, which isn't necessarily valid in the cross-compiling case.

@nagisa
Copy link
Member

nagisa commented Apr 26, 2016

LGTM once the two comments are resolved.

@alexcrichton
Copy link
Member Author

@bors: r=nagisa 0be64f3ea384dfddbe5cec685d9cda13e3d2fd94

@bors
Copy link
Contributor

bors commented Apr 26, 2016

⌛ Testing commit 0be64f3 with merge 33ec2aa...

@bors
Copy link
Contributor

bors commented Apr 26, 2016

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member Author

@bors: r=nagisa 0e4ff0a

@bors
Copy link
Contributor

bors commented Apr 27, 2016

⌛ Testing commit 0e4ff0a with merge f25455d...

@bors
Copy link
Contributor

bors commented Apr 27, 2016

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member Author

@bors: r=nagisa 04b78c1

@bors
Copy link
Contributor

bors commented Apr 27, 2016

⌛ Testing commit 04b78c1 with merge 3b9f856...

@bors
Copy link
Contributor

bors commented Apr 27, 2016

💔 Test failed - auto-linux-64-x-android-t

The Gecko folks currently use Android API level 9 for their builds, so they're
requesting that we move back our minimum supported API level from 18 to 9. Turns
out, ABI-wise at least, there's not that many changes we need to take care of.
The `ftruncate64` API appeared in android-12 and the `log2` and `log2f` APIs
appeared in android-18. We can have a simple shim for `ftruncate64` which falls
back on `ftruncate` and the `log2` function can be approximated with just
`ln(f) / ln(2)`.

This should at least get the standard library building on API level 9, although
the tests aren't quite happening there just yet. As we seem to be growing a
number of Android compatibility shims, they're now centralized in a common
`sys::android` module.
@alexcrichton
Copy link
Member Author

@bors: r=nagisa c31e2e7

bors added a commit that referenced this pull request Apr 28, 2016
std: Add compatibility with android-9

The Gecko folks currently use Android API level 9 for their builds, so they're
requesting that we move back our minimum supported API level from 18 to 9. Turns
out, ABI-wise at least, there's not that many changes we need to take care of.
The `ftruncate64` API appeared in android-12 and the `log2` and `log2f` APIs
appeared in android-18. We can have a simple shim for `ftruncate64` which falls
back on `ftruncate` and the `log2` function can be approximated with just
`ln(f) / ln(2)`.

This should at least get the standard library building on API level 9, although
the tests aren't quite happening there just yet. As we seem to be growing a
number of Android compatibility shims, they're now centralized in a common
`sys::android` module.
@bors
Copy link
Contributor

bors commented Apr 28, 2016

⌛ Testing commit c31e2e7 with merge 02acf09...

@bors bors merged commit c31e2e7 into rust-lang:master Apr 28, 2016
@alexcrichton alexcrichton deleted the android-back-in-time branch May 2, 2016 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants