servo / rust-mozjs

DEPRECATED - moved to servo/mozjs instead.
Mozilla Public License 2.0
293 stars 122 forks source link

Compilation for Android x86 fails #345

Closed vmx closed 7 years ago

vmx commented 7 years ago

I tried to compile rust-mozjs for Android x86. It fails with the error below. I suspect that there's a mismatch between the platform headers and the actual platform. On Android x86 c_char is i8 on ARM it's u8.

I have no clue, why it would expect an ARM-stlye u8 although I compile for x86. I'm happy to work on a fix if anyone tells me where to look.

$ PATH=$PATH:/home/vmx/src/rust/android/android-24-toolchain-x86/bin ANDROID_NDK=/home/vmx/src/rust/android/android-ndk-r12b cargo build --target i686-linux-android --verbose
       Fresh log v0.3.7
       Fresh num-traits v0.1.37
       Fresh lazy_static v0.2.5
       Fresh gcc v0.3.45
       Fresh libc v0.2.21
       Fresh pkg-config v0.3.9
       Fresh cmake v0.1.22
       Fresh heapsize v0.3.9
       Fresh libz-sys v1.0.13
       Fresh mozjs_sys v0.0.0 (https://github.com/servo/mozjs#98c3df63)
   Compiling js v0.1.4 (file:///tmp/rust-mozjs)
     Running `rustc --crate-name js src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=bf95172d2256808a -C extra-filename=-bf95172d2256808a --out-dir /tmp/rust-mozjs/target/i686-linux-android/debug/deps --target i686-linux-android -C ar=/home/vmx/src/rust/android/android-24-toolchain-x86/bin/i686-linux-android-ar -C linker=/home/vmx/src/rust/android/android-24-toolchain-x86/bin/i686-linux-android-gcc -L dependency=/tmp/rust-mozjs/target/i686-linux-android/debug/deps -L dependency=/tmp/rust-mozjs/target/debug/deps --extern lazy_static=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/liblazy_static-6512ce482ce46607.rlib --extern num_traits=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/libnum_traits-69f4129d46397118.rlib --extern mozjs_sys=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/libmozjs_sys-97826a5d9cd703db.rlib --extern log=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/liblog-d4c0e5c2504fbbea.rlib --extern heapsize=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/libheapsize-a0ca106bb4f4bbb6.rlib --extern libc=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/liblibc-5dc7b85e748840b4.rlib -L native=/tmp/rust-mozjs/target/i686-linux-android/debug/build/js-62abd7c6dbea0549/out/lib -l static=jsglue -L native=/tmp/rust-mozjs/target/i686-linux-android/debug/build/mozjs_sys-2cecbe7697181d13/out/js/src`
error[E0308]: mismatched types
  --> src/error.rs:24:11
   |
24 |     name: b"RUSTMSG_TYPE_ERROR\0" as *const _ as *const libc::c_char,
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
   |
   = help: here are some functions which might fulfill your needs:
           - .offset(...)
           - .wrapping_offset(...)

error[E0308]: mismatched types
  --> src/error.rs:25:13
   |
25 |     format: &ERROR_FORMAT_STRING_STRING as *const libc::c_char,
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
   |
   = help: here are some functions which might fulfill your needs:
           - .offset(...)
           - .wrapping_offset(...)

error[E0308]: mismatched types
  --> src/error.rs:32:11
   |
32 |     name: b"RUSTMSG_RANGE_ERROR\0" as *const _ as *const libc::c_char,
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
   |
   = help: here are some functions which might fulfill your needs:
           - .offset(...)
           - .wrapping_offset(...)

error[E0308]: mismatched types
  --> src/error.rs:33:13
   |
33 |     format: &ERROR_FORMAT_STRING_STRING as *const libc::c_char,
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
   |
   = help: here are some functions which might fulfill your needs:
           - .offset(...)
           - .wrapping_offset(...)

error: aborting due to 4 previous errors

error: Could not compile `js`.

Caused by:
  process didn't exit successfully: `rustc --crate-name js src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=bf95172d2256808a -C extra-filename=-bf95172d2256808a --out-dir /tmp/rust-mozjs/target/i686-linux-android/debug/deps --target i686-linux-android -C ar=/home/vmx/src/rust/android/android-24-toolchain-x86/bin/i686-linux-android-ar -C linker=/home/vmx/src/rust/android/android-24-toolchain-x86/bin/i686-linux-android-gcc -L dependency=/tmp/rust-mozjs/target/i686-linux-android/debug/deps -L dependency=/tmp/rust-mozjs/target/debug/deps --extern lazy_static=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/liblazy_static-6512ce482ce46607.rlib --extern num_traits=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/libnum_traits-69f4129d46397118.rlib --extern mozjs_sys=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/libmozjs_sys-97826a5d9cd703db.rlib --extern log=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/liblog-d4c0e5c2504fbbea.rlib --extern heapsize=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/libheapsize-a0ca106bb4f4bbb6.rlib --extern libc=/tmp/rust-mozjs/target/i686-linux-android/debug/deps/liblibc-5dc7b85e748840b4.rlib -L native=/tmp/rust-mozjs/target/i686-linux-android/debug/build/js-62abd7c6dbea0549/out/lib -l static=jsglue -L native=/tmp/rust-mozjs/target/i686-linux-android/debug/build/mozjs_sys-2cecbe7697181d13/out/js/src` (exit code: 101)
jdm commented 7 years ago

The issue is that the generated bindings use std::os::raw::c_char, and our code uses libc::c_char. In the past these types have been identical, and now they are not for some reason. https://github.com/rust-lang/rust/pull/40317 just merged four days ago, so rust-mozjs requires a more recent nightly version in order to avoid this problem. For Servo, this can be addressed by updating the contents of the rust-commit-hash file to make the build system use the given compiler version.

vmx commented 7 years ago

I've updated rust via rustup, my system is now on

nightly-x86_64-unknown-linux-gnu updated - rustc 1.17.0-nightly (ccce2c6eb 2017-03-27)

Which is after the commit https://github.com/rust-lang/rust/commit/24be89980e2e89404075fe463edae0f5db369251 mentioned above. The error is still the same.

jdm commented 7 years ago

Unless you are building rust-mozjs standalone, your local compiler (as updated by rustup) has no effect on the Servo build system. Are you building Servo (via ./mach build), or rust-mozjs (via cargo build)?

vmx commented 7 years ago

I'm building rust-mozjs standalone (it's all I care about atm). See the exact command I'm building with on the original bug description.

vmx commented 7 years ago

It builds now. My nightly build wasn't recent enough as as fix got merged with https://github.com/rust-lang/rust/pull/40867 just two days ago. Another rustup update got me to version rustc 1.17.0-nightly (e1cec5d4b 2017-03-29) which is recent enough. Thanks @jdm for finding that out.