Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e10d0dcde7 | ||
|
|
52839d91bd | ||
|
|
5b5d0b578b | ||
|
|
02bec77bb9 | ||
|
|
67b2637704 | ||
|
|
cd04d1a926 | ||
|
|
242cf4bba9 | ||
|
|
8a64ff717c | ||
|
|
a8c1049914 | ||
|
|
c76d836532 |
227
.github/workflows/test.yml
vendored
227
.github/workflows/test.yml
vendored
@@ -15,206 +15,206 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
target: x86_64-unknown-freebsd
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "x86-64.+FreeBSD"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: false
|
||||
expect-file-re: "x86-64.+FreeBSD"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: false
|
||||
|
||||
- platform_name: Linux-x86_64
|
||||
runs-on: ubuntu-22.04
|
||||
target: x86_64-unknown-linux-musl
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "ELF.+x86-64"
|
||||
expect_cross: ""
|
||||
expect_stripped: "--expect-stripped"
|
||||
can_execute: true
|
||||
expect-file-re: "ELF.+x86-64"
|
||||
expect-cross: ""
|
||||
expect-stripped: "--expect-stripped"
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-aarch64
|
||||
runs-on: ubuntu-22.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "aarch64"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "aarch64"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-aarch64 (no cache)
|
||||
runs-on: ubuntu-22.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
cache-cross-binary: false
|
||||
expect_file_re: "aarch64"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "aarch64"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-aarch64 with cross v0.2.3
|
||||
runs-on: ubuntu-22.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
cross-version: "v0.2.3"
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "aarch64"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_cross_version: "0.2.3"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "aarch64"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-cross-version: "0.2.3"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-aarch64 with cross v0.2.3 (no cache)
|
||||
runs-on: ubuntu-22.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
cross-version: "v0.2.3"
|
||||
cache-cross-binary: false
|
||||
expect_file_re: "aarch64"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_cross_version: "0.2.3"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "aarch64"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-cross-version: "0.2.3"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-aarch64 with cross 19be834
|
||||
runs-on: ubuntu-22.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
cross-version: "19be834"
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "aarch64"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_cross_version: "19be834"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "aarch64"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-cross-version: "19be834"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-aarch64 with cross 19be834
|
||||
runs-on: ubuntu-22.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
cross-version: "19be834"
|
||||
cache-cross-binary: false
|
||||
expect_file_re: "aarch64"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_cross_version: "19be834"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "aarch64"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-cross-version: "19be834"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-arm
|
||||
runs-on: ubuntu-22.04
|
||||
target: arm-unknown-linux-musleabi
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "32.+ARM"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "32.+ARM"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-i586
|
||||
runs-on: ubuntu-22.04
|
||||
target: i586-unknown-linux-musl
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "ELF.+80386"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "ELF.+80386"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-i686
|
||||
runs-on: ubuntu-22.04
|
||||
target: i686-unknown-linux-musl
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "ELF.+80386"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "ELF.+80386"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-powerpc
|
||||
runs-on: ubuntu-22.04
|
||||
target: powerpc-unknown-linux-gnu
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "32.+PowerPC"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "32.+PowerPC"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-powerpc64
|
||||
runs-on: ubuntu-22.04
|
||||
target: powerpc64-unknown-linux-gnu
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "64.+PowerPC"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "64.+PowerPC"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-powerpc64le
|
||||
runs-on: ubuntu-22.04
|
||||
target: powerpc64le-unknown-linux-gnu
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "64.+PowerPC"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "64.+PowerPC"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-riscv64
|
||||
runs-on: ubuntu-22.04
|
||||
target: riscv64gc-unknown-linux-gnu
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "64.+RISC-V"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "64.+RISC-V"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Linux-s390x
|
||||
runs-on: ubuntu-22.04
|
||||
target: s390x-unknown-linux-gnu
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "64.+S/390"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: true
|
||||
expect-file-re: "64.+S/390"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: true
|
||||
|
||||
- platform_name: NetBSD-x86_64
|
||||
runs-on: ubuntu-22.04
|
||||
target: x86_64-unknown-netbsd
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "x86-64.+NetBSD"
|
||||
expect_cross: "--expect-cross"
|
||||
expect_stripped: ""
|
||||
can_execute: false
|
||||
expect-file-re: "x86-64.+NetBSD"
|
||||
expect-cross: "--expect-cross"
|
||||
expect-stripped: ""
|
||||
can-execute: false
|
||||
|
||||
- platform_name: Windows-aarch64
|
||||
runs-on: windows-latest
|
||||
target: aarch64-pc-windows-msvc
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "Aarch64.+Windows"
|
||||
expect_cross: ""
|
||||
expect_stripped: ""
|
||||
can_execute: false
|
||||
expect-file-re: "Aarch64.+Windows"
|
||||
expect-cross: ""
|
||||
expect-stripped: ""
|
||||
can-execute: false
|
||||
|
||||
- platform_name: Windows-i686
|
||||
runs-on: windows-latest
|
||||
target: i686-pc-windows-msvc
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "80386.+Windows"
|
||||
expect_cross: ""
|
||||
expect_stripped: "--expect-stripped"
|
||||
can_execute: true
|
||||
expect-file-re: "80386.+Windows"
|
||||
expect-cross: ""
|
||||
expect-stripped: "--expect-stripped"
|
||||
can-execute: true
|
||||
|
||||
- platform_name: Windows-x86_64
|
||||
runs-on: windows-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "x86-64.+Windows"
|
||||
expect_stripped: "--expect-stripped"
|
||||
can_execute: true
|
||||
expect-file-re: "x86-64.+Windows"
|
||||
expect-stripped: "--expect-stripped"
|
||||
can-execute: true
|
||||
|
||||
- platform_name: macOS-x86_64
|
||||
runs-on: macOS-latest
|
||||
target: x86_64-apple-darwin
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "Mach-O.+x86_64"
|
||||
expect_cross: ""
|
||||
expect_stripped: "--expect-stripped"
|
||||
can_execute: true
|
||||
expect-file-re: "Mach-O.+x86_64"
|
||||
expect-cross: ""
|
||||
expect-stripped: "--expect-stripped"
|
||||
can-execute: true
|
||||
|
||||
- platform_name: macOS-aarch64
|
||||
runs-on: macOS-latest
|
||||
target: aarch64-apple-darwin
|
||||
cache-cross-binary: true
|
||||
expect_file_re: "Mach-O.+arm64"
|
||||
expect_cross: ""
|
||||
expect_stripped: "--expect-stripped"
|
||||
can_execute: false
|
||||
expect-file-re: "Mach-O.+arm64"
|
||||
expect-cross: ""
|
||||
expect-stripped: "--expect-stripped"
|
||||
can-execute: false
|
||||
|
||||
runs-on: ${{ matrix.platform.runs-on }}
|
||||
steps:
|
||||
@@ -233,7 +233,7 @@ jobs:
|
||||
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
if: ${{ matrix.platform.can_execute }}
|
||||
if: ${{ matrix.platform.can-execute }}
|
||||
- name: Run test command
|
||||
uses: ./
|
||||
with:
|
||||
@@ -242,7 +242,7 @@ jobs:
|
||||
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
if: ${{ matrix.platform.can_execute }}
|
||||
if: ${{ matrix.platform.can-execute }}
|
||||
- name: Run test command with args
|
||||
uses: ./
|
||||
with:
|
||||
@@ -252,7 +252,7 @@ jobs:
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: "-- --ignored"
|
||||
if: ${{ matrix.platform.can_execute }}
|
||||
if: ${{ matrix.platform.can-execute }}
|
||||
- name: Run build command
|
||||
uses: ./
|
||||
with:
|
||||
@@ -262,6 +262,18 @@ jobs:
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
strip: true
|
||||
- name: Check binary and cross for main crate on ${{ matrix.platform.platform_name }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
set -x
|
||||
cargo run --manifest-path ./run-tests/Cargo.toml -- \
|
||||
--checkout-root "$PWD" \
|
||||
--target "${{ matrix.platform.target }}" \
|
||||
--expect-file-re "${{ matrix.platform.expect-file-re }}" \
|
||||
--expect-cross-version "${{ matrix.platform.expect-cross-version }}" \
|
||||
${{ matrix.platform.expect-cross }} \
|
||||
${{ matrix.platform.expect-stripped }}
|
||||
- name: Run build command for subdir
|
||||
uses: ./
|
||||
with:
|
||||
@@ -272,6 +284,19 @@ jobs:
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
strip: true
|
||||
- name: Check binary and cross for subcrate on ${{ matrix.platform.platform_name }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
set -x
|
||||
cargo run --manifest-path ./run-tests/Cargo.toml -- \
|
||||
--checkout-root "$PWD" \
|
||||
--target "${{ matrix.platform.target }}" \
|
||||
--expect-file-re "${{ matrix.platform.expect-file-re }}" \
|
||||
--expect-cross-version "${{ matrix.platform.expect-cross-version }}" \
|
||||
${{ matrix.platform.expect-cross }} \
|
||||
${{ matrix.platform.expect-stripped }} \
|
||||
--is-subcrate
|
||||
- name: Run bench command
|
||||
uses: ./
|
||||
with:
|
||||
@@ -281,19 +306,7 @@ jobs:
|
||||
target: ${{ matrix.platform.target }}
|
||||
working-directory: bench
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
if: ${{ matrix.platform.can_execute }}
|
||||
- name: Check binary and cross on ${{ matrix.platform.platform_name }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
set -x
|
||||
cargo run --manifest-path ./run-tests/Cargo.toml -- \
|
||||
--checkout-root "$PWD" \
|
||||
--target "${{ matrix.platform.target }}" \
|
||||
--expect-file-re "${{ matrix.platform.expect_file_re }}" \
|
||||
--expect-cross-version "${{ matrix.platform.expect_cross_version }}" \
|
||||
${{ matrix.platform.expect_cross }} \
|
||||
${{ matrix.platform.expect_stripped }}
|
||||
if: ${{ matrix.platform.can-execute }}
|
||||
|
||||
test-validate-inputs:
|
||||
name: Test validate-inputs
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
## 1.0.1 - 2025-01-20
|
||||
|
||||
- Fixed a bug where this action would attempt to use `cross` when compiling for an ARM Linux target
|
||||
on an ARM Linux host.
|
||||
|
||||
## 1.0.0 - 2025-01-11
|
||||
|
||||
The addition of caching is a significant behavior change for this action, so the version has been
|
||||
|
||||
59
README.md
59
README.md
@@ -16,7 +16,6 @@ jobs:
|
||||
- os-name: FreeBSD-x86_64
|
||||
runs-on: ubuntu-20.04
|
||||
target: x86_64-unknown-freebsd
|
||||
skip_tests: true
|
||||
|
||||
- os-name: Linux-x86_64
|
||||
runs-on: ubuntu-20.04
|
||||
@@ -83,6 +82,26 @@ This action takes the following parameters:
|
||||
| `use-rust-cache` | boolean | no | Whether or not to use [the `Swatinem/rust-cache@v2` action](https://github.com/Swatinem/rust-cache). This defaults to true. |
|
||||
| `rust-cache-parameters` | string (containing JSON) | no | This must be a string containing valid JSON. The JSON should be an object where the keys are the parameters for [the `Swatinem/rust-cache@v2` action](https://github.com/Swatinem/rust-cache). |
|
||||
|
||||
### Setting Environment Variables
|
||||
|
||||
By default, `cross` passes most rust-related environment variables through when it runs `cargo` in a
|
||||
Docker image. This means you can simply set an `env` key in the workflow step that uses this action.
|
||||
|
||||
```
|
||||
- name: Run build command
|
||||
uses: houseabsolute/actions-rust-cross@v1
|
||||
env:
|
||||
CARGO_LOG: debug
|
||||
RUSTFLAGS: "-g"
|
||||
with:
|
||||
command: build
|
||||
```
|
||||
|
||||
If you want to pass other environment variables through, you will need to configure `cross` to do
|
||||
see. See the
|
||||
[`cross` docs](https://github.com/cross-rs/cross/blob/main/docs/environment_variables.md#environment-variable-passthrough)
|
||||
for more details.
|
||||
|
||||
## How it Works
|
||||
|
||||
Under the hood, this action will compile your binaries with either `cargo` or `cross`, depending on
|
||||
@@ -99,13 +118,6 @@ build `cross`.
|
||||
When compiling on Windows, it will do so in a Powershell environment, which can matter in some
|
||||
corner cases, like compiling the `openssl` crate with the `vendored` feature.
|
||||
|
||||
By default, it will use
|
||||
[the `Swatinem/rust-cache@v2` action](https://github.com/Swatinem/rust-cache) to cache compiled
|
||||
dependencies for this crate. Note that per the documentation for this action, it has fairly limited
|
||||
value for crates without a `Cargo.lock` file. The `key` parameter passed to this action will always
|
||||
include the value of the `target` input. If you specify a `key` parameter in
|
||||
`rust-cache-parameters`, then the `target` input will be appended to the value you specify.
|
||||
|
||||
When running `cargo` on a Linux system, it will also include the output of running
|
||||
`lsb_release --short --description` in the cache key. This is important for crates that link against
|
||||
system libraries. If those library versions change across OS versions (e.g. Ubuntu 20.04 to 22.04),
|
||||
@@ -118,3 +130,34 @@ that we do not re-use the cache across changes when these images change.
|
||||
Finally, it will run `strip` to strip the binaries it builds if the `strip` parameter is true. This
|
||||
is only possible for builds that are not done via `cross`. In addition, Windows builds for `aarch64`
|
||||
cannot be stripped either.
|
||||
|
||||
### Caching
|
||||
|
||||
By default, this action will use
|
||||
[the `Swatinem/rust-cache@v2` action](https://github.com/Swatinem/rust-cache) to cache compiled
|
||||
dependencies for a crate. Note that per the documentation for the `rust-cache` action, it has fairly
|
||||
limited value for crates without a `Cargo.lock` file. The `key` parameter passed to this action will
|
||||
always include the value of the `target` input. If you specify a `key` parameter in
|
||||
`rust-cache-parameters`, then the `target` input will be appended to the value you specify.
|
||||
|
||||
#### Weird Caching Issue with Multiple Crates
|
||||
|
||||
In my testing, it seemed like in some cases restoring the cache would delete existing files in a
|
||||
`target` directory. This manifested with this sequence of actions:
|
||||
|
||||
1. Run `actions-rust-cross` to compile a crate in a top-level directory.
|
||||
2. Run `actions-rust-cross` to compile a crate in a subdirectory.
|
||||
|
||||
After step 2, the compiled binaries from step 1 were no longer present, _sometimes_. I'm not sure
|
||||
exactly what's going on here, but my recommendation is to structure your workflows so that this
|
||||
cannot affect you.
|
||||
|
||||
For example, if you have multiple crates, each of which builds a binary you want to release, then
|
||||
you can avoid this issue by structuring your workflow as follows:
|
||||
|
||||
1. Run `actions-rust-cross` to compile crate A.
|
||||
2. Run the release steps for crate A.
|
||||
3. Run `actions-rust-cross` to compile crate B.
|
||||
4. Run the release steps for crate B.
|
||||
|
||||
When structured this way, it does not matter if the output of crate A is deleted in step 3.
|
||||
|
||||
@@ -76,7 +76,7 @@ runs:
|
||||
- name: Determine whether we need to cross-compile
|
||||
id: determine-cross-compile
|
||||
shell: bash
|
||||
run: set-cross-compile.sh ${{ inputs.target }}
|
||||
run: set-cross-compile.py ${{ inputs.target }}
|
||||
- name: Install toolchain
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
node = "22.11.0"
|
||||
"npm:prettier" = "3.4.1"
|
||||
ruff = "0.8.3"
|
||||
shellcheck = "v0.10.0"
|
||||
shellcheck = "0.10.0"
|
||||
shfmt = "v3.10.0"
|
||||
taplo = "0.9.3"
|
||||
typos = "1.28.1"
|
||||
|
||||
@@ -24,6 +24,8 @@ struct Args {
|
||||
expect_cross_version: Option<String>,
|
||||
#[arg(long)]
|
||||
expect_stripped: bool,
|
||||
#[arg(long)]
|
||||
is_subcrate: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -39,24 +41,27 @@ fn main() {
|
||||
);
|
||||
|
||||
let checkout_root_path = PathBuf::from(args.checkout_root);
|
||||
let bin_paths = vec![
|
||||
checkout_root_path
|
||||
.join("target")
|
||||
.join(&args.target)
|
||||
.join("debug")
|
||||
.join("bin1"),
|
||||
checkout_root_path
|
||||
.join("target")
|
||||
.join(&args.target)
|
||||
.join("debug")
|
||||
.join("bin2"),
|
||||
checkout_root_path
|
||||
let bin_paths = if args.is_subcrate {
|
||||
vec![checkout_root_path
|
||||
.join("subcrate")
|
||||
.join("target")
|
||||
.join(&args.target)
|
||||
.join("debug")
|
||||
.join("subcrate"),
|
||||
];
|
||||
.join("subcrate")]
|
||||
} else {
|
||||
vec![
|
||||
checkout_root_path
|
||||
.join("target")
|
||||
.join(&args.target)
|
||||
.join("debug")
|
||||
.join("bin1"),
|
||||
checkout_root_path
|
||||
.join("target")
|
||||
.join(&args.target)
|
||||
.join("debug")
|
||||
.join("bin2"),
|
||||
]
|
||||
};
|
||||
|
||||
for mut bin_path in bin_paths {
|
||||
if cfg!(windows) {
|
||||
|
||||
97
set-cross-compile.py
Executable file
97
set-cross-compile.py
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Written mostly by Claude.ai based on my original bash script.
|
||||
|
||||
import sys
|
||||
import platform
|
||||
import re
|
||||
import os
|
||||
from subprocess import run, PIPE, CalledProcessError
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""
|
||||
Main function to determine cross-compilation requirements.
|
||||
|
||||
Returns:
|
||||
Exit code (0 for success)
|
||||
"""
|
||||
if len(sys.argv) < 2:
|
||||
print("Error: Target architecture argument is required", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
target = sys.argv[1]
|
||||
needs_cross = check_needs_cross(target)
|
||||
write_github_output(needs_cross)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def check_needs_cross(target: str) -> bool:
|
||||
"""
|
||||
Determine if cross-compilation is needed based on system and target.
|
||||
|
||||
Args:
|
||||
target: Target architecture string
|
||||
|
||||
Returns:
|
||||
Boolean indicating if cross-compilation is needed
|
||||
"""
|
||||
system_info = get_uname_info().lower()
|
||||
|
||||
# Check if we're on macOS or Windows
|
||||
if any(os in system_info for os in ["darwin", "msys", "windows"]):
|
||||
return False
|
||||
|
||||
target = target.lower()
|
||||
|
||||
# Check for x86_64 Linux targets on x86_64 Linux host
|
||||
if (
|
||||
re.search(r"x86_64.+linux-(?:gnu|musl)", target)
|
||||
and "x86_64" in system_info
|
||||
and "linux" in system_info
|
||||
):
|
||||
return False
|
||||
|
||||
# Check if both host and target are ARM Linux. I'm assuming here that for things like
|
||||
# "arm-linux-androideabi" or "armv7-unknown-linux-ohos" we'd still need cross.
|
||||
if (
|
||||
re.search(r"(?:aarch64|arm).+linux-(?:gnu|musl)", target)
|
||||
and ("arm" in system_info or "aarch64" in system_info)
|
||||
and "linux" in system_info
|
||||
):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def get_uname_info() -> str:
|
||||
"""
|
||||
Get system information using uname command.
|
||||
|
||||
Returns:
|
||||
String containing system information
|
||||
"""
|
||||
try:
|
||||
result = run(["uname", "-a"], check=True, text=True, stdout=PIPE)
|
||||
return result.stdout
|
||||
except (CalledProcessError, FileNotFoundError):
|
||||
# Fallback to platform.platform() if uname is not available
|
||||
return platform.platform()
|
||||
|
||||
|
||||
def write_github_output(needs_cross: bool) -> None:
|
||||
"""
|
||||
Write the needs-cross output to GITHUB_OUTPUT environment variable file.
|
||||
|
||||
Args:
|
||||
needs_cross: Boolean indicating if cross-compilation is needed
|
||||
"""
|
||||
github_output = os.getenv("GITHUB_OUTPUT")
|
||||
if github_output:
|
||||
with open(github_output, "a") as f:
|
||||
f.write(f"needs-cross={str(needs_cross).lower()}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
set -o pipefail
|
||||
|
||||
TARGET="$1"
|
||||
|
||||
# On macOS and Windows, we can cross-compile to all possible targets without
|
||||
# using cross.
|
||||
if uname -a | grep --quiet --extended-regexp -i "darwin|msys|windows"; then
|
||||
echo "needs-cross=false" >>"$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# On Linux, we should be able to cross-compile to i586 and i686, but in
|
||||
# practice this fails with some crates, notably openssl with the "vendored"
|
||||
# feature. This feature makes it compile openssl itself, which fails without
|
||||
# cross.
|
||||
if echo "$TARGET" | grep --quiet --extended-regexp -i 'x86_64.+linux-(gnu|musl)'; then
|
||||
echo "needs-cross=false" >>"$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "needs-cross=true" >>"$GITHUB_OUTPUT"
|
||||
@@ -19,7 +19,7 @@ path = "src/bin2.rs"
|
||||
[package.metadata.cross.target.x86_64-unknown-netbsd]
|
||||
pre-build = [
|
||||
"mkdir -p /tmp/netbsd",
|
||||
"curl https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O",
|
||||
"curl https://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O",
|
||||
"tar -C /tmp/netbsd -xJf base.tar.xz",
|
||||
"cp /tmp/netbsd/usr/lib/libexecinfo.so /usr/local/x86_64-unknown-netbsd/lib",
|
||||
"rm base.tar.xz",
|
||||
|
||||
@@ -7,7 +7,7 @@ edition = "2021"
|
||||
[package.metadata.cross.target.x86_64-unknown-netbsd]
|
||||
pre-build = [
|
||||
"mkdir -p /tmp/netbsd",
|
||||
"curl https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O",
|
||||
"curl https://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O",
|
||||
"tar -C /tmp/netbsd -xJf base.tar.xz",
|
||||
"cp /tmp/netbsd/usr/lib/libexecinfo.so /usr/local/x86_64-unknown-netbsd/lib",
|
||||
"rm base.tar.xz",
|
||||
|
||||
Reference in New Issue
Block a user