This is BS. I've now spent several hours trying to fix this and I don't get anywhere.
I cloned servo, went into components/servo and changed the crate-type to "dylib". That's all I did in regards to servo. Then I copied the resulting .so file to my desktop, just to see if I could use it as a standalone library. TLDR: I can't.
I created a new project with just an empty library with "extern crate servo" at the start. For reproducabilitys sake, I've put the repo here: https://github.com/fschutt/servodynamictest
First, I nuked the rustup cache, which is the only way that I got rid of the error message I showed earlier - because rust doesn't "get" that I want to use the servo version in the libservo.so file. Here is a "fix", but I can't figure out what this should mean? What is stage-0-tools? Is this specific to the rust compiler?? Apparently, it has to do something with this Fixme, but I am not sure what I should do about this - recompile the compiler? So i remove the rustup cache, because it's the only thing I can do right now:
rm -rf /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/*
That gets rid of the duplicated crate error. But now, rust can't find the standard library:
$ cargo build --release --verbose
Compiling servodynamictest v0.1.0 (file:///home/felix/Development/servodynamictest)
Running `/home/felix/Development/servodynamictest/target/release/build/servodynamictest-2444ab718ef9b803/build-script-build`
Running `rustc --crate-name servodynamictest src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=7a4ef19a9cf4a27a -C extra-filename=-7a4ef19a9cf4a27a --out-dir /home/felix/Development/servodynamictest/target/release/deps -L dependency=/home/felix/Development/servodynamictest/target/release/deps -L crate=/home/felix/Schreibtisch -l dylib=servo`
error[E0463]: can't find crate for `std`
error: aborting due to previous error
error: Could not compile `servodynamictest`.
Caused by:
process didn't exit successfully: `rustc --crate-name servodynamictest src/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=7a4ef19a9cf4a27a -C extra-filename=-7a4ef19a9cf4a27a --out-dir /home/felix/Development/servodynamictest/target/release/deps -L dependency=/home/felix/Development/servodynamictest/target/release/deps -L crate=/home/felix/Schreibtisch -l dylib=servo` (exit code: 101)
I found this (outdated) article: Where Is The Std Crate Located In A Rust Installation | newspaint
Using rustc --print sysroot
and then
find /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu -name 'libstd-*'
... I was able to print the paths to where the standard library is installed:
/home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/libstd-b54a6d28690b7929.so
Alright, I put this directory in the RUSTFLAGS before invoking cargo:
$ RUSTFLAGS="-L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib" cargo build --verbose --release
But now rust complains that it "can't find core
, which std
depends on":
Compiling servodynamictest v0.1.0 (file:///home/felix/Development/servodynamictest)
Running `rustc --crate-name build_script_build build.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=2444ab718ef9b803 -C extra-filename=-2444ab718ef9b803 --out-dir /home/felix/Development/servodynamictest/target/release/build/servodynamictest-2444ab718ef9b803 -L dependency=/home/felix/Development/servodynamictest/target/release/deps -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib`
error[E0463]: can't find crate for `core` which `std` depends on
error: aborting due to previous error
error: Could not compile `servodynamictest`.
Caused by:
process didn't exit successfully: `rustc --crate-name build_script_build build.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=2444ab718ef9b803 -C extra-filename=-2444ab718ef9b803 --out-dir /home/felix/Development/servodynamictest/target/release/build/servodynamictest-2444ab718ef9b803 -L dependency=/home/felix/Development/servodynamictest/target/release/deps -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib` (exit code: 101)
Why, just why? All I could find regarding this topic was this (outdated) stackoverflow discussion: rust - Cannot link against core library when cross compiling - Stack Overflow
But the solution proposed there doesn't work:
$ rustup target add x86_64-unknown-linux-gnu
error: component 'rust-std' for target 'x86_64-unknown-linux-gnu' is required for toolchain 'nightly-2017-10-01-x86_64-unknown-linux-gnu' and cannot be re-added
At this point I have no idea what this means. libcore is already installed, ffs!.
So I try locating libcore manually, again, via the find command
find /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu -name 'libcore*'
In the article linked above, the author gets two libraries listed: A .rlib file and the directory with the sources. This was after I executed rustup component add rust-src
. But I only get one:
`/home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore`
So what do I do now? I go in this directory and try to build it manually via cargo build --release
. Since I didn't switch the toolchain, this should work, right? Wrong! I add the /target/release
to the -L flag and get this:
$ RUSTFLAGS="-L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/target/release" cargo build --verbose --release
Compiling servodynamictest v0.1.0 (file:///home/felix/Development/servodynamictest)
Running `rustc --crate-name build_script_build build.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=2444ab718ef9b803 -C extra-filename=-2444ab718ef9b803 --out-dir /home/felix/Development/servodynamictest/target/release/build/servodynamictest-2444ab718ef9b803 -L dependency=/home/felix/Development/servodynamictest/target/release/deps -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/target/release`
error[E0460]: found possibly newer version of crate `core` which `std` depends on
|
= note: perhaps that crate needs to be recompiled?
= note: crate `core` path #1: /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/target/release/libcore.rlib
= note: crate `std` path #1: /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/libstd-b54a6d28690b7929.so
error: aborting due to previous error
error: Could not compile `servodynamictest`.
Caused by:
process didn't exit successfully: `rustc --crate-name build_script_build build.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=2444ab718ef9b803 -C extra-filename=-2444ab718ef9b803 --out-dir /home/felix/Development/servodynamictest/target/release/build/servodynamictest-2444ab718ef9b803 -L dependency=/home/felix/Development/servodynamictest/target/release/deps -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib -L /home/felix/.rustup/toolchains/nightly-2017-10-01-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/target/release` (exit code: 101)
How? I just recompiled it?! Yes, you can build dynamic libraries with Rust, but what sense does this make if you can't even use them! Statically linking everything is not a valid solution. Sorry for my tone.