From b775e78a2f44a327394136c53501aa7a9503ddf8 Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 7 May 2024 21:00:12 -0400 Subject: [PATCH] scubainit: Use nightly flag -Zon-broken-pipe=inherit to fix SIGPIPE Rust ignores SIGPIPE by default, this patch overrides that behaviour to fix this by *not* panic'ing on Broken pipes and restore old scubainit behavior. In short, the following fails: > image: debian:latest > > aliases: > test: yes '' | echo "test" $ scuba test: > test > yes: standard output: Broken pipe * Use nightly on-broken-pipe="inherit" to inherit the behavior from the parent process, Instead of killing our process. See docs here: https://github.com/rust-lang/rust/blob/master/src/doc/unstable-book/src/compiler-flags/on-broken-pipe.md This nightly fix is definitely unstable(with very recent API changes), but hopefully they keep this interface as a compiler option the same until stabilization. * Add test to verify this doesn't break in the future * Add rust-toolchain.toml to define the locked rust version since this requires a nightly option. I specifically didn't think nightly was an issue, since you were looking into using -Zbuild-std for scubainit size minimization (which has a long path to stabilization) This has been a longstanding issue for the Rust language: - https://github.com/rust-lang/rust/issues/62569 - https://github.com/rust-lang/rust/issues/97889 --- run_full_tests.py | 1 + scubainit/Makefile | 5 +++-- scubainit/rust-toolchain.toml | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 scubainit/rust-toolchain.toml diff --git a/run_full_tests.py b/run_full_tests.py index 69c14c01..fa12f9b1 100755 --- a/run_full_tests.py +++ b/run_full_tests.py @@ -36,6 +36,7 @@ def test1(): f.write(in_data) subprocess.check_call(["scuba", "/bin/sh", "-c", "cat file.in >> file.out"]) + subprocess.check_call(["scuba", "/bin/sh", "-c", "yes '' | echo 'test'"]) with open("file.out", "rt") as f: out_data = f.read() diff --git a/scubainit/Makefile b/scubainit/Makefile index 34bd0594..e2e48d73 100644 --- a/scubainit/Makefile +++ b/scubainit/Makefile @@ -23,6 +23,7 @@ TARGET=x86_64-unknown-linux-musl # Enable static linking STATIC_RUSTFLAGS=-C relocation-model=static +NIGHTLY_RUSTFLAGS=-Zon-broken-pipe=inherit export RUSTFLAGS @@ -43,7 +44,7 @@ fmt: .PHONY: scubainit-debug # always build scubainit-debug: PROFILE=debug -scubainit-debug: RUSTFLAGS=$(STATIC_RUSTFLAGS) +scubainit-debug: RUSTFLAGS=$(STATIC_RUSTFLAGS) $(NIGHTLY_RUSTFLAGS) scubainit-debug: setup @/bin/echo -e "\nBuilding scubainit ($(PROFILE)) with RUSTFLAGS=\"$$RUSTFLAGS\"" cargo build --target $(TARGET) @@ -51,7 +52,7 @@ scubainit-debug: setup .PHONY: scubainit # always build scubainit: PROFILE=release -scubainit: RUSTFLAGS=$(STATIC_RUSTFLAGS) +scubainit: RUSTFLAGS=$(STATIC_RUSTFLAGS) $(NIGHTLY_RUSTFLAGS) scubainit: setup @/bin/echo -e "\nBuilding scubainit ($(PROFILE)) with RUSTFLAGS=\"$$RUSTFLAGS\"" cargo build --target $(TARGET) --release diff --git a/scubainit/rust-toolchain.toml b/scubainit/rust-toolchain.toml new file mode 100644 index 00000000..e386c089 --- /dev/null +++ b/scubainit/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly-2024-05-07" +targets = ["x86_64-unknown-linux-musl"]