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