KodrAus / json_str

Rust library for tidy json string literals
Apache License 2.0
5 stars 0 forks source link

Cannot run binary built with json_str #5

Closed Mange closed 7 years ago

Mange commented 7 years ago
cargo new --bin json-str-test
cd json-str-test
echo 'json_str = "*"' >> Cargo.toml
// main.rs
#[macro_use]
extern crate json_str;

fn main() {
    println!("Hello, world!");
}
cargo run
#   Compiling json-str-test v0.1.0 (file:///Users/mange/tmp/json-str-test)
#    Finished debug [unoptimized + debuginfo] target(s) in 0.10 secs
#     Running `target/debug/json-str-test`
# Hello, world!

rustup run stable ./target/debug/json-str-test
# Hello, world!

./target/debug/json-str-test
# dyld: Library not loaded: @rpath/libstd-f5a209a9.dylib
#  Referenced from: /Users/mange/tmp/json-str-test/./target/debug/json-str-test
#  Reason: image not found
# zsh: trace trap  ./target/debug/json-str-test

Removing the extern crate json_str, this problem does not appear.

> otool -L ./target/debug/json-str-test
./target/debug/json-str-test:
    /Users/mange/tmp/json-str-test/target/debug/deps/libjson_str-01e27c904eba6a7a.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libstd-f5a209a9.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

> uname -a
Darwin Naiad.local 14.5.0 Darwin Kernel Version 14.5.0: Sun Sep 25 22:07:15 PDT 2016; root:xnu-2782.50.9~1/RELEASE_X86_64 x86_64 i386 MacBookPro11,3 Darwin

> rustc --version
rustc 1.14.0 (e8a012324 2016-12-16)

> rustup show
Default host: x86_64-apple-darwin

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.14.0 (e8a012324 2016-12-16)

> cargo --version
cargo 0.15.0-nightly (298a012 2016-12-20)

> cat Cargo.lock
[root]
name = "json-str-test"
version = "0.1.0"
dependencies = [
 "json_str 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "json_str"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum json_str 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "73d699063dfc2ee05f524a9dc49a77906e675c90580f4b7551545328ed14b961"

Is there anything else I can help you with? Is there something I need to do? It feels like I should be able to run the built executable without having a Rust ecosystem installed. This happens in release mode too.

KodrAus commented 7 years ago

Ah thanks for the bug report! Seems like the issue is that as a dylib Rust loads the libjson_str object and assumes it depends on libstd, so it tries to find it, but it's not in the deps, so fails.

I've opened a PR that builds both a static linked rlib for runtime and a dynamic linked dylib for the compiler plugin on the nightly channel. This seems to work on my machine for stable and nightly.

Do you mind taking that branch for a spin and see if that fixes your issue?

Mange commented 7 years ago

It seems to work! I tried with the 2c477618b2b77343bb5297738464afe0ffedc611 revision and I can now run the bin. :-)

> cargo build
    Updating git repository `https://github.com/KodrAus/json_str.git`
   Compiling json_str v0.4.0 (https://github.com/KodrAus/json_str.git?rev=2c477618b2b77343bb5297738464afe0ffedc611#2c477618)
   Compiling json-str-test v0.1.0 (file:///Users/mange/tmp/json-str-test)
    Finished debug [unoptimized + debuginfo] target(s) in 1.26 secs

> ./target/debug/json-str-test
Hello, world!

###

> rustup run nightly rustc --version
rustc 1.16.0-nightly (47c8d9fdc 2017-01-08)

> rustup run nightly cargo build
   Compiling json_str v0.4.0 (https://github.com/KodrAus/json_str.git?rev=2c477618b2b77343bb5297738464afe0ffedc611#2c477618)
   Compiling json-str-test v0.1.0 (file:///Users/mange/tmp/json-str-test)
    Finished debug [unoptimized + debuginfo] target(s) in 1.37 secs

> ./target/debug/json-str-test
Hello, world!

That was fast! Great job!

KodrAus commented 7 years ago

Glad to hear it worked! I've released this fix as 0.4.0 on crates.io.