Skip to content

Commit 6919390

Browse files
committed
feat: support cross-platform host builds
1 parent e2eef48 commit 6919390

7 files changed

Lines changed: 71 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@ permissions:
99

1010
jobs:
1111
build:
12-
name: Build / Lint (macOS aarch64)
13-
runs-on: macos-14
12+
name: Build / Lint (${{ matrix.label }})
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- os: macos-14
19+
label: macOS arm64
20+
- os: ubuntu-latest
21+
label: Linux x86_64
22+
- os: windows-latest
23+
label: Windows x86_64
1424

1525
steps:
1626
- name: Checkout
@@ -21,20 +31,17 @@ jobs:
2131
with:
2232
components: rustfmt, clippy
2333

24-
- name: Add target
25-
run: rustup target add aarch64-apple-darwin
26-
2734
- name: Cache cargo artifacts
2835
uses: Swatinem/rust-cache@v2
2936

3037
- name: Check formatting
3138
run: cargo fmt --all -- --check
3239

3340
- name: Check compilation
34-
run: cargo check --all-targets --target aarch64-apple-darwin
41+
run: cargo check --all-targets
3542

3643
- name: Run clippy
37-
run: cargo clippy --all-targets --target aarch64-apple-darwin -- -D warnings
44+
run: cargo clippy --all-targets -- -D warnings
3845

3946
- name: Run tests
40-
run: cargo test --target aarch64-apple-darwin
47+
run: cargo test

.github/workflows/release.yml

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,27 @@ permissions:
1010

1111
jobs:
1212
build:
13-
name: Build release asset (macOS aarch64)
14-
runs-on: macos-14
13+
name: Build release asset (${{ matrix.label }})
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- os: macos-14
20+
label: macOS arm64
21+
artifact_name: insert-dylib-macos-aarch64
22+
binary_name: insert-dylib
23+
archive_glob: dist/*.tar.gz
24+
- os: ubuntu-latest
25+
label: Linux x86_64
26+
artifact_name: insert-dylib-linux-x86_64
27+
binary_name: insert-dylib
28+
archive_glob: dist/*.tar.gz
29+
- os: windows-latest
30+
label: Windows x86_64
31+
artifact_name: insert-dylib-windows-x86_64
32+
binary_name: insert-dylib.exe
33+
archive_glob: dist/*.zip
1534

1635
steps:
1736
- name: Checkout
@@ -20,30 +39,39 @@ jobs:
2039
- name: Install Rust toolchain
2140
uses: dtolnay/rust-toolchain@stable
2241

23-
- name: Add target
24-
run: rustup target add aarch64-apple-darwin
25-
2642
- name: Cache cargo artifacts
2743
uses: Swatinem/rust-cache@v2
2844

2945
- name: Build release binary
30-
run: cargo build --release --target aarch64-apple-darwin
46+
run: cargo build --release
3147

3248
- name: Package archive
49+
if: runner.os != 'Windows'
3350
shell: bash
3451
run: |
3552
set -euo pipefail
36-
package_dir="insert-dylib-macos-aarch64"
53+
package_dir="${{ matrix.artifact_name }}"
3754
mkdir -p dist "$package_dir"
38-
cp "target/aarch64-apple-darwin/release/insert-dylib" "$package_dir/"
55+
cp "target/release/${{ matrix.binary_name }}" "$package_dir/"
3956
cp README.md README.cn.md LICENSE "$package_dir/"
4057
tar -czf "dist/${package_dir}.tar.gz" "$package_dir"
4158
59+
- name: Package archive
60+
if: runner.os == 'Windows'
61+
shell: pwsh
62+
run: |
63+
$packageDir = "${{ matrix.artifact_name }}"
64+
New-Item -ItemType Directory -Force -Path "dist" | Out-Null
65+
New-Item -ItemType Directory -Force -Path $packageDir | Out-Null
66+
Copy-Item "target/release/${{ matrix.binary_name }}" $packageDir
67+
Copy-Item README.md, README.cn.md, LICENSE $packageDir
68+
Compress-Archive -Path "$packageDir/*" -DestinationPath "dist/$packageDir.zip" -Force
69+
4270
- name: Upload workflow artifact
4371
uses: actions/upload-artifact@v4
4472
with:
45-
name: insert-dylib-macos-aarch64
46-
path: dist/*.tar.gz
73+
name: ${{ matrix.artifact_name }}
74+
path: ${{ matrix.archive_glob }}
4775

4876
publish:
4977
name: Publish GitHub Release
@@ -60,19 +88,20 @@ jobs:
6088
run: |
6189
set -euo pipefail
6290
mkdir -p release-files
63-
find dist -type f -name '*.tar.gz' -exec cp {} release-files/ \;
91+
find dist -type f \( -name '*.tar.gz' -o -name '*.zip' \) -exec cp {} release-files/ \;
6492
6593
- name: Generate SHA256 checksums
6694
run: |
6795
set -euo pipefail
6896
cd release-files
69-
sha256sum *.tar.gz > SHA256SUMS.txt
97+
sha256sum *.tar.gz *.zip > SHA256SUMS.txt
7098
7199
- name: Create GitHub Release
72100
uses: softprops/action-gh-release@v2
73101
with:
74102
files: |
75103
release-files/*.tar.gz
104+
release-files/*.zip
76105
release-files/SHA256SUMS.txt
77106
generate_release_notes: true
78107
env:

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@ license = "MIT"
1111
keywords = ["macho", "dylib", "patcher", "binary", "macos"]
1212
categories = ["command-line-utilities"]
1313

14-
[package.metadata.docs.rs]
15-
default-target = "aarch64-apple-darwin"
16-
targets = ["aarch64-apple-darwin"]
17-
1814
[dependencies]

README.cn.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
77
## 平台支持
88

9-
- 仅支持:**macOS aarch64(Apple Silicon)**
10-
- 其它目标会在编译期直接报错(设计如此)。
9+
- 宿主平台支持:**macOS、Linux、Windows**
10+
- 处理对象支持:**Mach-O thin / fat binary**
11+
- 实现只依赖可移植的 `std` 文件 I/O,没有宿主系统专属 API。
1112

1213
## 功能
1314

@@ -20,12 +21,13 @@
2021
## 构建
2122

2223
```bash
23-
cargo build --release --target aarch64-apple-darwin
24+
cargo build --release
2425
```
2526

2627
生成的可执行文件位于:
2728

28-
- `target/aarch64-apple-darwin/release/insert-dylib`
29+
- macOS / Linux:`target/release/insert-dylib`
30+
- Windows:`target/release/insert-dylib.exe`
2931

3032
## 用法
3133

@@ -78,7 +80,7 @@ insert-dylib --ios --dylib-path libarcaea_function.dylib @executable_path/Framew
7880

7981
## 代码签名说明
8082

81-
若移除了 `LC_CODE_SIGNATURE`,原签名会失效。需要的话请对补丁后的文件重新签名:
83+
若移除了 `LC_CODE_SIGNATURE`,原签名会失效。需要的话请对补丁后的文件重新签名。下面的 `codesign` 命令本身仅在 macOS 上可用
8284

8385
```bash
8486
codesign --force --sign - MyApp.patched

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ A Rust rewrite of `insert_dylib`: injects a new `LC_LOAD_DYLIB` (or `LC_LOAD_WEA
66
77
## Platform Support
88

9-
- Supported platform: **macOS aarch64 (Apple Silicon)**
10-
- Unsupported targets fail at compile time by design.
9+
- Host platforms: **macOS, Linux, and Windows**
10+
- Supported inputs: **Mach-O thin and fat binaries**
11+
- The implementation uses portable `std` file I/O only; no host-OS-specific APIs are required.
1112

1213
## Features
1314

@@ -20,12 +21,13 @@ A Rust rewrite of `insert_dylib`: injects a new `LC_LOAD_DYLIB` (or `LC_LOAD_WEA
2021
## Build
2122

2223
```bash
23-
cargo build --release --target aarch64-apple-darwin
24+
cargo build --release
2425
```
2526

2627
The binary will be at:
2728

28-
- `target/aarch64-apple-darwin/release/insert-dylib`
29+
- macOS / Linux: `target/release/insert-dylib`
30+
- Windows: `target/release/insert-dylib.exe`
2931

3032
## Usage
3133

@@ -78,7 +80,7 @@ insert-dylib --ios --dylib-path libarcaea_function.dylib @executable_path/Framew
7880

7981
## Code Signing Note
8082

81-
If `LC_CODE_SIGNATURE` is removed, the binary's signature is invalidated. Re-sign the patched binary if needed:
83+
If `LC_CODE_SIGNATURE` is removed, the binary's signature is invalidated. Re-sign the patched binary if needed. The `codesign` command itself is only available on macOS:
8284

8385
```bash
8486
codesign --force --sign - MyApp.patched

examples/classic-tight-headerpad-case/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This folder is a reproducible failure/success comparison for Mach-O dylib inject
1313

1414
## Prerequisites
1515

16-
- macOS aarch64 (Apple Silicon)
16+
- This example itself requires macOS aarch64 (Apple Silicon)
1717
- `codesign` available in your environment
1818

1919
## Build and Run (Step-by-Step)

src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ use std::path::Path;
77
use std::process;
88
use std::ptr;
99

10-
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
11-
compile_error!("insert-dylib currently supports only macOS aarch64.");
12-
1310
const MH_MAGIC: u32 = 0xfeedface;
1411
const MH_CIGAM: u32 = 0xcefaedfe;
1512
const MH_MAGIC_64: u32 = 0xfeedfacf;

0 commit comments

Comments
 (0)