Closed jminh closed 1 year ago
Rust does have musl targets apparently: https://doc.rust-lang.org/nightly/rustc/platform-support.html so this sounds doable with cross-compilation.
Perhaps building releases on an earlier Ubuntu version would help? I'm currently using ubuntu-latest which is 22.04 (edit: looks like it defaults to 20.04), but 20.04 and even 18.04 are available: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
Having tried it myself, I had to patch out the explicit libstd++ linking in build.rs
to avoid the final linking against glibc.
--- a/build.rs
+++ b/build.rs
@@ -52,10 +52,6 @@
Some("stdc++".to_string())
}
};
-
- if let Some(cpp_stdlib) = cpp_stdlib {
- println!("cargo:rustc-link-lib={}", cpp_stdlib);
- }
}
}
You probably won't need this when building in a musl only environment, but my build environment is a bit peculiar, as I build this as part of a much larger bundle of tools, and I'm not going to bother with Alpine.
And this is what I have in my Cargo config.
[build]
target = "x86_64-unknown-linux-musl"
[target.x86_64-unknown-linux-musl]
rustflags = [
"-C", "target-feature=+crt-static",
"-C", "link-arg=-fuse-ld=mold",
"-C", "link-arg=-l:libstdc++.a",
"-C", "link-arg=-l:libc.a",
"-C", "link-arg=-l:libgcc.a"
]
linker = "x86_64-linux-musl-gcc"
I also have these set in the environment
AR=x86_64-linux-musl-ar
CC=x86_64-linux-musl-gcc
CXX=x86_64-linux-musl-g++
LD=x86_64-linux-musl-ld.mold
RUSTC_WRAPPER=/usr/bin/sccache
edit: BTW, you'll need a GCC 12.1+ based toolchain for the linker flag -fuse-ld=mold
.
Perhaps building releases on an earlier Ubuntu version would help? I'm currently using ubuntu-latest which is 22.04 (edit: looks like it defaults to 20.04), but 20.04 and even 18.04 are available: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
Ubuntu 18.04 comes with glibc 2.27. CentOS7 18.04 comes with glibc 2.17. Thus, It's likely the binary built on Ubuntu cannot run on CentOS.
Regarding musl, I've built some rust cli code with musl before. Below is my note:
rustup target add x86_64-unknown-linux-musl
git clone https://github.com/ellie/atuin
cd atuin
cargo install --target=x86_64-unknown-linux-musl --path .
# ---
cargo install broot --target=x86_64-unknown-linux-musl
cargo install exa --target=x86_64-unknown-linux-musl
Some rust cli utilities provide musl precompiled binary, for example:
https://github.com/sharkdp/fd/releases/tag/v8.4.0
https://github.com/BurntSushi/ripgrep/releases/tag/13.0.0
I'm not familiar with github ci flow but using musl as keyword, we can see something related.
https://github.com/cantino/mcfly/search?q=musl
https://github.com/BurntSushi/ripgrep/search?p=2&q=musl
==18880==
==18880== Process terminating with default action of signal 11 (SIGSEGV)
==18880== Bad permissions for mapped region at address 0x1FB076
==18880== at 0x1FB076: ???
==18880== by 0xBDF08A: ts_parser_set_language (parser.c:1790)
==18880== by 0xBBE6C3: tree_sitter::Parser::set_language (lib.rs:363)
==18880== by 0xB18F92: difft_lib::parse::tree_sitter_parser::parse_to_tree (tree_sitter_parser.rs:797)
==18880== by 0xB1A254: difft_lib::parse::tree_sitter_parser::parse (tree_sitter_parser.rs:941)
==18880==
==18880== HEAP SUMMARY:
==18880== in use at exit: 0 bytes in 0 blocks
==18880== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==18880==
==18880== All heap blocks were freed -- no leaks are possible
==18880==
==18880== For lists of detected and suppressed errors, rerun with: -s
==18880== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
That would be nice. And it could perhaps solve tickets like this one? https://github.com/Wilfred/difftastic/issues/446
I enabled the Software Collections repo and installed devtoolset-8-gcc
on Centos 7 but without fiddling with the ldd path I can not safely enable this. Once it is working the musl
build should fix my issue to run difft on Centos 7.
Failed on try run the binary on CentOS 7, the binary is downloaded from the release page.
And I found another project that the binary can run on CentOS 7 for downloaded binary from its release page.
The key configuration should be the container
in the line { os: ubuntu-20.04, target: linux, platform: linux-x64, container: 'ubuntu:18.04' }
.
https://github.com/LuaLS/lua-language-server/blob/c602d39994f92b5780faf9e9f504f2a29e484864/.github/workflows/build.yml#L17-L32
Done, 0.51.1 has musl prebuilt binaries.
Note open issue #563.
Since 0.51.1, musl releases are not published. Could you please add them so that I can use the newer versions of difftastic on my old OS? By the way, version 0.51.1 with musl fails with a segfault on Fedora 26, GLIBC 2.25.
Is it possible to provide a musl build as well?
I downloaded latest prebuilt tar difft-x86_64-unknown-linux-gnu.tar.gz (https://github.com/Wilfred/difftastic/releases/tag/0.35.0) but found it cannot run on centos 7 machine.