Skip to content
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

Static compilation possible? #80

Closed
wwood opened this issue Apr 29, 2018 · 7 comments
Closed

Static compilation possible? #80

wwood opened this issue Apr 29, 2018 · 7 comments

Comments

@wwood
Copy link

wwood commented Apr 29, 2018

Hi,

I'm trying to create a static binary for a project of mine https://github.com/wwood/CoverM but i'm running into an issue:

$ rustup target add x86_64-unknown-linux-musl
...
$ cargo build --target x86_64-unknown-linux-musl --release
...
/usr/bin/ld: /home/ben/git/coverm/target/x86_64-unknown-linux-musl/release/deps/librust_htslib-f71d6303e993dcd2.rlib(sam_header.o): undefined reference to symbol '__printf_chk@@GLIBC_2.3.4'

Is it possible to get a static compile of a project using rust-htslib? Am I doing something incorrectly?
ta, ben

@johanneskoester
Copy link
Contributor

Static building is fine. I do that all the time. However, HTSlib needs glibc >= 2.3.4. You are trying to build on musl instead. I don't know if that is supported. I suggest asking the htslib guys.

@johanneskoester
Copy link
Contributor

Closing for now, feel free to reopen if you disagree or new issues arise.

@wwood
Copy link
Author

wwood commented May 1, 2018

Thanks, I would be happy to use glibc. However, after a frustrating amount of internet searching I'm finding it difficult to work out how, exactly. Would you mind sharing your secret? I'm looking to build an executable.

Apologies if this is a naive question, I just figure you might have a solution easily at hand.
Thanks, ben

@johanneskoester
Copy link
Contributor

glibc should be the default on most linux distributions. So, if you e.g. run on Ubuntu or Fedora, it will use a new enough glibc automatically. Unfortunately, if your system uses musl, you might need to do the build inside a container or a virtual machine, or try to figure out how to switch to glibc on your system.

@wwood
Copy link
Author

wwood commented May 5, 2018

Right, glibc is the default on my (Ubuntu/GNU Guix) system. I installed the musl toolchain with rustup specifically for the purpose of static compilation, following this advice:

Static linking is supported via an alternative libc, musl.

https://doc.rust-lang.org/1.12.1/book/advanced-linking.html#static-linking

Compiling with the musl toolchain gives a static binary by default, where the glibc toolchain does not (I tried using ldd and it failed to run on another system). Do you have any suggestions on how to ask for a static compilation with the glibc toolchain, or some other solution?

Thanks, ben

@johanneskoester
Copy link
Contributor

Ok, so you want the libc to be statically linked as well. This is indeed not possible if you depend on htslib, since that requires glibc as far as I know. However, please note that statically linking glibc into a binary is usually not necessary. It is present on virtually every system. All you need is to build your binary on an old enough linux, because glibc is forward compatible. By e.g. building on centos 6, it should work on all newer linuxes. The problem you have is that your ubuntu has a too new glibc for many other linuxes I guess.

Instead of trying to build a compatible binary on your own (I guess for distribution), please consider providing your package via Bioconda, which solves such problems for you.

@wwood
Copy link
Author

wwood commented May 7, 2018

OK, thanks for the suggestions. I'll figure something out.

zitsen added a commit to zitsen/rust-htslib that referenced this issue Sep 4, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Changes:
- explicitly declare deps for `bzip2` and `lzma` feature.
- add musl target support using `cc` crate.

Though I choose to link native deps with the `bzip2-sys` and `lzma-sys` crates,
note that the deps could be done with cargo's `target` selector.
Let me know if you do not want to link it by default.

/cc rust-bio#80
zitsen added a commit to zitsen/rust-htslib that referenced this issue Sep 5, 2018
Changes:
- explicitly declare deps for `bzip2` and `lzma` feature.
- add musl target support using `cc` crate.

Though I choose to link native deps with the `bzip2-sys` and `lzma-sys` crates,
note that the deps could be done with cargo's `target` selector.
Let me know if you do not want to link it by default.

/cc rust-bio#80
zitsen added a commit to zitsen/rust-htslib that referenced this issue Sep 5, 2018
Changes:
- explicitly declare deps for `bzip2` and `lzma` feature.
- add musl target support using `cc` crate.

Though I choose to link native deps with the `bzip2-sys` and `lzma-sys` crates,
note that the deps could be done with cargo's `target` selector.
Let me know if you do not want to link it by default.

/cc rust-bio#80
zitsen added a commit to zitsen/rust-htslib that referenced this issue Sep 5, 2018
Changes:
- explicitly declare deps for `bzip2` and `lzma` feature.
- add musl target support using `cc` crate.

Though I choose to link native deps with the `bzip2-sys` and `lzma-sys` crates,
note that the deps could be done with cargo's `target` selector.
Let me know if you do not want to link it by default.

/cc rust-bio#80
johanneskoester pushed a commit that referenced this issue Sep 12, 2018
* feat: add musl target support

Changes:
- explicitly declare deps for `bzip2` and `lzma` feature.
- add musl target support using `cc` crate.

Though I choose to link native deps with the `bzip2-sys` and `lzma-sys` crates,
note that the deps could be done with cargo's `target` selector.
Let me know if you do not want to link it by default.

/cc #80

* chore: not force install cargo-travis to save time

* fix: try to fix default target error

* fix(CI): fix cargo-travis(kcov) error

Error description(see https://travis-ci.org/rust-bio/rust-htslib/builds/424648253):

```
kcov: warning: kcov: WARNING: kcov has been built without libbfd-dev (or
kcov: binutils-dev), so the --verify option will not do anything.
Can't set personality: Operation not permitted
kcov: error: Can't start/attach to /home/travis/build/rust-bio/rust-htslib/target/debug/deps/rust_htslib-b4e39d181972c8d6
Child hasn't stopped: ff00
kcov: error: Can't start/attach to /home/travis/build/rust-bio/rust-htslib/target/debug/deps/rust_htslib-b4e39d181972c8d6
error: test failed
```

Reference: roblabla/cargo-travis#38
@brainstorm brainstorm mentioned this issue Feb 27, 2020
5 tasks
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