forked from extendr/extendr
-
Notifications
You must be signed in to change notification settings - Fork 0
455 lines (390 loc) · 21.3 KB
/
test.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
name: Tests
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
# cargo error handling is wrapped by ci-cargo, for simplicity and better logging.
# To use ci-cargo in a step, source ci-cargo.ps1 (using `. ./ci-cargo.ps`, note the extra dot in front).
# ci-cargo does not handle correctly -- separator, so wrap it in quotes ('--')
# A special named parameter called `ActionName` can be used to set the name of current ci-cargo action,
# used as `ci-cargo .... -ActionName "Called for documentation purposes"`.
jobs:
# All tests under this job are run with pre-computed libR-sys bindings.
tests_no_bindgen:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (R-${{ matrix.config.r }} rust-${{ matrix.config.rust-version }})
strategy:
fail-fast: false
matrix:
config:
- { os: windows-latest, r: 'release', rust-version: 'stable-msvc', rtools-version: '43' }
- { os: windows-latest, r: 'devel', rust-version: 'stable-msvc', rtools-version: '44' }
- { os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rtools-version: '42' }
- { os: macOS-latest, r: 'release', rust-version: 'stable' }
# - {os: macOS-latest, r: 'release', rust-version: 'nightly'}
# - {os: macOS-latest, r: 'devel', rust-version: 'stable'}
# - {os: macOS-latest, r: 'oldrel', rust-version: 'stable'}
- { os: ubuntu-latest, r: 'release', rust-version: 'stable', check_fmt: true }
- { os: ubuntu-latest, r: 'release', rust-version: 'nightly' }
# R-devel requires LD_LIBRARY_PATH
- { os: ubuntu-latest, r: 'devel', rust-version: 'stable' }
- { os: ubuntu-latest, r: 'oldrel', rust-version: 'stable' }
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
# This environment variable enables support for pseudo multi-target cargo builds.
# Current stable Rust does not support multi-targeting,
# see https://github.com/rust-lang/cargo/issues/8176
# The variable is treated as a comma-separated list of valid Rust targets.
# 'default' value emits no '--target' flag.
# E.g.: BUILD_TARGETS=i686-pc-windows-gnu,x86_64-pc-windows-gnu builds two times,
# each time providing '--target=*-pc-windows-gnu' flag to cargo.
BUILD_TARGETS: default
# PowerShell core is available on all platforms and can be used to unify scripts
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.config.rust-version }}
components: rustfmt, clippy
- name: Install cargo-expand
uses: dtolnay/install@master
if: startsWith(runner.os, 'Windows') != true
with:
crate: cargo-expand
# https://github.com/dtolnay/install/issues/12
- name: Install cargo-expand (dtolnay/install#12 workaround)
if: startsWith(runner.os, 'Windows')
run: cargo install cargo-expand
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
rtools-version: ${{ matrix.config.rtools-version }}
# TODO: enable RSPM when all the packages are available
use-public-rspm: true
- name: Set up Pandoc
uses: r-lib/actions/setup-pandoc@v2
- name: Configure Windows
if: startsWith(runner.os, 'Windows')
run: |
$rtools_home = "C:\rtools${{ matrix.config.rtools-version }}"
# c.f. https://github.com/wch/r-source/blob/f1501504df8df1668a57d3a1b6f80167f24441d3/src/library/profile/Rprofile.windows#L70-L71
echo "${rtools_home}\x86_64-w64-mingw32.static.posix\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
echo "${rtools_home}\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
# Add target
rustup target add x86_64-pc-windows-gnu
echo "BUILD_TARGETS=x86_64-pc-windows-gnu" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ;
# The following lines add two tweaks:
#
# 1. Change the linker name to "x86_64-w64-mingw32.static.posix-gcc.exe".
# 2. Add empty libgcc_s.a and libgcc_eh.a, and add them to the compiler's
# library search paths via `LIBRARY_PATH` envvar.
#
# The first tweak is needed because Rtools42 doesn't contain
# "x86_64-w64-mingw32-gcc," which `rustc` uses as the default linker
# for the `x86_64-pc-windows-gnu` target.
#
# If we use the Rtools' toolchain, the second tweak is also required.
# `rustc` adds `-lgcc_eh` and `-lgcc_s` flags to the compiler, but
# Rtools' GCC doesn't have `libgcc_eh` or `libgcc_s` due to the
# compilation settings. So, in order to please the compiler, we need
# to add empty `libgcc_eh` or `libgcc_s` to the library search paths.
#
# For more details, please refer to https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
New-Item -Path libgcc_mock -Type Directory
New-Item -Path libgcc_mock\libgcc_eh.a -Type File
New-Item -Path libgcc_mock\libgcc_s.a -Type File
New-Item -Path .cargo -ItemType Directory -Force
$pwd_slash = echo "${PWD}" | % {$_ -replace '\\','/'}
echo "LIBRARY_PATH=${pwd_slash}/libgcc_mock;$env:LIBRARY_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
@"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32.static.posix-gcc.exe"
"@ | Out-File -FilePath .cargo/config.toml -Encoding utf8 -Append ;
env:
RUST_TOOLCHAIN: ${{ matrix.config.rust-version }}
# This is required for ubuntu r-devel
# 'Del alias:R' removes 'R' alias which prevents running R
- name: Configure Linux
if: startsWith(runner.os, 'linux')
run: |
Del alias:R
echo "LD_LIBRARY_PATH=$(R -s -e 'cat(normalizePath(R.home()))')/lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# Check code formatting. As this doesn't depend on the platform, do this only on one platform.
- name: Check code formatting
if: matrix.config.check_fmt
run: cargo fmt -- --check
# For each target in the BUILD_TARGETS comma-separated list, run cargo build with appropriate target
# Required by Windows builds, does not affect other platforms
- name: Build
run: |
. ./ci-cargo.ps1
foreach($target in ($env:BUILD_TARGETS).Split(',')) {
ci-cargo build $(if($target -ne 'default') {"--target=$target"} ) -ActionName "Building for $target target"
}
# For each target in the BUILD_TARGETS comma-separated list, run cargo test with appropriate target
# Required by Windows builds, does not affect other platforms
# ! ci-cargo requires '--' to be wrapped in quotes (passed as an explicit string)
- name: Run tests
run: |
. ./ci-cargo.ps1
foreach($target in ($env:BUILD_TARGETS).Split(',')) {
# Note: no feature is specified, which means such features like graphics, serde, ndarray, and num-complex are not tested here.
ci-cargo test $(if($target -ne 'default') {"--target=$target"} ) '--' --nocapture -ActionName "Testing for $target target"
}
env:
LIBRARY_PATH: ${{ env.LIBRARY_PATH }}
RUST_BACKTRACE: 1
# c.f. https://github.com/actions/checkout#checkout-multiple-repos-side-by-side
- name: Obtain 'rextendr'
uses: actions/checkout@v4
with:
submodules: 'true'
repository: extendr/rextendr
path: ./tests/rextendr
- name: Install dependencies for extendrtests and rcmdcheck
uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 4
working-directory: tests/extendrtests
extra-packages: any::rcmdcheck
- name: Install dependencies for rextendr
uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 4
working-directory: tests/rextendr
# TODO: allow warnings on oldrel (cf., https://stat.ethz.ch/pipermail/r-package-devel/2023q2/009229.html)
- name: Check R version
id: error-on
run: |
output <- Sys.getenv("GITHUB_OUTPUT")
if (.Platform$OS.type == "windows" && getRversion() < "4.3.0") {
cat('level=error', file = output, append = TRUE)
} else {
cat('level=warning', file = output, append = TRUE)
}
shell: Rscript {0}
- name: Run R integration tests using {extendrtests} and `cargo extendr r-cmd-check`
id: id_cargo_r_cmd_check
run: |
cargo extendr r-cmd-check --error-on ${{ steps.error-on.outputs.level }} --check-dir extendrtests_check
- name: Upload `check-dir` if r-cmd-check failed on `{extendrtests}`
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}-{1}-r{2}-rust-version{3}-{4}-results', runner.os, runner.arch, matrix.config.r, matrix.config.rust-version, matrix.config.id || strategy.job-index) }}
path: extendrtests_check
# With https://github.com/extendr/rextendr/pull/31
# rextendr can be configured using environment variables.
# 'patch.crates_io' is used to point libraries to local copies of
# extendr-api and extendr-macros, so rextendr tests current version of extendr-*
- name: Prepare for R integration tests using {rextendr}
id: rextendr_check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
cat("::group::Preparing 'rextendr'\n")
patch.crates_io <-
paste(
paste0(
"extendr-api = { path = \"",
normalizePath(file.path(getwd(), "extendr-api"), winslash = "/"),
"\" }"),
paste0(
"extendr-macros = { path = \"",
normalizePath(file.path(getwd(), "extendr-macros"), winslash = "/"),
"\" }"),
# uncomment this line when we need to depend on the dev version of libR-sys
#'libR-sys = { git = "https://github.com/extendr/libR-sys" }',
# use the embedded libR-sys submodule
paste0(
"libR-sys = { path = \"",
normalizePath(file.path(getwd(), "libR-sys"), winslash = "/"),
"\" }"),
sep = ";")
patch.crates_io <- paste0("REXTENDR_PATCH_CRATES_IO=", patch.crates_io)
github_env_file <- Sys.getenv("GITHUB_ENV")
cat(patch.crates_io, file = github_env_file, append = TRUE)
cat("::endgroup::\n")
shell: Rscript {0}
- name: Run R integration tests using {rextendr}
env:
REXTENDR_SKIP_DEV_TESTS: 1
uses: r-lib/actions/check-r-package@v2
with:
args: 'c("--no-manual", "--as-cran", "--force-multiarch")'
working-directory: 'tests/rextendr'
check-dir: '"rextendr_check"'
error-on: '"${{ steps.error-on.outputs.level }}"'
# All tests under this job are run with R devel and freshly generated bindings.
# Run bindgen tests without cross-compilation.
# Cross-compilation prevents from running doc tests
# if toolchain does not match target (Windows x86_64/i686 case), see
# > https://github.com/rust-lang/rust/issues/64245
# > https://github.com/rust-lang/cargo/issues/7040
bindgen:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} w/ bindgen (R-${{ matrix.config.r }} rust-${{ matrix.config.rust-version }} ${{join(matrix.config.rust-targets, ',')}})
strategy:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: 'devel', rust-version: 'stable' }
- { os: macOS-latest, r: 'devel', rust-version: 'stable' }
- { os: windows-latest, r: 'release', rust-version: 'stable-msvc', rust-targets: [ 'x86_64-pc-windows-gnu' ], rtools-version: '43' }
- { os: windows-latest, r: 'devel', rust-version: 'stable-msvc', rust-targets: [ 'x86_64-pc-windows-gnu' ], rtools-version: '44' }
# When the MSVC target is used, since it's cross-compilation from MSVC
# to GNU, the doc tests are usually skipped. Adding `-Zdoctest-xcompile`
# lets the doctests run, which accordingly require the nightly toolchain.
- { os: windows-latest, r: 'release', rust-version: 'nightly-msvc', rust-targets: [ 'x86_64-pc-windows-gnu' ], rtools-version: '43', extra-args: [ '-Zdoctest-xcompile' ] }
- { os: windows-latest, r: 'oldrel', rust-version: 'nightly-msvc', rust-targets: [ 'x86_64-pc-windows-gnu' ], rtools-version: '42', extra-args: [ '-Zdoctest-xcompile' ] }
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
# PowerShell core is available on all platforms and can be used to unify scripts
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.config.rust-version }}
# 1. Update rustup
# 2. For each target add respective toolchain &
# update target for that toolchain
- name: Set up Rust targets
run: |
$targets = $env:RUST_TARGETS.Split(',')
foreach ($target in $targets) {
echo "::group::Setting up $env:RUST_TOOLCHAIN $target"
if ($target -ne '') {
rustup target add $target --toolchain "$env:RUST_TOOLCHAIN"
if(!$?) {
throw "Last exit code $LASTEXITCODE"
}
}
echo "::endgroup::"
}
env:
RUST_TARGETS: ${{ join(matrix.config.rust-targets, ',') }}
RUST_TOOLCHAIN: ${{ matrix.config.rust-version }}
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
rtools-version: ${{ matrix.config.rtools-version }}
use-public-rspm: true
windows-path-include-mingw: false
- name: Configure Windows
if: startsWith(runner.os, 'Windows')
run: |
$rtools_home = "C:\rtools${{ matrix.config.rtools-version }}"
echo "::group::Setting up x86_64"
# c.f. https://github.com/wch/r-source/blob/f1501504df8df1668a57d3a1b6f80167f24441d3/src/library/profile/Rprofile.windows#L70-L71
echo "${rtools_home}\x86_64-w64-mingw32.static.posix\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
echo "${rtools_home}\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "::endgroup::"
# The following lines add two tweaks:
#
# 1. Change the linker name to "x86_64-w64-mingw32.static.posix-gcc.exe".
# 2. Add empty libgcc_s.a and libgcc_eh.a, and add them to the compiler's
# library search paths via `LIBRARY_PATH` envvar.
#
# The first tweak is needed because Rtools42 doesn't contain
# "x86_64-w64-mingw32-gcc," which `rustc` uses as the default linker
# for the `x86_64-pc-windows-gnu` target.
#
# If we use the Rtools' toolchain, the second tweak is also required.
# `rustc` adds `-lgcc_eh` and `-lgcc_s` flags to the compiler, but
# Rtools' GCC doesn't have `libgcc_eh` or `libgcc_s` due to the
# compilation settings. So, in order to please the compiler, we need
# to add empty `libgcc_eh` or `libgcc_s` to the library search paths.
#
# For more details, please refer to https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
New-Item -Path libgcc_mock -Type Directory
New-Item -Path libgcc_mock\libgcc_eh.a -Type File
New-Item -Path libgcc_mock\libgcc_s.a -Type File
New-Item -Path .cargo -ItemType Directory -Force
$pwd_slash = echo "${PWD}" | % {$_ -replace '\\','/'}
echo "LIBRARY_PATH=${pwd_slash}/libgcc_mock;$env:LIBRARY_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
@"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32.static.posix-gcc.exe"
"@ | Out-File -FilePath .cargo/config.toml -Encoding utf8 -Append ;
env:
RUST_TARGETS: ${{ join(matrix.config.rust-targets, ',') }}
- name: Configure Linux
if: startsWith(runner.os, 'linux')
run: |
Del alias:R
echo "LD_LIBRARY_PATH=$(R -s -e 'cat(normalizePath(R.home()))')/lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# 1. Retrieve targets
# 2. Retrieve 'libcalng' paths
# 3. For each target run
# 3.1 Select correct $target & $toolchain
# 3.x Run build commands, checking for errors, providing explicit toolchain & target
- name: Build
run: |
echo $LIBRARY_PATH
echo $env:LIBRARY_PATH
. ./ci-cargo.ps1
$targets = $env:BUILD_TARGETS.Split(',')
$toolchain = $env:RUST_TOOLCHAIN
$itt = 0..($targets.Length - 1)
foreach($i in $itt) {
if ($targets[$i] -eq "") {
$target = 'default'
}
else {
$target = $targets[$i]
}
ci-cargo +$toolchain build --manifest-path extendr-api/Cargo.toml --features tests-all $(if($target -ne 'default') {"--target=$target"} ) -ActionName "Build extendr-api for $toolchain/$target"
ci-cargo +$toolchain build --manifest-path extendr-engine/Cargo.toml --features tests-all $(if($target -ne 'default') {"--target=$target"} ) -ActionName "Build extendr-engine for $toolchain/$target"
}
env:
BUILD_TARGETS: ${{ join(matrix.config.rust-targets, ',') }}
RUST_TOOLCHAIN: ${{ matrix.config.rust-version }}
# Identical to the build process, but running more test commands
# ! ci-cargo requires '--' to be wrapped in quotes (passed as an explicit string)
- name: Run tests
run: |
. ./ci-cargo.ps1
$targets = $env:BUILD_TARGETS.Split(',')
$toolchain = $env:RUST_TOOLCHAIN
$itt = 0..($targets.Length - 1)
foreach($i in $itt) {
if ($targets[$i] -eq "") {
$target = 'default'
}
else {
$target = $targets[$i]
}
ci-cargo +$toolchain test --manifest-path extendr-engine/Cargo.toml --features tests-all $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture -ActionName "Test extendr-engine \w tests-all for $target target"
ci-cargo +$toolchain test --manifest-path extendr-api/Cargo.toml --features tests $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture -ActionName "Test extendr-api \w tests for $target target"
# graphics tests requires --test-threads=1
ci-cargo +$toolchain test graphics_tests:: --manifest-path extendr-api/Cargo.toml --features tests-graphics $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture --test-threads=1 -ActionName "Test extendr-api \w graphics for $target target"
ci-cargo +$toolchain test --manifest-path extendr-api/Cargo.toml --features tests-minimal $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture -ActionName "Test extendr-api \w tests-minimal for $target target"
ci-cargo +$toolchain test test_result_list --manifest-path extendr-api/Cargo.toml --features tests-minimal,result_list $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture -ActionName "Test extendr-api \w tests-minimal for $target target with `result_list` feature"
ci-cargo +$toolchain test test_result_condition --manifest-path extendr-api/Cargo.toml --features tests-minimal,result_condition $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture -ActionName "Test extendr-api \w tests-minimal for $target target with `result_condition` feature"
ci-cargo +$toolchain test --manifest-path extendr-macros/Cargo.toml $(if($target -ne 'default') {"--target=$target"} ) $env:EXTRA_ARGS '--' --nocapture -ActionName "Test extendr-macros for $target target"
}
env:
BUILD_TARGETS: ${{ join(matrix.config.rust-targets, ',') }}
RUST_TOOLCHAIN: ${{ matrix.config.rust-version }}
EXTRA_ARGS: ${{ join(matrix.config.extra-args, ',') }}