From ef0abfa956fb731af6356c33120954f088a4f638 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 9 Jul 2023 03:12:57 +0200 Subject: [PATCH] xx-verify: XX_VERIFY_STATIC env Signed-off-by: CrazyMax --- README.md | 5 +++++ base/test-verify.bats | 19 +++++++++++++++++++ base/xx-verify | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index ad904b2..43357b1 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,11 @@ RUN xx-clang --static -o /out/myapp app.c && \ xx-verify --static /out/myapp ``` +> **Note** +> +> `XX_VERIFY_STATIC=1` environment variable can be defined to make `xx-verify` +> always verify that the compiler produced a static binary. + ## C/C++ The recommended method for C-based build is to use `clang` via `xx-clang` wrapper. Clang is natively a cross-compiler, but in order to use it, you also need a linker, compiler-rt or libgcc, and a C library(musl or glibc). All these are available as packages in Alpine and Debian based distros. Clang and linker are binaries and should be installed for your build architecture, while libgcc and C library should be installed for your target architecture. diff --git a/base/test-verify.bats b/base/test-verify.bats index 622530c..34e51fc 100755 --- a/base/test-verify.bats +++ b/base/test-verify.bats @@ -53,6 +53,25 @@ load 'assert' unset TARGETPLATFORM } +@test "static-env" { + export XX_VERIFY_STATIC=1 + + export XX_VERIFY_FILE_CMD_OUTPUT=": ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-aarch64.so.1, stripped" + export TARGETPLATFORM=linux/arm64 + run xx-verify /idontexist + assert_failure + assert_output --partial "not statically linked" + + export XX_VERIFY_FILE_CMD_OUTPUT=": ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped" + export TARGETPLATFORM=linux/amd64 + run xx-verify /idontexist + assert_success + + unset XX_VERIFY_FILE_CMD_OUTPUT + unset XX_VERIFY_STATIC + unset TARGETPLATFORM +} + @test "darwin" { export XX_VERIFY_FILE_CMD_OUTPUT=": Mach-O 64-bit executable x86_64" export TARGETPLATFORM=darwin/amd64 diff --git a/base/xx-verify b/base/xx-verify index a88b443..464d44d 100755 --- a/base/xx-verify +++ b/base/xx-verify @@ -41,6 +41,10 @@ EOT static="" files="" +if [ "$XX_VERIFY_STATIC" = "1" ]; then + static=1 +fi + for i in "$@"; do case "$i" in "--setup")