-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaction.yml
297 lines (263 loc) · 11.1 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
---
name: "Setup Ruby and Rust"
description: "Setup Ruby and Rust for GitHub Actions"
author: "Ian Ker-Seymer"
branding:
icon: "download"
color: "gray-dark"
inputs:
ruby-version:
description: "Engine and version to use, see the syntax in the README. Reads from .ruby-version or .tool-versions if unset. Can be set to 'none' to skip installing Ruby."
default: "default"
bundler-cache:
description: 'Run "bundle install", and cache the result automatically. Either true or false.'
default: "false"
rubygems:
description: "Runs `gem update --system`. See https://github.com/ruby/setup-ruby/blob/master/README.md for more info."
required: false
default: 'default'
working-directory:
description: "The working directory to use for resolving paths for .ruby-version, .tool-versions and Gemfile.lock."
cache-version:
default: "v0"
description: |
Arbitrary string that will be added to the cache key of the bundler cache. Set or change it if you need
to invalidate the cache.
rustup-toolchain:
description: |
Rustup toolchain specifier e.g. stable, nightly, 1.42.0, nightly-2022-01-01.
default: stable
rustup-targets:
description: |
Comma-separated string of additional targets to install e.g. wasm32-unknown-unknown
default: ""
rustup-components:
description: |
Comma-separated string of additional components to install e.g. clippy, rustfmt
default: clippy, rustfmt
cargo-cache:
description: "Strategy to use for caching build artifacts (either 'sccache', 'tarball', or 'false')"
default: "default"
cargo-cache-clean:
description: "Clean the cargo cache with cargo cache --autoclean"
default: "true"
cargo-cache-extra-path:
description: "Paths to cache for cargo and gem compilation"
cargo-vendor:
description: "Vendor cargo dependencies to avoid repeated downloads"
default: "false"
debug:
description: "Enable verbose debugging info (includes summary of action)"
default: "false"
outputs:
ruby-prefix:
description: "The prefix of the installed ruby"
value: ${{ steps.set-outputs.outputs.ruby-prefix }}
ruby-platform:
description: "The platform of the installed ruby"
value: ${{ steps.set-outputs.outputs.ruby-platform }}
cache-key:
description: "Derived cache key for the current environment"
value: ${{ steps.set-outputs.outputs.cache-key }}
runs:
using: "composite"
steps:
- uses: "ruby/setup-ruby-pkgs@v1"
if: inputs.ruby-version != 'none'
with:
ruby-version: ${{ inputs.ruby-version }}
bundler-cache: ${{ inputs.bundler-cache }}
working-directory: ${{ inputs.working-directory }}
cache-version: ${{ inputs.cache-version }}
rubygems: ${{ inputs.rubygems }}
# for now we have to use clang-15 for mingw builds, since our bindgen is too old to work with clang-16
mingw: clang-15
- name: Install helpers
shell: bash
run: |
: Install helpers
echo "$GITHUB_ACTION_PATH/bin" >> $GITHUB_PATH
- name: Print rbconfig
if: inputs.ruby-version != 'none'
shell: bash
run: |
: Print rbconfig
echo "::group::Print rbconfig below"
rbconfig
echo "::endgroup::"
- name: Derive toolchain
id: derive-toolchain
shell: bash
run: |
: Derive toolchain
derived_toolchain="$(ruby --disable-gems $GITHUB_ACTION_PATH/helpers/derive_toolchain.rb ${{ inputs.rustup-toolchain }})"
echo "toolchain=$derived_toolchain" >> $GITHUB_OUTPUT
- uses: dtolnay/rust-toolchain@master
id: rust-toolchain
with:
toolchain: ${{ steps.derive-toolchain.outputs.toolchain }}
targets: ${{ inputs.rustup-targets }}
components: ${{ inputs.rustup-components }}
- name: Clean out alternative Windows toolchains (to avoid compiler conflicts)
shell: bash
if: runner.os == 'Windows'
run: |
IFS=$'\n\t'
for toolchain in $(rustup toolchain list); do
if [[ "$toolchain" != *"default"* ]]; then
echo "Uninstalling $toolchain"
rustup toolchain uninstall "$toolchain"
fi
done
- name: Set outputs
id: set-outputs
shell: bash
run: |
: Set outputs
ruby_platform="$(rbconfig arch)"
ruby_version="$(rbconfig MAJOR).$(rbconfig MINOR).$(rbconfig TEENY)"
echo "ruby-prefix=$(rbconfig prefix)" >> $GITHUB_OUTPUT
echo "ruby-platform=$ruby_platform" >> $GITHUB_OUTPUT
base_cache_level_1="${{ inputs.cache-version }}__${{ steps.rust-toolchain.outputs.cachekey }}__${ruby_platform}"
base_cache_level_2="${base_cache_level_1}__${{ hashFiles('**/Cargo.toml') }}"
base_cache_level_3="${base_cache_level_2}__${{ hashFiles('**/Cargo.lock') }}"
echo "base-cache-key-level-1=$base_cache_level_1" >> $GITHUB_OUTPUT
echo "base-cache-key-level-2=$base_cache_level_2" >> $GITHUB_OUTPUT
echo "base-cache-key-level-3=$base_cache_level_3" >> $GITHUB_OUTPUT
echo "cache-key=$base_cache_level_3" >> $GITHUB_OUTPUT
ruby --disable-gems $GITHUB_ACTION_PATH/helpers/cargo_registry_cache_keys.rb
if [ "${{ inputs.cargo-cache }}" = "true" ]; then
echo "cargo-cache=tarball" >> $GITHUB_OUTPUT
elif [ "${{ inputs.cargo-cache }}" = "default" ]; then
echo "cargo-cache=tarball" >> $GITHUB_OUTPUT
else
echo "cargo-cache=${{ inputs.cargo-cache }}" >> $GITHUB_OUTPUT
fi
- name: Configure environment
shell: bash
run: |
: Configure environment
echo "::group::Configuring environment"
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
echo "CARGO_NET_RETRY=5" >> $GITHUB_ENV
echo "RUBY_VERSION=$(rbconfig ruby_version)" >> $GITHUB_ENV
if [ "${{ inputs.debug }}" = "true" ]; then
echo "::info::Setting debug mode"
echo "RB_SYS_DEBUG_BUILD=1" >> $GITHUB_ENV
echo "SCCACHE_LOG=debug" >> $GITHUB_ENV
fi
- name: Install cargo-cache
uses: oxidize-rb/actions/cargo-binstall@v1
id: install-cargo-cache
if: inputs.cargo-cache-clean == 'true' && steps.set-outputs.outputs.cargo-cache == 'tarball'
with:
crate: cargo-cache
version: 0.8.3
strategies: quick-install
install-path: ${{ github.action_path }}/bin
- name: Cargo registry cache
uses: actions/cache@v3
if: steps.set-outputs.outputs.cargo-cache != 'false'
with:
key: ${{ steps.set-outputs.outputs.cargo-registry-cache-key }}
restore-keys: |
${{ steps.set-outputs.outputs.cargo-registry-restore-keys }}
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
- name: Setup base cargo cache
uses: actions/cache@v3
if: steps.set-outputs.outputs.cargo-cache == 'tarball'
with:
key: ${{ steps.set-outputs.outputs.base-cache-key-level-3 }}
path: |
~/.cargo/bin/
./target/
restore-keys: |
${{ steps.set-outputs.outputs.base-cache-key-level-2 }}
${{ steps.set-outputs.outputs.base-cache-key-level-1 }}
- name: Clean the cargo cache
if: inputs.cargo-cache-clean == 'true' && steps.set-outputs.outputs.cargo-cache == 'tarball'
uses: oxidize-rb/actions/post-run@v1
with:
run: cargo-cache --autoclean
cwd: ${{ inputs.working-directory }}
- name: Install sccache
uses: oxidize-rb/actions/cargo-binstall@v1
if: steps.set-outputs.outputs.cargo-cache == 'sccache'
with:
crate: sccache
version: 0.3.3
strategies: quick-install
install-path: ${{ github.action_path }}/bin
- name: Configure sccache
if: steps.set-outputs.outputs.cargo-cache == 'sccache'
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
core.exportVariable('RUSTC_WRAPPER', process.env.RUSTC_WRAPPER || 'sccache');
core.exportVariable('SCCACHE_C_CUSTOM_CACHE_BUSTER', '${{ inputs.cache-version }}-${{ steps.rust-toolchain.outputs.cachekey }}');
- name: Install sccache
if: steps.set-outputs.outputs.cargo-cache == 'sccache'
shell: bash
run: |
: Setup sccache
cache_from="${{ steps.rust-toolchain.outputs.cachekey }}__${{ steps.derive-toolchain.outputs.toolchain }}"
cache_to="${cache_from}__${GITHUB_SHA}"
echo "SCCACHE_GHA_CACHE_FROM=$cache_from" >> $GITHUB_ENV
echo "SCCACHE_GHA_CACHE_TO=$cache_to" >> $GITHUB_ENV
- name: Set LD_LIBRARY_PATH for Ruby (linux)
if: runner.os == 'Linux' && inputs.ruby-version != 'none'
shell: bash
run: |
: Set LD_LIBRARY_PATH for Ruby
echo "::group::Adding Ruby libdir to LD_LIBRARY_PATH"
libdir="$(rbconfig libdir)"
echo "Ruby libdir is $libdir"
if [ ! -z "$LD_LIBRARY_PATH" ]; then
echo "::info::Appending to LD_LIBRARY_PATH"
echo "LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH" >> $GITHUB_ENV
else
echo "::info::Setting new LD_LIBRARY_PATH"
echo "LD_LIBRARY_PATH=$libdir" >> $GITHUB_ENV
fi
echo "::endgroup::"
- name: Vendor cargo dependencies
if: inputs.cargo-vendor == 'true'
shell: bash
run: |
: Vendor cargo dependencies
echo "::group::Vendoring cargo deps"
[ "${{ inputs.working-directory }}" != "" ] && pushd "${{ inputs.working-directory }}"
mkdir -p .cargo tmp && cargo vendor "$PWD/tmp/cargo-vendor" >> .cargo/config.toml
[ "${{ inputs.working-directory }}" != "" ] && popd
echo "::endgroup::"
- name: Configure bindgen
if: contains(steps.derive-toolchain.outputs.toolchain, 'msvc')
shell: pwsh
run: |
echo LIBCLANG_PATH="$((gcm clang).source -replace 'clang.exe')" >> $env:GITHUB_ENV
echo BINDGEN_EXTRA_CLANG_ARGS="-I$((gcm clang).source -replace 'bin\clang.exe', 'include')" >> $env:GITHUB_ENV
- name: Configure bindgen
if: contains(steps.derive-toolchain.outputs.toolchain, 'pc-windows-gnu')
shell: bash
run: |
: Configure bindgen for msys2
msys_root=""
if [ "$MSYSTEM" = "MINGW64" ]; then
msys_root="c:/msys64/mingw64"
elif [ "$MSYSTEM" = "UCRT64" ]; then
msys_root="c:/msys64/ucrt64"
else
echo "Unknown MSYSTEM: $MSYSTEM, cannot configure bindgen"
exit 1
fi
# We can't use llvm-16 just yet due to backwards compatibility issues, so we have to workaround for now
echo MSYS_ROOT="$msys_root" >> $GITHUB_ENV
echo LIBCLANG_PATH="$msys_root/opt/llvm-15/bin" >> $GITHUB_ENV
echo BINDGEN_EXTRA_CLANG_ARGS="--target=${{ steps.derive-toolchain.outputs.toolchain }} --sysroot=$msys_root" >> $GITHUB_ENV
echo "::info::Set LIBCLANG_PATH to $LIBCLANG_PATH"
echo "::info::Set BINDGEN_EXTRA_CLANG_ARGS to $BINDGEN_EXTRA_CLANG_ARGS"