|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - master |
| 12 | + |
| 13 | +# cargo error handling is wrapped by ci-cargo, for simplicity and better logging. |
| 14 | +# To use ci-cargo in a step, source ci-cargo.ps1 (using `. ./ci-cargo.ps`, note the extra dot in front). |
| 15 | +# ci-cargo does not handle correctly -- separator, so wrap it in quotes ('--') |
| 16 | +# A special named parameter called `ActionName` can be used to set the name of current ci-cargo action, |
| 17 | +# used as `ci-cargo .... -ActionName "Called for documentation purposes"`. |
| 18 | +jobs: |
| 19 | + # All tests |
| 20 | + tests: |
| 21 | + runs-on: ${{ matrix.config.os }} |
| 22 | + |
| 23 | + name: ${{ matrix.config.os }} (R-${{ matrix.config.r }} rust-${{ matrix.config.rust-version }}) |
| 24 | + |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + config: |
| 29 | + # On Windows, |
| 30 | + # |
| 31 | + # * for R >= 4.2, both the MSVC toolchain and the GNU toolchain should |
| 32 | + # work. Since our main support is on MSVC, we mainly test MSVC here. |
| 33 | + # Also, at least one GNU case should be included so that we can |
| 34 | + # detect when something gets broken. |
| 35 | + # * for R < 4.2, the MSVC toolchain must be used to support |
| 36 | + # cross-compilation for the 32-bit. |
| 37 | + - {os: windows-latest, r: 'release', rust-version: 'stable-msvc', rtools-version: '42'} |
| 38 | + - {os: windows-latest, r: 'devel', rust-version: 'stable-msvc'} |
| 39 | + - {os: windows-latest, r: 'release', rust-version: 'stable-gnu', rtools-version: '42'} |
| 40 | + - {os: windows-latest, r: '4.1', rust-version: 'stable-msvc'} # TODO: Remove this runner when we drop the support for R < 4.2 |
| 41 | + |
| 42 | + - {os: macOS-latest, r: 'release', rust-version: 'stable'} |
| 43 | + # - {os: macOS-latest, r: 'release', rust-version: 'nightly'} |
| 44 | + # - {os: macOS-latest, r: 'devel', rust-version: 'stable'} |
| 45 | + # - {os: macOS-latest, r: 'oldrel', rust-version: 'stable'} |
| 46 | + |
| 47 | + - {os: ubuntu-latest, r: 'release', rust-version: 'stable', check_fmt: true} |
| 48 | + - {os: ubuntu-latest, r: 'release', rust-version: 'nightly'} |
| 49 | + # R-devel requires LD_LIBRARY_PATH |
| 50 | + - {os: ubuntu-latest, r: 'devel', rust-version: 'stable'} |
| 51 | + - {os: ubuntu-latest, r: 'oldrel', rust-version: 'stable'} |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + env: |
| 56 | + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true |
| 57 | + |
| 58 | + # This environment variable enables support for pseudo multi-target cargo builds. |
| 59 | + # Current stable Rust does not support multi-targeting, |
| 60 | + # see https://github.com/rust-lang/cargo/issues/8176 |
| 61 | + # The variable is treated as a comma-separated list of valid Rust targets. |
| 62 | + # 'default' value emits no '--target' flag. |
| 63 | + # E.g.: BUILD_TARGETS=i686-pc-windows-gnu,x86_64-pc-windows-gnu builds two times, |
| 64 | + # each time providing '--target=*-pc-windows-gnu' flag to cargo. |
| 65 | + BUILD_TARGETS: default |
| 66 | + |
| 67 | + # PowerShell core is available on all platforms and can be used to unify scripts |
| 68 | + defaults: |
| 69 | + run: |
| 70 | + shell: pwsh |
| 71 | + |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v3 |
| 74 | + |
| 75 | + - name: Set up Rust |
| 76 | + uses: dtolnay/rust-toolchain@master |
| 77 | + with: |
| 78 | + toolchain: ${{ matrix.config.rust-version }} |
| 79 | + components: rustfmt, clippy |
| 80 | + |
| 81 | + - name: Set up R |
| 82 | + uses: r-lib/actions/setup-r@v2 |
| 83 | + with: |
| 84 | + r-version: ${{ matrix.config.r }} |
| 85 | + rtools-version: ${{ matrix.config.rtools-version }} |
| 86 | + # TODO: enable RSPM when all the packages are available |
| 87 | + use-public-rspm: false |
| 88 | + |
| 89 | + - name: Set up Pandoc |
| 90 | + uses: r-lib/actions/setup-pandoc@v2 |
| 91 | + |
| 92 | + - name: Configure Windows (R >= 4.2) |
| 93 | + if: startsWith(runner.os, 'Windows') && matrix.config.r != '4.1' |
| 94 | + run: | |
| 95 | + if ("${{ matrix.config.rtools-version }}" -eq "42") { |
| 96 | + $rtools_home = "C:\rtools42" # for R 4.2 |
| 97 | + } else { |
| 98 | + $rtools_home = "C:\rtools43" # for R >= 4.3 |
| 99 | + } |
| 100 | +
|
| 101 | + # c.f. https://github.com/wch/r-source/blob/f1501504df8df1668a57d3a1b6f80167f24441d3/src/library/profile/Rprofile.windows#L70-L71 |
| 102 | + echo "${rtools_home}\x86_64-w64-mingw32.static.posix\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 103 | + echo "${rtools_home}\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 104 | + echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 105 | +
|
| 106 | + # Add target |
| 107 | + rustup target add x86_64-pc-windows-gnu |
| 108 | + echo "BUILD_TARGETS=x86_64-pc-windows-gnu" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ; |
| 109 | +
|
| 110 | + # The following lines add two tweaks: |
| 111 | + # |
| 112 | + # 1. Change the linker name to "x86_64-w64-mingw32.static.posix-gcc.exe". |
| 113 | + # 2. Add empty libgcc_s.a and libgcc_eh.a, and add them to the compiler's |
| 114 | + # library search paths via `LIBRARY_PATH` envvar. |
| 115 | + # |
| 116 | + # The first tweak is needed because Rtools42 doesn't contain |
| 117 | + # "x86_64-w64-mingw32-gcc," which `rustc` uses as the default linker |
| 118 | + # for the `x86_64-pc-windows-gnu` target. |
| 119 | + # |
| 120 | + # If we use the Rtools' toolchain, the second tweak is also required. |
| 121 | + # `rustc` adds `-lgcc_eh` and `-lgcc_s` flags to the compiler, but |
| 122 | + # Rtools' GCC doesn't have `libgcc_eh` or `libgcc_s` due to the |
| 123 | + # compilation settings. So, in order to please the compiler, we need |
| 124 | + # to add empty `libgcc_eh` or `libgcc_s` to the library search paths. |
| 125 | + # |
| 126 | + # For more details, please refer to https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316 |
| 127 | +
|
| 128 | + New-Item -Path libgcc_mock -Type Directory |
| 129 | + New-Item -Path libgcc_mock\libgcc_eh.a -Type File |
| 130 | + New-Item -Path libgcc_mock\libgcc_s.a -Type File |
| 131 | +
|
| 132 | + New-Item -Path .cargo -ItemType Directory -Force |
| 133 | + $pwd_slash = echo "${PWD}" | % {$_ -replace '\\','/'} |
| 134 | + @" |
| 135 | + [target.x86_64-pc-windows-gnu] |
| 136 | + linker = "x86_64-w64-mingw32.static.posix-gcc.exe" |
| 137 | +
|
| 138 | + [env] |
| 139 | + LIBRARY_PATH = "${pwd_slash}/libgcc_mock" |
| 140 | + "@ | Out-File -FilePath .cargo/config.toml -Encoding utf8 -Append ; |
| 141 | + env: |
| 142 | + RUST_TOOLCHAIN: ${{ matrix.config.rust-version }} |
| 143 | + |
| 144 | + # TODO: Remove this runner when we drop the support for R < 4.2 |
| 145 | + - name: Configure Windows (R < 4.2) |
| 146 | + if: startsWith(runner.os, 'Windows') && matrix.config.r == '4.1' |
| 147 | + # 1. Add rust target |
| 148 | + # 2. Add target name to the $targets variable |
| 149 | + # 3. Add mingw32/mingw64 bin folders to PATH |
| 150 | + # 4. Add R x64/i386 folders to PATH |
| 151 | + run: | |
| 152 | + $targets=@() |
| 153 | + if ($env:RUST_TOOLCHAIN -notlike "*x86_64*") { |
| 154 | + rustup target add i686-pc-windows-gnu ; |
| 155 | + $targets+="i686-pc-windows-gnu" |
| 156 | + echo "${env:RTOOLS40_HOME}\mingw32\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 157 | + echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\i386" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 158 | + } |
| 159 | + if ($env:RUST_TOOLCHAIN -notlike "*i686*") { |
| 160 | + rustup target add x86_64-pc-windows-gnu ; |
| 161 | + $targets+="x86_64-pc-windows-gnu" |
| 162 | + echo "${env:RTOOLS40_HOME}\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 163 | + echo "$(Rscript.exe -e 'cat(normalizePath(R.home()))')\bin\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append ; |
| 164 | + } |
| 165 | + echo "BUILD_TARGETS=$($targets -join ',')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append ; |
| 166 | + env: |
| 167 | + RUST_TOOLCHAIN: ${{ matrix.config.rust-version }} |
| 168 | + |
| 169 | + # This is required for ubuntu r-devel |
| 170 | + # 'Del alias:R' removes 'R' alias which prevents running R |
| 171 | + - name: Configure Linux |
| 172 | + if: startsWith(runner.os, 'linux') |
| 173 | + run: | |
| 174 | + Del alias:R |
| 175 | + echo "LD_LIBRARY_PATH=$(R -s -e 'cat(normalizePath(R.home()))')/lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 176 | +
|
| 177 | + # Check code formatting. As this doesn't depend on the platform, do this only on one platform. |
| 178 | + - name: Check code formatting |
| 179 | + if: matrix.config.check_fmt |
| 180 | + run: cargo fmt -- --check |
| 181 | + |
| 182 | + # For each target in the BUILD_TARGETS comma-separated list, run cargo build with appropriate target |
| 183 | + # Required by Windows builds, does not affect other platforms |
| 184 | + - name: Build |
| 185 | + run: | |
| 186 | + . ./ci-cargo.ps1 |
| 187 | + foreach($target in ($env:BUILD_TARGETS).Split(',')) { |
| 188 | + ci-cargo build $(if($target -ne 'default') {"--target=$target"} ) -ActionName "Building for $target target" |
| 189 | + } |
| 190 | + # For each target in the BUILD_TARGETS comma-separated list, run cargo test with appropriate target |
| 191 | + # Required by Windows builds, does not affect other platforms |
| 192 | + # ! ci-cargo requires '--' to be wrapped in quotes (passed as an explicit string) |
| 193 | + - name: Run tests |
| 194 | + run: | |
| 195 | + . ./ci-cargo.ps1 |
| 196 | + foreach($target in ($env:BUILD_TARGETS).Split(',')) { |
| 197 | + # Note: no feature is specified, which means such features like graphics, serde, ndarray, and num-complex are not tested here. |
| 198 | + ci-cargo test $(if($target -ne 'default') {"--target=$target"} ) '--' --nocapture -ActionName "Testing for $target target" |
| 199 | + } |
| 200 | +
|
0 commit comments