servo / rust-mozjs

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

cargo test fails to build (linker error) on macOS #452

Closed zrzka closed 5 years ago

zrzka commented 5 years ago

I'm trying to use mozjs crate in one of my project and I'm encountering linker issues. It always fails with the following error message:

  = note: 0  0x10b3d9898  __assert_rtn + 129
          1  0x10b423bc4  archive::File<x86_64>::makeObjectFileForMember(archive::File<x86_64>::Entry const*) const + 1232
          2  0x10b422fa5  archive::File<x86_64>::justInTimeforEachAtom(char const*, ld::File::AtomHandler&) const + 141
          3  0x10b443f6d  ld::tool::InputFiles::searchLibraries(char const*, bool, bool, bool, ld::File::AtomHandler&) const + 249
          4  0x10b44f537  ld::tool::Resolver::resolveUndefines() + 151
          5  0x10b453389  ld::tool::Resolver::resolve() + 75
          6  0x10b3da6ea  main + 798
          7  0x7fff72745ed9  start + 1
          A linker snapshot was created at:
              /tmp/capture_stack-13154f8e018df84d-2019-01-19-142333.ld-snapshot
          ld: Assertion failed: (memberIndex != 0), function makeObjectFileForMember, file /Library/Caches/com.apple.xbs/Sources/ld64_Fall2018/ld64-409.12/src/ld/parsers/archive_file.cpp, line 383.
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

It has something to do with cdylib. Tried to create minimal reproducible example:

[package]
name = "foo"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["rlib", "cdylib"]

[dependencies]
mozjs = "0.10"

src/lib.rs contains just one line use mozjs;.

When I remove the whole [lib] section:

Hmm, weird. Even this doesn't work. Did checkout rust-mozjs repo and tried same commands there:

I checked your .travis.yml and followed all steps for osx like brew install autoconf@2.13 ccache llvm yasm, but still no luck.

I'm running macOS 10.14.3 (18D109) & Xcode 10.1 (10B61) & reinstalled Xcode command line tools.

Did you ever saw this error message? Any idea how this can be fixed? I've found couple of similar issues (Google), but none of those recommendations (like link toolchain frameworks to /Library/Frameworks) help.

jdm commented 5 years ago

I have never seen that error before :/

zrzka commented 5 years ago

There's another warning in the output (did overlook it before), which says:

ld: warning: ignoring file rust-mozjs/target/debug/build/mozjs-f51f5dceff420288/out/libjsglue.a,
file was built for archive which is not the architecture being linked (x86_64):
rust-mozjs/target/debug/build/mozjs-f51f5dceff420288/out/libjsglue.a

And lipo says:

Non-fat file: rust-mozjs/target/debug/build/mozjs-f51f5dceff420288/out/libjsglue.a
is architecture: x86_64
zrzka commented 5 years ago

Okay, had time to investigate more. I've found that the wrong ar (archiver) was used - because of the wrong PATH. Tools from different sources (system vs brew llvm vs brew binutils) were used.

There are two ways to fix this:

Both ways works fine with rlib & cdylib. It was a problem on my side, not rust-mozjs. Closing. Sorry for the noise.