Skip to content

setting $RUBY_STATIC doesn't seem to generate a statically linked library #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
coder543 opened this issue Jun 11, 2018 · 10 comments
Open

Comments

@coder543
Copy link

coder543 commented Jun 11, 2018

if I do echo $RUBY_STATIC in my environment, I get back 1, so the env var is set, but ruby-sys is still trying to link against libruby.so. ldd target/release/mylib.so shows the dynamic link to libruby.so, so I tried moving the dynamic library somewhere that it won't be on the path and rebuilding. Now, Rust complains that /usr/bin/ld: cannot find -lruby, which just shows what I thought was happening.

Looking at the build script, it seems to support the notion of linking against the Ruby library statically, but it doesn't seem to do that. Is this a working thing?

I'm on 64-bit Fedora 27.

@malept
Copy link
Contributor

malept commented Jun 11, 2018

Try this PR? #31

@coder543
Copy link
Author

I just now tried both #31 and #25, being sure to do a cargo clean to ensure that the new version of ruby-sys gets used, and ldd still shows a dynamic linkage to libruby.so which is rather confusing. To switch versions of ruby-sys, I created a patch in Cargo.toml like this:

[patch.crates-io]
ruby-sys = { git = "http://github.com/steveklabnik/ruby-sys", branch = "fix/static_build" }

@coder543
Copy link
Author

Maybe the patch wasn't working... I tried setting it to use the first revision of this git repository which would absolutely fail to compile, and it compiled just fine again.

@malept
Copy link
Contributor

malept commented Jun 11, 2018

It might be because I haven't done this in a while, but this is what I had to do to replace ruby-sys (as an example):

https://github.com/malept/rusty_blank/blob/4013243666c71899c303734794ed4f97b254979b/Cargo.toml#L25-L26

@coder543
Copy link
Author

Ok, so the problem with [patch] is that ruru is linking against 0.2.20, and the version in each of the branches was 0.3.0, so they were getting ignored. I cloned the PRs locally and modified their version numbers. #31 seems to have built without a dynamic linkage, which is good. #25 was giving me a linker error about relocation R_X86_64_PC32 against symbol __gmp_version' can not be used when making a shared object; recompile with -fPIC`

@malept
Copy link
Contributor

malept commented Jun 11, 2018

Yeah, I think #31 supercedes #25 at this point.

@coder543
Copy link
Author

It looks like the ruby-sys dependency was updated in ruru's Cargo.toml file, but then the updated version of ruru was never published to crates.io. I'll try out the [replace] syntax and see if that'll work even with a version mismatch.

It would be nice if #31 could get merged.

@coder543
Copy link
Author

Thanks for the help!

@coder543
Copy link
Author

Yeah, the [replace] syntax doesn't work.

error: no matching package for override `https://github.com/rust-lang/crates.io-index#ruby-sys:0.2.20` found
location searched: http://github.com/andrewstucki/ruby-sys?branch=test-build
version required: = 0.2.20

since the target branch has 0.3.0 in it.

@malept
Copy link
Contributor

malept commented Jun 11, 2018

You may want to consider overriding the ruru dependency as well then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants