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

Provide musl build #357

Closed
jminh opened this issue Sep 8, 2022 · 11 comments
Closed

Provide musl build #357

jminh opened this issue Sep 8, 2022 · 11 comments
Labels
help wanted Contributions and/or pull requests are appreciated :)

Comments

@jminh
Copy link

jminh commented Sep 8, 2022

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.

$ lsb_release -d
Description:    CentOS Linux release 7.9.2009 (Core)

$ ./difft
./difft: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./difft)
./difft: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./difft)
./difft: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by ./difft)
@Wilfred
Copy link
Owner

Wilfred commented Sep 9, 2022

Rust does have musl targets apparently: https://doc.rust-lang.org/nightly/rustc/platform-support.html so this sounds doable with cross-compilation.

@Wilfred
Copy link
Owner

Wilfred commented Sep 9, 2022

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

@tinywrkb
Copy link

tinywrkb commented Sep 11, 2022

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.

@jminh
Copy link
Author

jminh commented Sep 11, 2022

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

@imuxin
Copy link

imuxin commented Sep 15, 2022

Segmentation fault

==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)

@tmysik
Copy link

tmysik commented Dec 20, 2022

That would be nice. And it could perhaps solve tickets like this one? #446

@danie-dejager
Copy link

danie-dejager commented Jan 12, 2023

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.

@sunlin7
Copy link

sunlin7 commented Feb 3, 2023

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

@Wilfred Wilfred added the help wanted Contributions and/or pull requests are appreciated :) label Mar 3, 2023
@Wilfred
Copy link
Owner

Wilfred commented Aug 26, 2023

Done, 0.51.1 has musl prebuilt binaries.

@Wilfred
Copy link
Owner

Wilfred commented Oct 5, 2023

Note open issue #563.

@CsatiZoltan
Copy link

CsatiZoltan commented Feb 28, 2024

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.

hugo-vrijswijk pushed a commit to hugo-vrijswijk/difftastic that referenced this issue Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions and/or pull requests are appreciated :)
Projects
None yet
Development

No branches or pull requests

8 participants