-
Notifications
You must be signed in to change notification settings - Fork 32
164 lines (140 loc) · 5.71 KB
/
release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Build precompiled NIFs
env:
NIF_DIRECTORY: "native/wasmex"
on:
push:
branches:
# Always run on main branch.
- main
tags:
# Tags will always run.
- '*'
pull_request:
paths:
# Run if "native" path changed.
- 'native/**'
defaults:
run:
shell: bash
# Sets the working dir for "run" scripts.
# Note that this won't change the directory for actions (tasks with "uses").
working-directory: "./native/wasmex"
jobs:
build_release:
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }})
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
nif:
# see: https://github.com/erlang/otp/blob/master/erts/emulator/beam/erl_nif.h
- "2.15" # OTP 22, OTP 23
- "2.16" # OTP 24, OTP 25
- "2.17" # OTP 26
job:
# cranelift-codegen panics at 'error when identifying target: "no supported isa found for arch `arm`"'
# - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true }
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
- { target: aarch64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
- { target: riscv64gc-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
- { target: aarch64-apple-darwin , os: macos-11 }
- { target: x86_64-apple-darwin , os: macos-11 }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 }
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
env:
RUSTLER_NIF_VERSION: ${{ matrix.nif }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Install prerequisites
run: |
case ${{ matrix.job.target }} in
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
esac
- name: Extract crate information
run: |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
# Get the project version from mix.exs
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' ../../mix.exs | head -n1)" >> $GITHUB_ENV
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.job.target }}
- name: Show version information (Rust, cargo, GCC)
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
rustc --print=cfg
- name: Download cross from GitHub releases
uses: giantswarm/[email protected]
if: ${{ matrix.job.use-cross }}
with:
binary: "cross"
version: "v0.2.2"
download_url: "https://github.com/cross-rs/cross/releases/download/${version}/cross-x86_64-unknown-linux-gnu.tar.gz"
tarball_binary_path: "${binary}"
smoke_test: "${binary} --version"
- name: Build
run: |
if [ "${{ matrix.job.use-cross }}" == "true" ]; then
cross build --release --target=${{ matrix.job.target }}
else
cargo build --release --target=${{ matrix.job.target }}
fi
- name: Rename lib to the final name
id: rename
run: |
LIB_PREFIX="lib"
case ${{ matrix.job.target }} in
*-pc-windows-*) LIB_PREFIX="" ;;
esac;
# Figure out suffix of lib
# See: https://doc.rust-lang.org/reference/linkage.html
LIB_SUFFIX=".so"
case ${{ matrix.job.target }} in
*-apple-darwin) LIB_SUFFIX=".dylib" ;;
*-pc-windows-*) LIB_SUFFIX=".dll" ;;
esac;
CICD_INTERMEDIATES_DIR=$(mktemp -d)
# Setup paths
LIB_DIR="${CICD_INTERMEDIATES_DIR}/released-lib"
mkdir -p "${LIB_DIR}"
LIB_NAME="${LIB_PREFIX}${{ env.PROJECT_NAME }}${LIB_SUFFIX}"
LIB_PATH="${LIB_DIR}/${LIB_NAME}"
# Copy the release build lib to the result location
cp "target/${{ matrix.job.target }}/release/${LIB_NAME}" "${LIB_DIR}"
# Final paths
# In the end we use ".so" for MacOS in the final build
# See: https://www.erlang.org/doc/man/erlang.html#load_nif-2
LIB_FINAL_SUFFIX="${LIB_SUFFIX}"
case ${{ matrix.job.target }} in
*-apple-darwin) LIB_FINAL_SUFFIX=".so" ;;
esac;
LIB_FINAL_NAME="${LIB_PREFIX}${PROJECT_NAME}-v${PROJECT_VERSION}-nif-${RUSTLER_NIF_VERSION}-${{ matrix.job.target }}${LIB_FINAL_SUFFIX}"
# Copy lib to final name on this directory
cp "${LIB_PATH}" "${LIB_FINAL_NAME}"
tar -cvzf "${LIB_FINAL_NAME}.tar.gz" "${LIB_FINAL_NAME}"
# Passes the path relative to the root of the project.
LIB_FINAL_PATH="${NIF_DIRECTORY}/${LIB_FINAL_NAME}.tar.gz"
# Let subsequent steps know where to find the lib
echo "LIB_FINAL_PATH=${LIB_FINAL_PATH}" >> $GITHUB_OUTPUT
echo "LIB_FINAL_NAME=${LIB_FINAL_NAME}.tar.gz" >> $GITHUB_OUTPUT
- name: "Artifact upload"
uses: actions/upload-artifact@v3
with:
name: ${{ steps.rename.outputs.LIB_FINAL_NAME }}
path: ${{ steps.rename.outputs.LIB_FINAL_PATH }}
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
with:
files: |
${{ steps.rename.outputs.LIB_FINAL_PATH }}
if: startsWith(github.ref, 'refs/tags/')