-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
206 lines (175 loc) · 7.17 KB
/
action.yml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Rustler Precompiled Action
description: Precompiles Rustler projects and outputs files in the expected filenames.
branding:
icon: cpu
color: purple
inputs:
project-name:
description: Name of the crate that is being built. This is the same of the Cargo.toml of the crate.
required: true
project-version:
description: The version to use in the name of the lib. This mostly matches the Elixir package version.
required: true
cross-version:
description: >
The version desired for cross, the tool that builds for multiple plataforms.
It's possible to specify a version, or the string "from-source" to install
from the main branch of the project repository.
required: false
default: "v0.2.4"
use-cross:
description: If the target requires the usage of cross.
type: boolean
required: false
default: false
target:
description: The Rust target we are building to.
required: true
nif-version:
description: The NIF version that we are aiming to.
default: "2.16"
required: false
project-dir:
description: >
A relative path where the project is located.
The script is going to enter this path in order to compile the NIF.
For example, "native/my_nif".
required: true
default: "./"
variant:
description: >
An alternative version for a given target that is useful when you are building for
the same target, but with different dependencies, or hardware capatibilities.
This name should be a valid string that can be represented as an Elixir atom.
Prefer to use only alphanumerics and underscores.
This is going to be appended to the artifact name.
required: false
default: ""
cargo-args:
description: >
A string with additional arguments to be appended to the build command.
This is useful to pass flags like `--features`.
Notice that the flags `--release` and `--target` are going to be
passed down automatically.
The flag `--features` may be passed, depending of the NIF version. But you can
always pass this flag multiple times.
required: false
default: ""
outputs:
file-name:
description: The tarball compressed file name that was generated.
value: ${{ steps.rename.outputs.file-name }}
file-path:
description: >
The file path of the tar.gz generated.
For compatible reasons, this is equal to the file name.
The final file is going to be placed at the root of your project.
value: ${{ steps.rename.outputs.file-path }}
file-sha256:
description: The SHA256 of the tarball file.
value: ${{ steps.rename.outputs.file-sha256 }}
runs:
using: "composite"
steps:
- name: Set the NIF version as env var
shell: bash
run: |
echo "RUSTLER_NIF_VERSION=${{ inputs.nif-version }}" >> $GITHUB_ENV
- name: Add the action path to the gh paths to find scripts
shell: bash
run: |
# Both needed because they are unexpectedly different for containers apparently:
# https://github.com/actions/runner/pull/1762#issuecomment-1105843659
echo "${{ github.action_path }}" >> $GITHUB_PATH
echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
- name: Download cross from GitHub releases
uses: giantswarm/[email protected]
if: ${{ inputs.use-cross && inputs.cross-version != 'from-source' }}
with:
binary: "cross"
version: ${{ inputs.cross-version }}
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: Install cross from GitHub latest revision
shell: bash
if: ${{ inputs.use-cross && inputs.cross-version == 'from-source' }}
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Show version information (Rust, cargo, GCC, NIF version)
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
rustc --print=cfg
echo "env RUSTLER_NIF_VERSION=$RUSTLER_NIF_VERSION"
echo "env RUSTFLAGS=$RUSTFLAGS"
echo "env RUSTLER_PRECOMPILED_DEBUG_MODE=$RUSTLER_PRECOMPILED_DEBUG_MODE"
- name: Build
shell: bash
run: |
build.sh "$(pwd)" "${{ inputs.project-dir }}" "${{ inputs.target }}" "${{ inputs.nif-version }}" "${{ inputs.use-cross }}" "${{ inputs.cargo-args }}"
- name: Rename lib to the final name
id: rename
shell: bash
run: |
INITIAL_DIR=$(pwd)
echo "Going from path: $INITIAL_DIR"
echo "To path: ${{ inputs.project-dir }}"
cd "${{ inputs.project-dir }}"
LIB_PREFIX="lib"
case ${{ inputs.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 ${{ inputs.target }} in
*-apple-darwin) LIB_SUFFIX=".dylib" ;;
*-pc-windows-*) LIB_SUFFIX=".dll" ;;
esac;
TARGET_MODE_DIR="release"
# A scape hatch to improve build times for when a release is not the intention.
if [ "$RUSTLER_PRECOMPILED_DEBUG_MODE" = "true" ]; then
TARGET_MODE_DIR="debug"
fi
# Setup paths
LIB_NAME="${LIB_PREFIX}${{ inputs.project-name }}${LIB_SUFFIX}"
LIB_DIR="target/${{ inputs.target }}/${TARGET_MODE_DIR}"
# Final name
# 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 ${{ inputs.target }} in
*-apple-darwin) LIB_FINAL_SUFFIX=".so" ;;
esac;
MAYBE_VARIANT_NAME="${{ inputs.variant }}"
if [[ $MAYBE_VARIANT_NAME != "" ]]; then
MAYBE_VARIANT_NAME="--${MAYBE_VARIANT_NAME}"
fi
# It saves in the format RustlerPrecompiled expects.
LIB_FINAL_NAME="${LIB_PREFIX}${{ inputs.project-name }}-v${{ inputs.project-version }}-nif-${{ inputs.nif-version }}-${{ inputs.target }}${MAYBE_VARIANT_NAME}${LIB_FINAL_SUFFIX}"
TAR_GZ_FILE="${LIB_FINAL_NAME}.tar.gz"
cd "${LIB_DIR}"
# Copy with the correct final name.
cp "${LIB_NAME}" "${LIB_FINAL_NAME}"
tar -cvzf "${TAR_GZ_FILE}" "${LIB_FINAL_NAME}"
case ${{ runner.os }} in
macOS) FILE_SHA256=$(shasum -a 256 "${TAR_GZ_FILE}" | cut -d' ' -f1) ;;
*) FILE_SHA256=$(sha256sum "${TAR_GZ_FILE}" | cut -d' ' -f1) ;;
esac;
echo "File name: ${TAR_GZ_FILE}"
echo "SHA256: ${FILE_SHA256}"
# Move the tar gz to the initial/root dir. This is necessary because Windows cannot find
# inside the path we provide.
mv "${TAR_GZ_FILE}" "${INITIAL_DIR}/"
# Go back to the initial path.
cd "${INITIAL_DIR}"
# Let subsequent steps know where to find the lib.
echo "file-path=${TAR_GZ_FILE}" >> $GITHUB_OUTPUT
echo "file-name=${TAR_GZ_FILE}" >> $GITHUB_OUTPUT
echo "file-sha256=${FILE_SHA256}" >> $GITHUB_OUTPUT