Skip to content

Commit bcacb42

Browse files
Cross-compiling and precomputed bindings for Mac-aarch64 (#45)
* Removed unused 'msystem' * Set up multiple targets * Enabling linux path * Running multiple tests * Correct handling of RUST_TARGETS and Windows support * Adding default MacOS * Fixed typo * Enabling other steps * Cleanup * Enabling all steps * Optional tests * Trying to fix libclang@Windows * Trying aarch with nightly rust * Cleanup & enabling all targets * Fixed MacOS rust version * Rearranging Macs & throwing if loop step fails * Attempting to fix MacOS path issue * Emitting bindings from rust-nightly * Improving error reporting * Testing aarch64 builds * Setting up MacOS environment vars * Fixed MacOS-11.0 dependencies' version * Tuning bindings upload condition * Reverting to rust-nightly * Added macos-aarch64 bindings
1 parent 07dac17 commit bcacb42

File tree

3 files changed

+11517
-41
lines changed

3 files changed

+11517
-41
lines changed

.github/workflows/test.yml

Lines changed: 99 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,23 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
config:
24-
25-
- {os: windows-latest, r: 'release', rust-version: 'stable-x86_64-pc-windows-msvc', msystem: "MINGW64"}
26-
- {os: windows-latest, r: 'release', rust-version: 'nightly-x86_64-pc-windows-msvc', msystem: "MINGW64"}
27-
- {os: windows-latest, r: 'devel', rust-version: 'stable-x86_64-pc-windows-msvc', msystem: "MINGW64"}
28-
- {os: windows-latest, r: 'oldrel', rust-version: 'stable-x86_64-pc-windows-msvc', msystem: "MINGW64"}
29-
30-
31-
- {os: windows-latest, r: 'release', rust-version: 'stable-i686-pc-windows-msvc', msystem: "MINGW32"}
32-
- {os: windows-latest, r: 'release', rust-version: 'nightly-i686-pc-windows-msvc', msystem: "MINGW32"}
33-
- {os: windows-latest, r: 'devel', rust-version: 'stable-i686-pc-windows-msvc', msystem: "MINGW32"}
34-
- {os: windows-latest, r: 'oldrel', rust-version: 'stable-i686-pc-windows-msvc', msystem: "MINGW32"}
35-
24+
- {os: windows-latest, r: 'release', rust-version: 'stable-msvc', targets: ['x86_64-pc-windows-gnu', 'i686-pc-windows-gnu']}
25+
- {os: windows-latest, r: 'release', rust-version: 'nightly-msvc', targets: ['x86_64-pc-windows-gnu', 'i686-pc-windows-gnu']}
26+
- {os: windows-latest, r: 'devel', rust-version: 'stable-msvc', targets: ['x86_64-pc-windows-gnu', 'i686-pc-windows-gnu']}
27+
- {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', targets: ['x86_64-pc-windows-gnu', 'i686-pc-windows-gnu']}
3628

3729
- {os: macOS-latest, r: 'release', rust-version: 'stable'}
3830
- {os: macOS-latest, r: 'release', rust-version: 'nightly'}
39-
- {os: macOS-latest, r: 'devel', rust-version: 'stable'}
40-
- {os: macOS-latest, r: 'oldrel', rust-version: 'stable'}
31+
- {os: macOS-latest, r: 'devel', rust-version: 'stable'}
32+
- {os: macOS-latest, r: 'oldrel', rust-version: 'stable'}
33+
- {os: macOS-11.0, r: 'release', rust-version: 'nightly', targets: ['default', 'aarch64-apple-darwin'],
34+
no-test-targets: 'aarch64-apple-darwin', emit-bindings: 'true'}
4135

42-
43-
- {os: ubuntu-20.04, r: 'release', rust-version: 'stable', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
36+
- {os: ubuntu-20.04, r: 'release', rust-version: 'stable', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
4437
- {os: ubuntu-20.04, r: 'release', rust-version: 'nightly', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
4538
# R-devel requires LD_LIBRARY_PATH
46-
- {os: ubuntu-20.04, r: 'devel', rust-version: 'stable', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
47-
- {os: ubuntu-20.04, r: 'oldrel', rust-version: 'stable', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
39+
- {os: ubuntu-20.04, r: 'devel', rust-version: 'stable', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
40+
- {os: ubuntu-20.04, r: 'oldrel', rust-version: 'stable', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
4841

4942

5043

@@ -55,9 +48,10 @@ jobs:
5548
defaults:
5649
run:
5750
shell: pwsh
51+
5852
steps:
59-
- uses: actions/checkout@v2
6053

54+
- uses: actions/checkout@v2
6155

6256
- name: Set up R
6357
uses: r-lib/actions/setup-r@v1
@@ -71,42 +65,62 @@ jobs:
7165
default: true
7266
components: rustfmt, clippy
7367

68+
- name: Configure targets
69+
run: |
70+
if ($env:RUST_TARGETS -eq '') {
71+
$env:RUST_TARGETS = "default"
72+
}
73+
foreach ($target in ($env:RUST_TARGETS).Split(",")) {
74+
if ($target -ne "default") {
75+
rustup target add $target
76+
}
77+
}
78+
echo "RUST_TARGETS=$env:RUST_TARGETS" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
79+
env:
80+
RUST_TARGETS: ${{ join(matrix.config.targets, ',')}}
81+
7482
# All configurations for Windows go here
7583
# Rust toolchain is used to determine target architecture
7684
- name: Configure Windows
7785
if: runner.os == 'Windows'
78-
# 1. Add appropriate *-gnu target
79-
# 2. Set CARGO_BUILD_FLAGS to the Rust target
80-
# 3. Configure path to libclang
81-
# 4. Add path to mingw32/mingw64 -- otherwise library is linked to rtools
82-
# 5. Add path to R's i386/x64 -- to solve x86 build/test issue
86+
# 1. Configure path to libclang
87+
# 2. Add path to mingw32/mingw64 -- otherwise library is linked to rtools
88+
# 3. Add path to R's i386/x64 -- to solve x86 build/test issue
8389
run: |
84-
if ($env:RUST_TOOLCHAIN -like "*x86_64*") {
85-
rustup target add x86_64-pc-windows-gnu ;
86-
echo "CARGO_BUILD_FLAGS=--target=x86_64-pc-windows-gnu" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ;
87-
echo "LIBCLANG_PATH=C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ;
90+
if ($env:RUST_TARGETS -like "*x86_64*") {
8891
echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
8992
echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
9093
}
91-
if ($env:RUST_TOOLCHAIN -like "*i686*") {
92-
rustup target add i686-pc-windows-gnu ;
93-
echo "CARGO_BUILD_FLAGS=--target=i686-pc-windows-gnu" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ;
94-
echo "LIBCLANG_PATH=C:\msys64\mingw32\bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ;
94+
if ($env:RUST_TARGETS -like "*i686*") {
9595
echo "C:\msys64\mingw32\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
9696
echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\i386" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ;
97-
9897
}
99-
env:
100-
RUST_TOOLCHAIN: ${{ matrix.config.rust-version }}
10198
10299
103100
# MacOS configurations, mainly llvm and path to libclang
101+
# Because of this R installation issue on MacOS-11.0
102+
# https://github.com/r-lib/actions/issues/200
103+
# Symlinks to R/Rscript are not properly set up, so we do it by hand, using this trick
104+
# https://github.com/r-lib/ps/commit/a24f2c4d1bdba63be14e7729b9ab81d0ed9f719e
105+
# Environment variables are required fir Mac-OS-11.0, see
106+
# https://github.com/extendr/libR-sys/issues/35
104107
- name: Configure MacOs
105108
if: runner.os == 'macOS'
106109
run: |
107110
brew install llvm
108111
echo "LIBCLANG_PATH=$(brew --prefix llvm)/lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
109-
112+
$env:LLVM_CONFIG_PATH = "$(brew --prefix llvm)/bin/llvm-config"
113+
echo "LLVM_CONFIG_PATH=$env:LLVM_CONFIG_PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
114+
echo "LIBRSYS_LIBCLANG_INCLUDE_PATH=$(. $env:LLVM_CONFIG_PATH --libdir)/clang/$(. $env:LLVM_CONFIG_PATH --version)/include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
115+
116+
if ((Get-ChildItem -Path /usr/local/bin -Filter R | Measure-Object).Count -eq 0) {
117+
echo "::warning:: Found no R symlink in /usr/local/bin, setting up manually..."
118+
ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/R /usr/local/bin/
119+
}
120+
if ((Get-ChildItem -Path /usr/local/bin -Filter Rscript | Measure-Object).Count -eq 0) {
121+
echo "::warning:: Found no Rscript symlink in /usr/local/bin, setting up manually..."
122+
ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/Rscript /usr/local/bin/
123+
}
110124
111125
# This is required for ubuntu r-devel
112126
# 'Del alias:R' removes R alias which prevents running R
@@ -120,25 +134,69 @@ jobs:
120134
- name: Build & Emit bindings
121135
id: build
122136
run: |
123-
cargo build -vv --features use-bindgen $env:CARGO_BUILD_FLAGS
137+
foreach ($target in ($env:RUST_TARGETS).Split(",")) {
138+
echo "Building for target: $target"
139+
cargo build -vv --features use-bindgen $(if ($target -ne 'default') {"--target=$target"} )
140+
if (!$?) {
141+
echo "::error::$target" ;
142+
throw "Last exit code $LASTEXITCODE"
143+
}
144+
}
124145
env:
125146
LIBRSYS_BINDINGS_OUTPUT_PATH: generated_bindings
126147

127148
# Test the result of previous step
128149
- name: Run tests
129150
id: test
130151
run: |
131-
cargo test -vv --features use-bindgen $env:CARGO_BUILD_FLAGS -- --nocapture --test-threads=1
152+
foreach ($target in ($env:RUST_TARGETS).Split(",")) {
153+
if(($env:NO_TEST_TARGETS).Split(",").Contains($target)) {
154+
echo "::warning:: Skipping bindgen tests for target: $target"
155+
}
156+
else {
157+
echo "Running bindgen tests for target: $target"
158+
cargo test -vv --features use-bindgen $(if ($target -ne 'default') {"--target=$target"} ) -- --nocapture --test-threads=1
159+
if (!$?) {
160+
echo "::error::$target";
161+
throw "Last exit code $LASTEXITCODE"
162+
}
163+
}
164+
}
165+
env:
166+
NO_TEST_TARGETS: ${{ join(matrix.config.no-test-targets, ',') }}
167+
132168

133169

134-
# If success, upload bindings
170+
# If success
171+
# AND (either rust is stable and 'emit-bindings' != 'false'
172+
# OR rust is any and 'emit-bindings' == 'true'),
173+
# upload bindings
135174
- name: Upload generated bindings
136-
if: steps.build.outcome == 'success' && steps.test.outcome == 'success' && startsWith(matrix.config.rust-version, 'stable')
175+
if:
176+
steps.build.outcome == 'success' &&
177+
steps.test.outcome == 'success' &&
178+
((startsWith(matrix.config.rust-version, 'stable') && matrix.config.emit-bindings != 'false') ||
179+
(matrix.config.emit-bindings == 'true'))
137180
uses: actions/upload-artifact@main
138181
with:
139182
name: ${{ matrix.config.os }} (R-${{ matrix.config.r }} rust-${{ matrix.config.rust-version }}) generated bindings
140183
path: generated_bindings
141184

142185
# Run tests again using different bindings
143186
- name: Run tests on precomputed bindings shipped with libR-sys
144-
run: cargo test -vv $env:CARGO_BUILD_FLAGS -- --nocapture --test-threads=1
187+
run: |
188+
foreach ($target in ($env:RUST_TARGETS).Split(",")) {
189+
if(($env:NO_TEST_TARGETS).Split(",").Contains($target)) {
190+
echo "::warning:: Skipping tests for target: $target"
191+
}
192+
else {
193+
echo "Running tests for target: $target"
194+
cargo test -vv $(if ($target -ne 'default') {"--target=$target"} ) -- --nocapture --test-threads=1
195+
if (!$?) {
196+
echo "::error::$target";
197+
throw "Last exit code $LASTEXITCODE"
198+
}
199+
}
200+
}
201+
env:
202+
NO_TEST_TARGETS: ${{ join(matrix.config.no-test-targets, ',') }}

0 commit comments

Comments
 (0)