Skip to content

Commit a21b93c

Browse files
committed
Clean up and clarify Android targeting code
Use the online NDK compiler docs at [0] as a reference to document some of the existing behavior and supplement with a linker argument. Don't rely on vague things like "x86 doesn't contain eabi" and just test for the architectures we are targeting in the Android-specific code. [0]: https://developer.android.com/ndk/guides/standalone_toolchain
1 parent 81146d0 commit a21b93c

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

Diff for: src/lib.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -1930,17 +1930,34 @@ impl Build {
19301930
}
19311931
}
19321932

1933-
// (x86 Android doesn't say "eabi")
1934-
if target.contains("-androideabi") && target.contains("v7") {
1935-
// -march=armv7-a handled above
1933+
// -march=armv7-a (handled above) and -mthumb (handled above) can be
1934+
// present separately or together. In the absence of an explicit --target,
1935+
// only -march=armv7-a targets armv7-none-linux-androideabi, only -mthumb
1936+
// targets thumb-non-linux-androideabi, while supplying both targets
1937+
// thumbv7-non-linux-androideabi. It is recommended to supply -mthumb to
1938+
// force the use of 16-bit Thumb-2 instructions instead of 32-bit ARM
1939+
// instructions.
1940+
// Source: https://developer.android.com/ndk/guides/standalone_toolchain
1941+
if (target.starts_with("thumbv7") || target.starts_with("armv7"))
1942+
&& target.contains("-androideabi")
1943+
{
19361944
cmd.args.push("-mthumb".into());
19371945
if !target.contains("neon") {
1938-
// On android we can guarantee some extra float instructions
1939-
// (specified in the android spec online)
1940-
// NEON guarantees even more; see below.
1946+
// On android we can guarantee some extra float instructions (per
1947+
// the online spec). NEON guarantees even more; see below.
19411948
cmd.args.push("-mfpu=vfpv3-d16".into());
19421949
}
19431950
cmd.args.push("-mfloat-abi=softfp".into());
1951+
1952+
// Android NDK link above says to make sure the following flag is
1953+
// passed to the linker to work around a CPU bug on some Cortex-A8
1954+
// implementations.
1955+
cmd.args.push("-Wl,--fix-cortex-a8".into());
1956+
}
1957+
1958+
if target.contains("neon") {
1959+
// This automatically forces the use of VFPv3-D32, per ARM specifications
1960+
cmd.args.push("-mfpu=neon-vfpv4".into());
19441961
}
19451962

19461963
// Looks like `musl-gcc` makes it hard for `-m32` to make its way
@@ -1951,10 +1968,6 @@ impl Build {
19511968
if target == "i686-unknown-linux-musl" || target == "i586-unknown-linux-musl" {
19521969
cmd.args.push("-Wl,-melf_i386".into());
19531970
}
1954-
1955-
if target.contains("neon") {
1956-
cmd.args.push("-mfpu=neon-vfpv4".into());
1957-
}
19581971
}
19591972
}
19601973

0 commit comments

Comments
 (0)