diff --git a/Changes.md b/Changes.md index b15316e..ec91ae9 100644 --- a/Changes.md +++ b/Changes.md @@ -1,5 +1,7 @@ ## 0.0.10 +- Fixed handling of crates with multiple binaries. Attempting to strip binaries for such a crate + caused the build to fail. Reported by Tomaž Hribernik. GH #8 - Added a new `cross-version` parameter. This can be specified to make this action use a specific version of `cross`. If this is not specified, the latest version will be used. diff --git a/strip-binary.sh b/strip-binary.sh index 08ad2cb..63d1d19 100755 --- a/strip-binary.sh +++ b/strip-binary.sh @@ -2,20 +2,29 @@ set -e set -x TARGET=$1 -stripped="" +did_strip="" strip_binary () { if [[ $( uname -s ) =~ "Darwin" ]]; then - EXE=$( find "$1" -maxdepth 1 -type f -perm +111 ) + stripped=$( + find "$1" -maxdepth 1 -type f -perm +111 | while read exe; do + strip "$exe" + echo "stripped $exe" + done + ) else - EXE=$( find "$1" -maxdepth 1 -type f -executable ) + stripped=$( + find "$1" -maxdepth 1 -type f -executable | while read exe; do + strip "$exe" + echo "stripped $exe" + done + ) fi - if [ -z "$EXE" ]; then - echo "Could not find a binary to strip in $1" + if [ -z "$stripped" ]; then + echo "Could not find any binaries to strip in $1" else - strip "$EXE" - stripped="$EXE" + did_strip="true" fi } @@ -27,7 +36,7 @@ for type in debug release; do fi done -if [ -z "$stripped" ]; then +if [ -z "$did_strip" ]; then echo "No binaries were stripped" exit 1 fi diff --git a/test-project/Cargo.toml b/test-project/Cargo.toml index 8361856..15e5e60 100644 --- a/test-project/Cargo.toml +++ b/test-project/Cargo.toml @@ -3,4 +3,14 @@ name = "test-project" version = "0.1.0" edition = "2021" -[dependencies] +# For testing it would be nice to create a binary with spaces in the name, but +# right now the `name` value must be a valid crate name, and there's no +# separate setting for the compiled executable's name. See +# https://github.com/rust-lang/cargo/issues/9778. +[[bin]] +name = "bin1" +path = "src/bin1.rs" + +[[bin]] +name = "bin2" +path = "src/bin2.rs" diff --git a/test-project/src/main.rs b/test-project/src/bin1.rs similarity index 100% rename from test-project/src/main.rs rename to test-project/src/bin1.rs diff --git a/test-project/src/bin2.rs b/test-project/src/bin2.rs new file mode 100644 index 0000000..b80f5b7 --- /dev/null +++ b/test-project/src/bin2.rs @@ -0,0 +1,11 @@ +fn main() { + println!("Hello, world!"); +} + +#[cfg(test)] +mod test { + #[test] + fn test_something() { + assert_eq!(1, 1); + } +} diff --git a/tests/check-binary.pl b/tests/check-binary.pl index df08a63..204f87a 100755 --- a/tests/check-binary.pl +++ b/tests/check-binary.pl @@ -37,7 +37,8 @@ sub main { ); for my $bin ( - path( qw( . target ), $target, qw( debug test-project ) ), + path( qw( . target ), $target, qw( debug bin1 ) ), + path( qw( . target ), $target, qw( debug bin2 ) ), path( qw( . subcrate target ), $target, qw( debug subcrate ) ) ) { check_binary( $bin, $expect_file_re, $expect_stripped );