Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
joshmuente
committed
Sep 17, 2021
1 parent
a040664
commit f3c6caf
Showing
3 changed files
with
184 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env bash | ||
|
||
info() { | ||
echo "::info $*" >&2 | ||
} | ||
|
||
error() { | ||
echo "::error file=build.sh:: $*" >&2 | ||
} | ||
|
||
set -eu -o pipefail | ||
|
||
crash() { | ||
error "Command exited with non-zero exit code" | ||
exit 1 | ||
} | ||
|
||
trap 'crash' ERR | ||
PROJECT_ROOT="/rust/build/${GITHUB_REPOSITORY}" | ||
OUTPUT_DIR="$1" | ||
|
||
mkdir -p "$PROJECT_ROOT" | ||
rmdir "$PROJECT_ROOT" | ||
ln -s "$GITHUB_WORKSPACE" "$PROJECT_ROOT" | ||
cd "$PROJECT_ROOT" | ||
|
||
if [ -z "${SRC_DIR+0}" ]; then | ||
info "No SRC_DIR is set, using repo base dir" | ||
else | ||
info "Switching to src dir \"$SRC_DIR\"" | ||
cd "$SRC_DIR" | ||
fi | ||
|
||
info "Installing additional linkers" | ||
case ${RUSTTARGET} in | ||
"x86_64-pc-windows-gnu") ;; | ||
|
||
"x86_64-unknown-linux-musl") ;; | ||
|
||
"x86_64-unknown-linux-gnu") | ||
error "x86_64-unknown-linux-gnu is not supported: please use x86_64-unknown-linux-musl for a statically linked c library" | ||
exit 1 | ||
;; | ||
|
||
"wasm32-wasi") ;; | ||
"wasm32-unknown-emscripten") | ||
mkdir -p /.cargo | ||
cat > /.cargo/config.toml << EOF | ||
[target.wasm32-unknown-emscripten] | ||
linker = "/usr/lib/emscripten-fastcomp/bin/clang" | ||
ar = "/usr/lib/emscripten-fastcomp/bin/llvm-ar" | ||
EOF | ||
;; | ||
|
||
"x86_64-apple-darwin") | ||
mkdir -p /.cargo | ||
cat > /.cargo/config.toml << EOF | ||
[target.x86_64-apple-darwin] | ||
linker = "/opt/osxcross/target/bin/x86_64-apple-darwin14-clang" | ||
ar = "/opt/osxcross/target/bin/x86_64-apple-darwin14-ar" | ||
EOF | ||
;; | ||
|
||
*) | ||
error "${RUSTTARGET} is not supported" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
BINARIES="$(cargo read-manifest | jq -r ".targets[] | select(.kind[] | contains(\"bin\")) | .name")" | ||
|
||
OUTPUT_LIST="" | ||
for BINARY in $BINARIES; do | ||
info "Building $BINARY..." | ||
|
||
if [ -x "./build.sh" ]; then | ||
OUTPUT=$(./build.sh "${CMD_PATH}" "${OUTPUT_DIR}") | ||
else | ||
rustup target add "$RUSTTARGET" | ||
OPENSSL_LIB_DIR=/usr/lib OPENSSL_INCLUDE_DIR=/usr/include/openssl CARGO_TARGET_DIR="./target" cargo build --release --target "$RUSTTARGET" --bin "$BINARY" | ||
OUTPUT=$(find "target/${RUSTTARGET}/release/" -maxdepth 1 -type f -executable \( -name "${BINARY}" -o -name "${BINARY}.*" \) -print0 | xargs -0) | ||
fi | ||
|
||
info "$OUTPUT" | ||
|
||
if [ "$OUTPUT" = "" ]; then | ||
error "Unable to find output" | ||
exit 1 | ||
fi | ||
|
||
info "Saving $OUTPUT..." | ||
|
||
# shellcheck disable=SC2086 | ||
mv $OUTPUT "$OUTPUT_DIR" || error "Unable to copy binary" | ||
|
||
for f in $OUTPUT; do | ||
OUTPUT_LIST="$OUTPUT_LIST $(basename "$f")" | ||
done | ||
done | ||
echo "$OUTPUT_LIST" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
if [ -z "${CMD_PATH+x}" ]; then | ||
export CMD_PATH="" | ||
fi | ||
|
||
OUTPUT_DIR="output" | ||
mkdir -p "$OUTPUT_DIR" | ||
|
||
|
||
if ! FILE_LIST=$(ci/build.sh "$OUTPUT_DIR"); then | ||
echo "::error file=entrypoint.sh::Build failed" >&2 | ||
exit 1 | ||
fi | ||
|
||
EVENT_DATA=$(cat "$GITHUB_EVENT_PATH") | ||
echo "$EVENT_DATA" | jq . | ||
UPLOAD_URL=$(echo "$EVENT_DATA" | jq -r .release.upload_url) | ||
if [ "$UPLOAD_URL" = "null" ]; then | ||
echo "::error file=entrypoint.sh::The event provided did not contain an upload URL, this workflow can only be used with the release event." >&2 | ||
exit 1 | ||
fi | ||
UPLOAD_URL=${UPLOAD_URL/\{?name,label\}/} | ||
RELEASE_NAME=$(echo "$EVENT_DATA" | jq -r .release.tag_name) | ||
PROJECT_NAME=$(basename "$GITHUB_REPOSITORY") | ||
NAME="${NAME:-${PROJECT_NAME}_${RELEASE_NAME}}_${RUSTTARGET}" | ||
ARCHIVE_TYPES="${ARCHIVE_TYPES:-"zip"}" | ||
EXTRA_FILES="${EXTRA_FILES:-""}" | ||
|
||
if [ -z "${EXTRA_FILES+x}" ]; then | ||
echo "::warning file=entrypoint.sh::EXTRA_FILES not set" | ||
else | ||
for file in $(echo -n "${EXTRA_FILES}" | tr " " "\n"); do | ||
cp "$file" "$OUTPUT_DIR" | ||
done | ||
fi | ||
|
||
cd "$OUTPUT_DIR" | ||
|
||
if [ -n "${EXTRA_FILES+0}" ]; then | ||
FILE_LIST="${FILE_LIST} ${EXTRA_FILES}" | ||
fi | ||
|
||
FILE_LIST=$(echo "${FILE_LIST}" | awk '{$1=$1};1') | ||
|
||
echo "::info::Packing files: $FILE_LIST" | ||
|
||
for ARCHIVE_TYPE in $ARCHIVE_TYPES; do | ||
ARCHIVE="tmp.${ARCHIVE_TYPE}" | ||
|
||
# shellcheck disable=SC2086 | ||
case $ARCHIVE_TYPE in | ||
"zip") | ||
zip -9r $ARCHIVE ${FILE_LIST} | ||
;; | ||
|
||
"tar"|"tar.gz"|"tar.bz2"|"tar.xz") | ||
tar caf $ARCHIVE ${FILE_LIST} | ||
;; | ||
|
||
*) | ||
echo "::error file=entrypoint.sh::The given archive type '${ARCHIVE_TYPE}' is not supported; please choose one of 'zip' or 'tar.gz'" | ||
continue | ||
esac | ||
|
||
CHECKSUM=$(sha256sum "${ARCHIVE}" | cut -d ' ' -f 1) | ||
|
||
curl \ | ||
-X POST \ | ||
--data-binary @"${ARCHIVE}" \ | ||
-H 'Content-Type: application/octet-stream' \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${UPLOAD_URL}?name=${NAME}.${ARCHIVE/tmp./}" | ||
|
||
curl \ | ||
-X POST \ | ||
--data "$CHECKSUM" \ | ||
-H 'Content-Type: text/plain' \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${UPLOAD_URL}?name=${NAME}.${ARCHIVE/tmp./}.sha256sum" | ||
done |