Skip to content

Commit

Permalink
Build s390x binaries using musl libc
Browse files Browse the repository at this point in the history
Building using musl until NixOS/nixpkgs#306473 is resolved.

Refers to cri-o/cri-o#7911

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Apr 24, 2024
1 parent 0beabe6 commit a9d1daf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
10 changes: 10 additions & 0 deletions conmon-rs/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
})
.await
}

/// Workaround for rustc bug: https://github.com/rust-lang/rust/issues/47493
///
/// It shouldn't even be possible to reach this function, thanks to panic=abort,
/// but libcore is compiled with unwinding enabled and that ends up making unreachable
/// references to this.
#[no_mangle]
extern "C" fn _Unwind_Resume() -> ! {
unreachable!("Unwinding not supported");
}
10 changes: 10 additions & 0 deletions conmon-rs/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ fn main() -> Result<()> {
.start()
.context("start server")
}

/// Workaround for rustc bug: https://github.com/rust-lang/rust/issues/47493
///
/// It shouldn't even be possible to reach this function, thanks to panic=abort,
/// but libcore is compiled with unwinding enabled and that ends up making unreachable
/// references to this.
#[no_mangle]
extern "C" fn _Unwind_Resume() -> ! {
unreachable!("Unwinding not supported");
}
5 changes: 4 additions & 1 deletion nix/default-s390x.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(import ./nixpkgs.nix {
crossSystem = {
config = "s390x-unknown-linux-gnu";
# TODO: Switch back to glibc when
# https://github.com/NixOS/nixpkgs/issues/306473
# is resolved.
config = "s390x-unknown-linux-musl";
};
overlays = [ (import ./overlay.nix) ];
}).callPackage ./derivation.nix
Expand Down
20 changes: 16 additions & 4 deletions nix/derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ with pkgs; rustPlatform.buildRustPackage {
capnproto
protobuf
];
buildInputs = [
glibc
glibc.static
];
buildInputs =
if stdenv.hostPlatform.isMusl then [
libunwind
] else [
glibc
glibc.static
];
RUSTFLAGS = [
"-Ctarget-feature=+crt-static"
] ++ lib.optionals stdenv.hostPlatform.isMusl [
"-Cpanic=abort"
"-Clink-args=-nostartfiles"
"-Clink-args=-L${libunwind}/lib"
];
# Patch nix v0.27.1 for musl
preBuild = lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i 's;target_arch = "s390x";target_arch = "s390x" , not(target_env = "musl");g' \
/build/cargo-vendor-dir/nix-0.27.1/src/sys/statfs.rs
'';
stripAllList = [ "bin" ];
cargoLock = {
lockFile = lib.cleanSource ./.. + "/Cargo.lock";
Expand Down
4 changes: 3 additions & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ let
static = import ./static.nix;
in
self: super:
{ }
{
libunwind = (static super.libunwind);
}

0 comments on commit a9d1daf

Please sign in to comment.