-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
169 lines (144 loc) · 5.65 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
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.
required: false
default: "v0.2.4"
use-cross:
description: If the target requires the usage of cross.
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: "./"
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: Download cross from GitHub releases
uses: giantswarm/install-binary-action@v1.1.0
if: ${{ inputs.use-cross }}
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: 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"
- name: Build
shell: bash
run: |
INITIAL_DIR=$(pwd)
echo "Going from path: $INITIAL_DIR"
echo "To path: ${{ inputs.project-dir }}"
cd "${{ inputs.project-dir }}"
if [ "${{ inputs.use-cross }}" == "true" ]; then
if grep --quiet "RUSTLER_NIF_VERSION" "Cross.toml"; then
echo "Cross configuration looks good."
else
echo "::error file=Cross.toml,line=1::Missing configuration for passing the RUSTLER_NIF_VERSION env var to cross. Please read the precompilation guide: https://hexdocs.pm/rustler_precompiled/precompilation_guide.html#additional-configuration-before-build"
exit 1
fi
cross build --release --target=${{ inputs.target }}
else
cargo build --release --target=${{ inputs.target }}
fi
cd "$INITIAL_DIR"
- 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;
# Setup paths
LIB_NAME="${LIB_PREFIX}${{ inputs.project-name }}${LIB_SUFFIX}"
LIB_DIR="target/${{ inputs.target }}/release"
# 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;
# 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 }}${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