Skip to content

chcon: link to libfts on musl targets#7863

Closed
ctrlcctrlv wants to merge 3 commits intouutils:mainfrom
ctrlcctrlv:fts
Closed

chcon: link to libfts on musl targets#7863
ctrlcctrlv wants to merge 3 commits intouutils:mainfrom
ctrlcctrlv:fts

Conversation

@ctrlcctrlv
Copy link

This fixes a build failure on aarch64-unknown-linux-musl.

On musl‐based targets the fts API is not provided by libc but by a separate libfts library.

src/uu/chcon/build.rs

Add a build script (build.rs) that detects when CARGO_CFG_TARGET_OS=linux && CARGO_CFG_TARGET_ENV=musl and emits rustc-link-lib=fts, so that uu_chcon can link successfully.

src/uu/chcon/src/fts.rs

In the glibc version of the header, level is short, under musl it's int; likewise, pathlen is unsigned on musl but signed on glibc.

Note

To test this, I build as: RUSTFLAGS='-Ctarget-feature=-crt-static' make in Alpine Linux.

@github-actions
Copy link

github-actions bot commented May 1, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@sylvestre
Copy link
Contributor

i am not sure creating a build.rs is necessary

@ctrlcctrlv
Copy link
Author

How else would you conditionally link the -lfts library?

@sylvestre
Copy link
Contributor

not sure, sorry :)

This fixes a build failure on aarch64-unknown-linux-musl.

On musl‐based targets the fts API is not provided by libc but by a separate libfts library.

* src/uu/chcon/build.rs

Add a build script (`build.rs`) that detects when `CARGO_CFG_TARGET_OS=linux` &&
`CARGO_CFG_TARGET_ENV=musl` and emits `rustc-link-lib=fts`, so that `uu-chcon` can link successfully.

* src/uu/chcon/src/fts.rs

In the glibc version of the header, `level` is `short`, under musl it's `int`; likewise,
`pathlen` is `unsigned` on musl but signed on glibc.
@Ecordonnier Ecordonnier self-requested a review January 11, 2026 20:20
@Ecordonnier
Copy link
Collaborator

Ecordonnier commented Jan 11, 2026

@ctrlcctrlv Can you please clarify how you are building chcon with musl and selinux? I have tried with alpine linux arm64 docker image, but building selinux with musl is not a typical use-case, and I'm getting build errors because of missing libselinux etc.
The issue is that if we merge this PR, it would not be regression-tested by the existing CI setup (because feat_os_unix_musl does not contain feat_selinux in Cargo.toml).

I've tried this on my ubuntu x86 machine, but it doesn't work:

$ sudo apt install qemu-user-static
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
$ docker run --rm -it --platform linux/arm64   -v "$(pwd)":/work -w /work   rust:alpine sh

$ cat test-chcon-musl.sh 
#!/bin/sh
set -e

echo "=== Testing chcon musl ARM64 build ==="

echo "Architecture: $(uname -m)"

echo "Installing dependencies..."
apk add --no-cache musl-dev gcc make musl-fts-dev clang-dev clang-static llvm-static libselinux-dev libsepol-dev

echo ""
echo "Building chcon for musl (native build)..."
# Use static libclang for musl
export LIBCLANG_STATIC_PATH=/usr/lib/llvm21/lib
export RUSTY_LIBCLANG_LINK_STATIC=1
cargo build -p uu_chcon

echo ""
echo "Checking binary..."
ls -lh target/debug/chcon

echo ""
echo "Testing binary..."
./target/debug/chcon --help

echo ""
echo "✅ Build successful on musl ARM64 with SELinux and FTS!"

echo ""
echo "✅ Build successful!"

@Ecordonnier Ecordonnier self-assigned this Jan 13, 2026
@Ecordonnier
Copy link
Collaborator

@ctrlcctrlv ping

@Ecordonnier
Copy link
Collaborator

Please reopen if you still want to continue working on it. I don't know how to test this, please see my comment above.

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

Successfully merging this pull request may close these issues.

3 participants