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

musl support (prefer musl for linux?) #75

Closed
Gankra opened this issue Feb 1, 2023 · 13 comments · Fixed by #483
Closed

musl support (prefer musl for linux?) #75

Gankra opened this issue Feb 1, 2023 · 13 comments · Fixed by #483
Assignees
Labels
feature request New feature or request
Milestone

Comments

@Gankra
Copy link
Member

Gankra commented Feb 1, 2023

Prebuilt binaries for linux are a mess for various reasons (e.g. #73), and preferring musl over glibc fixes some of those issues (in exchange for other subtle problems that I'm assured are minor in comparison).

This requires some basic cross-compilation support to get the toolchain from rustup and to use musl-tools (#74).

@Gankra Gankra added the feature request New feature or request label Feb 1, 2023
@frol
Copy link
Contributor

frol commented Feb 2, 2023

In my experience, it is not always straightforward to get binary compiled against musl and/or static build. Just to name a few showstoppers:

  • the features that require udev and dbus usually need to be feature-flagged and disabled in musl context
  • openssl is another common problem for static linking

Thus, when we can automate things and create dedicated packages for all the platforms separately, that is still the best way, unfortunately.

P.S. Thanks for starting this project! I was dreaming of it for years (copying and manually adjusting scripts from ripgrep is not a fun task let alone creating release pipelines from scratch). I am using cargo-dist for https://github.com/FroVolod/near-social now 🎉

@Be-ing
Copy link

Be-ing commented Feb 13, 2023

Preferring statically linked musl can work okay until you need to dynamically link C/C++ libraries.

@ashleygwilliams ashleygwilliams added this to the next milestone Feb 16, 2023
@Gankra
Copy link
Member Author

Gankra commented Mar 1, 2023

I poked at this a bit yesterday, but mostly hit problems with a lack of properly reproducible linux environment. I think my wsl2 ubuntu already had musl-tools installed, and getting Ubuntu to forget them proved unfruitful. I'll need to set up proper docker images or something to be able to reliably reproduce "out of the box" states for a few major linux distros.

That or don't care about helping people set things up locally and just focus on the Github CI env (disappointing).

@frol
Copy link
Contributor

frol commented Mar 1, 2023

Setting up musl cross-compilation environment for every distro out there is not rewarding at all, which is why cross exists. Cross is used by ripgrep and a couple of other crates I saw around.

@bjorn3
Copy link

bjorn3 commented Mar 15, 2023

Something a lot more subtle that may be a reason not to use musl by default is that musl doesn't support DNS over TCP by design, so if a DNS response doesn't fit in a UDP packet it will get silently truncated. I did expect issues caused by this to be non-trivial to debug unless you actually know about this fact.

Edit: As pointed out by @panekj musl supports TCP fallback since about half a year.

By the way you may want to explicitly set -Ctarget-feature=+crt-static as the musl target may switch to dynamic linking by default in the future and musl based linux distros already patch rustc to make it dynamically link musl by default.

@Gankra
Copy link
Member Author

Gankra commented Mar 15, 2023

MUSL DISTROS PLEASE NO

PLEASE

@Be-ing
Copy link

Be-ing commented Mar 16, 2023

@panekj
Copy link

panekj commented Mar 16, 2023

Something a lot more subtle that may be a reason not to use musl by default is that musl doesn't support DNS over TCP by design, so if a DNS response doesn't fit in a UDP packet it will get silently truncated. I did expect issues caused by this to be non-trivial to debug unless you actually know about this fact.

Hi, this is not correct. musl has support for DNS over TCP

By the way you may want to explicitly set -Ctarget-feature=+crt-static as the musl target may switch to dynamic linking by default in the future and musl based linux distros already patch rustc to make it dynamically link musl by default.

MUSL DISTROS PLEASE NO

PLEASE

Yes, please, because static linking has been broken for a very very long time and you should not be using static linking unless absolutely necessary (via specifying crt-static and other compiler options).

@bjorn3
Copy link

bjorn3 commented Mar 16, 2023

Hi, this is not correct. musl has support for DNS over TCP

Great to hear that it is now implemented. Seems that commit is less than half a year old and I hadn't rechecked after it landed.

@ericonr
Copy link

ericonr commented Jun 7, 2023

the features that require udev and dbus usually need to be feature-flagged and disabled in musl context

@frol Whatever gave you that impression? glibc knows nothing about udev or dbus, and neither does musl, because those layers sit on top of the C library, not below it

@bjorn3
Copy link

bjorn3 commented Jun 7, 2023

If you have a glibc based distribution, libudev.so and libdbus.so are compiled for glibc and thus don't work with musl. And if you have a musl based distribution, the musl versions would be dynamically linked, thus still breaking on glibc distros at runtime. You did have to statically link a musl version of libudev and libdbus, which may be harder than just disabling udev and dbus support entirely.

@ericonr
Copy link

ericonr commented Jun 7, 2023

So the issue is about cross compilation and static linking, not musl specifically.

Building on a musl-based distro is considerably easier, and there's a good chance static libraries for these will be available on that distro.

Either way, thanks for clarifying

@nbittich
Copy link

+1 for musl support. If you target gnu + musl, the release.yml file produced doesn't seem correct.

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

Successfully merging a pull request may close this issue.

9 participants