Skip to content

Commit

Permalink
xx-verify: XX_VERIFY_STATIC env
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jul 9, 2023
1 parent ebe730a commit ef0abfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions base/test-verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions base/xx-verify
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ EOT
static=""
files=""

if [ "$XX_VERIFY_STATIC" = "1" ]; then
static=1
fi

for i in "$@"; do
case "$i" in
"--setup")
Expand Down

0 comments on commit ef0abfa

Please sign in to comment.