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: add musl-static and musl-dynamic aliases #518

Open
Gankra opened this issue Oct 25, 2023 · 0 comments
Open

musl: add musl-static and musl-dynamic aliases #518

Gankra opened this issue Oct 25, 2023 · 0 comments
Labels
feature request New feature or request

Comments

@Gankra
Copy link
Contributor

Gankra commented Oct 25, 2023

As noted elsewhere, the Rust team is planning to change the meaning of *-unknown-linux-musl from "+crt-static" to "-crt-static". This fixes a longstanding issue with the musl target, which should ideally default to the proper semantics for musl-libc distros like Alpine.

However this is a breaking change, and lots of people do want the static/portable binary solution that the current behaviour provides. We should introduce two new "magic" targets that cargo-dist desugars:

  • *-musl-static desugars to *-musl with the -Ctarget-feature=+crt-static -Clink-self-contained=yes
  • *-musl-dynamic desugars to *-musl with whatever the opposite of the above is

(plain *-musl would then just be "whatever rustc says today")

Some initial sketching/prep of this design has already been made for both the shell installer and npm installer (some random excerpts):

// Likewise, the default for musl will change in the future, so
// we can future-proof this by adding the flag now
// See: https://github.com/axodotdev/cargo-dist/issues/486
if target.ends_with("linux-musl") {
rustflags.push_str(" -Ctarget-feature=+crt-static -Clink-self-contained=yes");
}

const X64_MACOS: &str = "x86_64-apple-darwin";
const ARM64_MACOS: &str = "aarch64-apple-darwin";
const X64_GNU: &str = "x86_64-unknown-linux-gnu";
const X64_MUSL: &str = "x86_64-unknown-linux-musl";
const X64_MUSL_STATIC: &str = "x86_64-unknown-linux-musl-static";
const X64_MUSL_DYNAMIC: &str = "x86_64-unknown-linux-musl-dynamic";
let mut has_x64_apple = false;
let mut has_arm_apple = false;
let mut has_gnu_linux = false;
let mut has_static_musl_linux = false;
// Currently always false, someday this build will exist
let has_dynamic_musl_linux = false;
for &variant_idx in &release.variants {
let variant = self.variant(variant_idx);
let target = &variant.target;
if target == X64_MACOS {
has_x64_apple = true;
}
if target == ARM64_MACOS {
has_arm_apple = true;
}
if target == X64_GNU {
has_gnu_linux = true;
}
if target == X64_MUSL {
has_static_musl_linux = true;
}
}
let do_rosetta_fallback = has_x64_apple && !has_arm_apple;
let do_gnu_to_musl_fallback = !has_gnu_linux && has_static_musl_linux;
let do_musl_to_musl_fallback = has_static_musl_linux && !has_dynamic_musl_linux;

if ldd --version 2>&1 | grep -q 'musl'; then
_clibtype="musl-dynamic"
# glibc, but is it a compatible glibc?
else
# Parsing version out from line 1 like:
# ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35
_local_glibc="$(ldd --version | head -1 | awk -F' ' '{ print $NF }')"
if [ "$(echo "${_local_glibc}" | awk -F. '{ print $1 }')" = $BUILDER_GLIBC_MAJOR ] && [ "$(echo "${_local_glibc}" | awk -F. '{ print $2 }')" -ge $BUILDER_GLIBC_SERIES ]; then
_clibtype="gnu"
else
_clibtype="musl-static"
fi
fi

In particular:

  • both of those installers are aware of the concept of musl-static and musl-dynamic, and generate fallbacks for best-effort coverage of linux-gnu and linux-musl-dynamic (e.g. if there's no gnu build, say the musl-static build is a gnu build -- ditto for lack of musl-dynamic).
  • both of those installers now internally do their analyses to select one of
    • linux-gnu (lld reports glibc with sufficient version)
    • linux-musl-dynamic (lld reports musl, no version checks yet)
    • linux-musl-static (either glibc is too old, or an unknown libc is reported)

The piece that's missing is:

  • Us accepting linux-musl-static and linux-musl-dynamic as targets in [workspace.manifest.dist]
  • Us desugarring those internally so that we pass the right flags/triple to cargo
  • BUT keeping the sugar around in places like artifact names and the fallback/coverage logic in tasks.rs
  • Also emit some metadata in dist-manifest.json indicating the crt-static-ness (may also want this for msvc targets?)

For this to work properly, work should also be done in:

Note also that we don't currently have a story for building musl-dynamic on github CI. We might need custom infra or docker images to get a host Alpine system or something?

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

No branches or pull requests

1 participant