Skip to content

Commit

Permalink
entrypoint: Add option to disable/enable static linking
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
Douile committed Oct 22, 2023
1 parent cd6596e commit 47f8d8b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,13 @@ _Many target triples do not work, see #4_

# Static linking

Because this action is based on alpine some libraries won't dynamically link correctly (like openssl, see #66, #49, and #79). To enable static linking you can add this `RUSTFLAGS` option:

Some libraries (like openssl, see #49, #66, #79) don't statically link correctly on alpine. If you
experience issues you can try disabling static linking with
```yml
- name: Compile
id: compile
uses: rust-build/[email protected]
env:
RUSTFLAGS: '-C target-feature=-crt-static'
with:
RUSTTARGET: x86_64-unknown-linux-musl
STATIC_LINKING: false
```
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ inputs:
required: false
UPLOAD_MODE:
description: 'What method to use to upload compiled binaries, supported values: (release, none), default: release'
require: false
required: false
STATIC_LINKING:
description: 'Whether to statically link dependencies'
required: false
outputs:
BUILT_ARCHIVE:
description: 'Relative path to the archive containing compiled program'
Expand Down
27 changes: 27 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ error() {
echo "::error file=entrypoint.sh::$*"
}

# Variable tests
is_empty() {
if [ "$1" = "" ]; then
true
else
false
fi
}
is_true() {
if [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "1" ]; then
true
else
false
fi
}

# For backwards compatible also accept environment variable names, but parse all inputs in github
# action format
export RUSTTARGET="${INPUT_RUSTTARGET:-${RUSTTARGET:-}}"
Expand All @@ -27,6 +43,17 @@ POST_BUILD="${INPUT_POST_BUILD:-${POST_BUILD:-}}"
export MINIFY="${INPUT_MINIFY:-${MINIFY:-}}"
export TOOLCHAIN_VERSION="${INPUT_TOOLCHAIN_VERSION:-${TOOLCHAIN_VERSION:-}}"
UPLOAD_MODE="${INPUT_UPLOAD_MODE:-${UPLOAD_MODE:-release}}"
RUSTFLAGS="${INPUT_RUSTFLAGS:-${RUSTFLAGS:-}}"
STATIC_LINK="${INPUT_STATIC_LINKING:-${STATIC_LINK:-}}"

if ! is_empty "$STATIC_LINK" && ! printf "%s" "$RUSTFLAGS" | grep -q "crt-static"; then
if is_true "$STATIC_LINK"; then
RUSTFLAGS="$RUSTFLAGS -C target-feature=+crt-static"
else
RUSTFLAGS="$RUSTFLAGS -C target-feature=-crt-static"
fi
fi
export RUSTFLAGS

if [ -z "${CMD_PATH+x}" ]; then
export CMD_PATH=""
Expand Down

0 comments on commit 47f8d8b

Please sign in to comment.