diff --git a/.github/workflows/common/rust-cross/determine-cross-version.sh b/.github/workflows/common/rust-cross/determine-cross-version.sh new file mode 100755 index 0000000000..6efde069d4 --- /dev/null +++ b/.github/workflows/common/rust-cross/determine-cross-version.sh @@ -0,0 +1,15 @@ +set -e +set -x +set -o pipefail + +VERSION=$1 + +if [ -z "$VERSION" ]; then + JSON=$( curl \ + --request GET \ + --header "Authorization: Bearer $GITHUB_TOKEN" \ + https://api.github.com/repos/cross-rs/cross/releases/latest ) + VERSION=$( echo "$JSON" | jq -r ".tag_name") +fi + +echo "cross-version=$VERSION" >> $GITHUB_OUTPUT diff --git a/.github/workflows/common/rust-cross/install-cross-nix.sh b/.github/workflows/common/rust-cross/install-cross-nix.sh new file mode 100755 index 0000000000..cabd99c73b --- /dev/null +++ b/.github/workflows/common/rust-cross/install-cross-nix.sh @@ -0,0 +1,18 @@ +set -e +set -x +set -o pipefail + +CROSS_DIR="$1" +VERSION="$2" + +VERSION_ARGS="" +if [ -n "$VERSION" ]; then + VERSION_ARGS="--tag $VERSION" +fi + +cd "$CROSS_DIR" +export TARGET=. +curl --silent --location \ + https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | + sh +./ubi --project cross-rs/cross --matching musl --in . $VERSION_ARGS diff --git a/.github/workflows/common/rust-cross/perltidyrc.txt b/.github/workflows/common/rust-cross/perltidyrc.txt new file mode 100644 index 0000000000..b54e60db24 --- /dev/null +++ b/.github/workflows/common/rust-cross/perltidyrc.txt @@ -0,0 +1,22 @@ +-l=78 +-i=4 +-ci=4 +-se +-b +-bar +-boc +-vt=0 +-vtc=0 +-cti=0 +-pt=1 +-bt=1 +-sbt=1 +-bbt=1 +-nolq +-npro +-nsfs +--blank-lines-before-packages=0 +--opening-hash-brace-right +--no-outdent-long-comments +--iterations=2 +-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" diff --git a/.github/workflows/common/rust-cross/precious.toml b/.github/workflows/common/rust-cross/precious.toml new file mode 100644 index 0000000000..2ca71f9375 --- /dev/null +++ b/.github/workflows/common/rust-cross/precious.toml @@ -0,0 +1,47 @@ +exclude = [ + "target", +] + +[commands.perltidy] +type = "both" +include = [ "**/*.{pl,pm,t,psgi}" ] +exclude = "tests/lib/**" +cmd = [ "perltidy", "--profile=$PRECIOUS_ROOT/perltidyrc" ] +lint_flags = [ "--assert-tidy", "--no-standard-output", "--outfile=/dev/null" ] +tidy_flags = [ "--backup-and-modify-in-place", "--backup-file-extension=/" ] +ok_exit_codes = 0 +lint_failure_exit_codes = 2 +ignore_stderr = "Begin Error Output Stream" + +[commands.prettier-md] +type = "both" +include = [ "**/*.md" ] +cmd = [ "./node_modules/.bin/prettier", "--no-config", "--print-width", "100", "--prose-wrap", "always" ] +lint_flags = "--check" +tidy_flags = "--write" +ok_exit_codes = 0 +lint_failure_exit_codes = 1 +ignore_stderr = [ "Code style issues" ] + +[commands.prettier-yml] +type = "both" +include = [ "**/*.yml" ] +cmd = [ "./node_modules/.bin/prettier", "--no-config" ] +lint_flags = "--check" +tidy_flags = "--write" +ok_exit_codes = 0 +lint_failure_exit_codes = 1 +ignore_stderr = [ "Code style issues" ] + +[commands.omegasort-gitignore] +type = "both" +include = "**/.gitignore" +cmd = [ "omegasort", "--sort", "path", "--unique" ] +lint_flags = "--check" +tidy_flags = "--in-place" +ok_exit_codes = 0 +lint_failure_exit_codes = 1 +ignore_stderr = [ + "The .+ file is not sorted", + "The .+ file is not unique", +] diff --git a/.github/workflows/common/rust-cross/set-build-command.sh b/.github/workflows/common/rust-cross/set-build-command.sh new file mode 100755 index 0000000000..953cb6c022 --- /dev/null +++ b/.github/workflows/common/rust-cross/set-build-command.sh @@ -0,0 +1,9 @@ +set -e +set -x + +CROSS_DIR="$1" +if [ -f "$CROSS_DIR/cross" ]; then + echo "build-command=$CROSS_DIR/cross" >> $GITHUB_OUTPUT +else + echo "build-command=cargo" >> $GITHUB_OUTPUT +fi diff --git a/.github/workflows/common/rust-cross/set-cross-compile.sh b/.github/workflows/common/rust-cross/set-cross-compile.sh new file mode 100755 index 0000000000..a8119b6eb0 --- /dev/null +++ b/.github/workflows/common/rust-cross/set-cross-compile.sh @@ -0,0 +1,22 @@ +set -e +set -x + +TARGET="$1" + +# On macOS and Windows, we can cross-compile to all possible targets without +# using cross. +if uname -a | grep --quiet --extended-regexp -i "darwin|msys|windows"; then + echo "needs-cross=false" >> $GITHUB_OUTPUT + exit 0 +fi + +# On Linux, we should be able to cross-compile to i586 and i686, but in +# practice this fails with some crates, notably openssl with the "vendored" +# feature. This feature makes it compile openssl itself, which fails without +# cross. +if echo "$TARGET" | grep --quiet --extended-regexp -i 'x86_64.+linux-(gnu|musl)'; then + echo "needs-cross=false" >> $GITHUB_OUTPUT + exit 0 +fi + +echo "needs-cross=true" >> $GITHUB_OUTPUT diff --git a/.github/workflows/common/rust-cross/set-cross-dir.sh b/.github/workflows/common/rust-cross/set-cross-dir.sh new file mode 100755 index 0000000000..f67a0af8f2 --- /dev/null +++ b/.github/workflows/common/rust-cross/set-cross-dir.sh @@ -0,0 +1,4 @@ +set -e +set -x + +echo "cross-dir=$RUNNER_TEMP" >> $GITHUB_OUTPUT diff --git a/.github/workflows/common/rust-cross/strip-binary.sh b/.github/workflows/common/rust-cross/strip-binary.sh new file mode 100755 index 0000000000..63d1d19c60 --- /dev/null +++ b/.github/workflows/common/rust-cross/strip-binary.sh @@ -0,0 +1,42 @@ +set -e +set -x + +TARGET=$1 +did_strip="" + +strip_binary () { + if [[ $( uname -s ) =~ "Darwin" ]]; then + stripped=$( + find "$1" -maxdepth 1 -type f -perm +111 | while read exe; do + strip "$exe" + echo "stripped $exe" + done + ) + else + stripped=$( + find "$1" -maxdepth 1 -type f -executable | while read exe; do + strip "$exe" + echo "stripped $exe" + done + ) + fi + + if [ -z "$stripped" ]; then + echo "Could not find any binaries to strip in $1" + else + did_strip="true" + fi +} + +for type in debug release; do + if [ -d "target/$TARGET/$type" ]; then + strip_binary "target/$TARGET/$type" + elif [ -d "target/$type" ]; then + strip_binary "target/$type" + fi +done + +if [ -z "$did_strip" ]; then + echo "No binaries were stripped" + exit 1 +fi