cargo-cross 1.4.2

A cargo subcommand for cross-compilation, no need docker!
Documentation
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
# Rust Cross Build Action

A powerful GitHub Action for building, testing, and checking Rust projects with cross-compilation support. This action automatically downloads and configures the necessary cross-compilation toolchains, making it easy to execute various Rust commands for multiple platforms. No Need Docker!

## Features

- 🚀 **Cross-compilation support** for Linux (GNU/musl), Windows, macOS, FreeBSD, NetBSD, Android, and iOS
- 🖥️ **Multi-platform hosts** - runs on Linux (x86_64/aarch64/armv7/riscv64/s390x/powerpc64/powerpc64le/mips64/mips64el/loongarch64), macOS (x86_64/aarch64), and Windows (x86_64)
- 📦 **Automatic toolchain setup** - downloads and configures cross-compilers as needed
- 🎯 **Multiple target support** - build for 64+ target platforms in a single run
- 🏗️ **Workspace support** - work with entire workspaces or specific packages
-**Flexible linking** - some musl targets default to static (varies by target), GNU targets default to dynamic, both configurable via `crt-static` parameter
- 🔧 **Flexible configuration** - extensive customization options
- 🛠️ **Multiple commands** - supports build, bench, test, and check operations

## Local Usage

### Installation as Cargo Subcommand

You can install this tool as a cargo subcommand for easy cross-compilation:

```bash
# Install from crate
cargo install cargo-cross

# Install from GitHub
cargo install cargo-cross --git https://github.com/zijiren233/cargo-cross

# Or install from local path
cargo install --path .
```

After installation, you can use `cargo cross` command:

```bash
# Show help
cargo cross --help

# Show all supported targets
cargo cross --show-all-targets

# Build for a specific target
cargo cross build --target x86_64-unknown-linux-musl

# Build for multiple targets
cargo cross build --targets x86_64-unknown-linux-musl,aarch64-unknown-linux-musl

# Build with release profile
cargo cross build --target x86_64-unknown-linux-musl --release

# Build with features
cargo cross build --target x86_64-unknown-linux-musl --features feature1,feature2

# Test for a target
cargo cross test --target x86_64-unknown-linux-musl

# Check the project
cargo cross check --target x86_64-unknown-linux-musl

# Build with specific glibc version for GNU targets
cargo cross build --target x86_64-unknown-linux-gnu --glibc-version 2.31

# Build iOS targets with specific iPhone SDK version
cargo cross build --target aarch64-apple-ios --iphone-sdk-version 18.2

# Build macOS targets with specific macOS SDK version (native macOS only)
cargo cross build --target aarch64-apple-darwin --macos-sdk-version 14.0

# Build FreeBSD targets with specific FreeBSD version
cargo cross build --target x86_64-unknown-freebsd --freebsd-version 14

# Build NetBSD targets
cargo cross build --target x86_64-unknown-netbsd

# Build with specific cross-make version
cargo cross build --target x86_64-unknown-linux-musl --cross-make-version v0.7.7

# Build with custom SDK path (skips version lookup)
cargo cross build --target aarch64-apple-darwin --macos-sdk-path /path/to/MacOSX.sdk
cargo cross build --target aarch64-apple-ios --iphone-sdk-path /path/to/iPhoneOS.sdk
cargo cross build --target aarch64-apple-ios-sim --iphone-simulator-sdk-path /path/to/iPhoneSimulator.sdk
```

## GitHub Actions Usage

### Basic Usage

```yaml
name: Build

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Cross compile
        uses: zijiren233/cargo-cross@v1
        with:
          command: build
          targets: |
            x86_64-unknown-linux-musl
            aarch64-unknown-linux-musl
```

### Build for Multiple Platforms

```yaml
name: Release

on:
  release:
    types: [created]

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      
      - name: Build Release
        uses: zijiren233/cargo-cross@v1
        with:
          command: build
          targets: |
            x86_64-unknown-linux-musl
            aarch64-unknown-linux-musl
            x86_64-pc-windows-gnu
            x86_64-apple-darwin
            aarch64-apple-darwin
          profile: release

      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: binaries-${{ matrix.os }}
          path: target/*/release/*
```

## Host Platforms (Runners)

This action can run on the following GitHub Actions runners or local platforms:

### Supported Host Platforms

| Platform | Architecture | GitHub Runner | Local Support |
|----------|--------------|---------------|---------------|
| **Linux** | x86_64 (amd64) | `ubuntu-latest`, `ubuntu-24.04`, `ubuntu-22.04`, `ubuntu-20.04` | ✅ Yes |
| **Linux** | aarch64 (arm64) | `ubuntu-24.04-arm` | ✅ Yes |
| **Linux** | armv7 | Self-hosted runners | ✅ Yes |
| **Linux** | riscv64 | Self-hosted runners | ✅ Yes |
| **Linux** | s390x | Self-hosted runners | ✅ Yes |
| **Linux** | powerpc64 | Self-hosted runners | ✅ Yes |
| **Linux** | powerpc64le | Self-hosted runners | ✅ Yes |
| **Linux** | mips64 | Self-hosted runners | ✅ Yes |
| **Linux** | mips64el | Self-hosted runners | ✅ Yes |
| **Linux** | loongarch64 | Self-hosted runners | ✅ Yes |
| **macOS** | x86_64 (Intel) | `macos-15-intel` | ✅ Yes |
| **macOS** | aarch64 (Apple Silicon) | `macos-15` | ✅ Yes |
| **Windows** | x86_64 | `windows-latest` | ✅ Yes |

### Recommended Usage

For maximum compatibility and cross-compilation support, use **Linux x86_64** runners:

```yaml
jobs:
  build:
    runs-on: ubuntu-latest  # Best for cross-compilation
    steps:
      - uses: actions/checkout@v3
      - uses: zijiren233/cargo-cross@v1
        with:
          targets: |
            x86_64-unknown-linux-musl
            aarch64-unknown-linux-musl
            x86_64-pc-windows-gnu
            aarch64-apple-darwin
            aarch64-apple-ios
```

For macOS/iOS native/cross builds, use macOS runners:

```yaml
jobs:
  build-macos:
    runs-on: macos-latest  # Apple Silicon
    steps:
      - uses: actions/checkout@v3
      - uses: zijiren233/cargo-cross@v1
        with:
          targets: |
            x86_64-unknown-linux-musl
            aarch64-unknown-linux-musl
            x86_64-pc-windows-gnu
            aarch64-apple-darwin
            aarch64-apple-ios
```

## Supported Targets

### Linux (musl)

Most musl targets produce **statically linked binaries by default**, but this varies by target (check `rustc --print=target-spec-json -Z unstable-options --target <target>` for the actual default). Use `crt-static: true/false` to explicitly control linking behavior.

- `i586-unknown-linux-musl` - Linux i586
- `i686-unknown-linux-musl` - Linux i686
- `x86_64-unknown-linux-musl` - Linux x86_64
- `arm-unknown-linux-musleabi` - ARM Linux
- `arm-unknown-linux-musleabihf` - ARM Linux hard-float
- `armv5te-unknown-linux-musleabi` - ARMv5TE Linux
- `armv7-unknown-linux-musleabi` - ARMv7 Linux
- `armv7-unknown-linux-musleabihf` - ARMv7 Linux hard-float
- `aarch64-unknown-linux-musl` - ARM64 Linux
- `aarch64_be-unknown-linux-musl` - ARM64 big-endian Linux
- `loongarch64-unknown-linux-musl` - LoongArch64 Linux
- `mips-unknown-linux-musl` - MIPS Linux
- `mipsel-unknown-linux-musl` - MIPS little-endian Linux
- `mips64-unknown-linux-muslabi64` - MIPS64 Linux
- `mips64-openwrt-linux-musl` - MIPS64 OpenWrt Linux
- `mips64el-unknown-linux-muslabi64` - MIPS64 little-endian Linux
- `powerpc64-unknown-linux-musl` - PowerPC64 Linux
- `powerpc64le-unknown-linux-musl` - PowerPC64 little-endian Linux
- `riscv32gc-unknown-linux-musl` - RISC-V 32-bit Linux
- `riscv64gc-unknown-linux-musl` - RISC-V 64-bit Linux
- `s390x-unknown-linux-musl` - S390x Linux

### Linux (GNU libc - dynamic by default)

GNU libc targets produce **dynamically linked binaries by default**. Use `crt-static: true` to enable static linking.

**Glibc version**: By default, the latest stable version is used (no version suffix). You can specify a different version (2.17-2.43) using the `glibc-version` parameter for better compatibility with specific Linux distributions.

- `i586-unknown-linux-gnu` - Linux i586
- `i686-unknown-linux-gnu` - Linux i686
- `x86_64-unknown-linux-gnu` - Linux x86_64
- `x86_64-unknown-linux-gnux32` - Linux x86_64 x32 ABI
- `arm-unknown-linux-gnueabi` - ARM Linux
- `arm-unknown-linux-gnueabihf` - ARM Linux hard-float
- `armv5te-unknown-linux-gnueabi` - ARMv5TE Linux
- `armv7-unknown-linux-gnueabi` - ARMv7 Linux
- `armv7-unknown-linux-gnueabihf` - ARMv7 Linux hard-float
- `aarch64-unknown-linux-gnu` - ARM64 Linux
- `aarch64_be-unknown-linux-gnu` - ARM64 big-endian Linux
- `loongarch64-unknown-linux-gnu` - LoongArch64 Linux
- `mips-unknown-linux-gnu` - MIPS Linux
- `mipsel-unknown-linux-gnu` - MIPS little-endian Linux
- `mipsisa32r6-unknown-linux-gnu` - MIPS32 R6 Linux
- `mipsisa32r6el-unknown-linux-gnu` - MIPS32 R6 little-endian Linux
- `mips64-unknown-linux-gnuabi64` - MIPS64 Linux
- `mips64el-unknown-linux-gnuabi64` - MIPS64 little-endian Linux
- `mipsisa64r6-unknown-linux-gnuabi64` - MIPS64 R6 Linux
- `mipsisa64r6el-unknown-linux-gnuabi64` - MIPS64 R6 little-endian Linux
- `powerpc64-unknown-linux-gnu` - PowerPC64 Linux
- `powerpc64le-unknown-linux-gnu` - PowerPC64 little-endian Linux
- `riscv32gc-unknown-linux-gnu` - RISC-V 32-bit Linux
- `riscv64gc-unknown-linux-gnu` - RISC-V 64-bit Linux
- `s390x-unknown-linux-gnu` - S390x Linux

### Windows

- `i686-pc-windows-gnu` - Windows i686 (MinGW)
- `x86_64-pc-windows-gnu` - Windows x86_64 (MinGW)

### FreeBSD

- `x86_64-unknown-freebsd` - FreeBSD x86_64
- `aarch64-unknown-freebsd` - FreeBSD ARM64
- `powerpc64-unknown-freebsd` - FreeBSD PowerPC64
- `powerpc64le-unknown-freebsd` - FreeBSD PowerPC64 little-endian
- `riscv64gc-unknown-freebsd` - FreeBSD RISC-V 64-bit

### NetBSD

- `x86_64-unknown-netbsd` - NetBSD x86_64

### macOS

- `x86_64-apple-darwin` - macOS Intel (x86_64)
- `x86_64h-apple-darwin` - macOS Intel (x86_64h, optimized for Haswell+)
- `aarch64-apple-darwin` - macOS Apple Silicon (ARM64)
- `arm64e-apple-darwin` - macOS Apple Silicon (ARM64e)

### Android

- `i686-linux-android` - Android x86
- `x86_64-linux-android` - Android x86_64
- `armv7-linux-androideabi` - Android ARMv7
- `arm-linux-androideabi` - Android ARM
- `aarch64-linux-android` - Android ARM64
- `riscv64-linux-android` - Android RISC-V 64-bit

### iOS

- `x86_64-apple-ios` - iOS Simulator (x86_64)
- `aarch64-apple-ios` - iOS ARM64
- `aarch64-apple-ios-sim` - iOS ARM64 Simulator

## Inputs

| Input | Description | Default |
|-------|-------------|---------|
| `command` | Command to execute (`build`, `test`, `check`) | `build` |
| `targets` | Newline-separated list of Rust target triples (comma-separated also supported) | Host target |
| `profile` | Build profile (`debug` or `release`) | `release` |
| `features` | Comma-separated list of features to activate | |
| `no-default-features` | Do not activate default features | `false` |
| `all-features` | Activate all available features | `false` |
| `package` | Package to build (workspace member) | |
| `bin` | Binary target to build | |
| `workspace` | Build all workspace members | `false` |
| `manifest-path` | Path to Cargo.toml | |
| `source-dir` | Directory containing the Rust project | `${{ github.workspace }}` |
| `github-proxy-mirror` | GitHub proxy mirror URL | |
| `cross-compiler-dir` | Directory to store cross compilers | |
| `ndk-version` | Android NDK version (e.g., r27d, r29) | `r27d` (LTS) |
| `glibc-version` | Glibc version for GNU targets (e.g., 2.31, 2.42) | (default) |
| `iphone-sdk-version` | iPhone SDK version for iOS targets (non-macOS: bundled SDKs, macOS: installed Xcode SDK) | (default 26.2) |
| `iphone-sdk-path` | Override iPhoneOS SDK path for device targets (skips version lookup, native macOS only) | |
| `iphone-simulator-sdk-path` | Override iPhoneSimulator SDK path for simulator targets (skips version lookup, native macOS only) | |
| `macos-sdk-version` | macOS SDK version for Darwin targets (non-macOS: bundled SDKs, macOS: installed Xcode SDK) | (default 26.2) |
| `macos-sdk-path` | Override macOS SDK path directly (skips version lookup, native macOS only) | |
| `freebsd-version` | FreeBSD version for FreeBSD targets (13, 14, or 15) | `13` |
| `qemu-version` | QEMU version for user-mode emulation (e.g., v10.2.0) | `v10.2.0` |
| `cross-make-version` | Cross-compiler make version (e.g., v0.7.7) | `v0.7.7` |
| `use-default-linker` | Use system default linker | `false` |
| `cc` | Force set the C compiler | |
| `cxx` | Force set the C++ compiler | |
| `rustflags` | Additional rustflags | |
| `crt-static` | Control CRT linking mode: `true` for static (+crt-static), `false` for dynamic (-crt-static), empty for target default (varies by target) | |
| `build-std` | Use -Zbuild-std for building standard library from source (`true` for default, or specify crates like `core,alloc`) | `false` |
| `args` | Additional arguments to pass to cargo command | |
| `toolchain` | Rust toolchain to use (stable, nightly, etc.) | `stable` |
| `cargo-trim-paths` | Set CARGO_TRIM_PATHS environment variable for reproducible builds | |
| `no-embed-metadata` | Add -Zno-embed-metadata flag to cargo | `false` |
| `rustc-bootstrap` | Set RUSTC_BOOTSTRAP environment variable: `1` for all crates, `-1` for stable behavior, or `crate_name` for specific crate | |
| `clean-cache` | Clean build cache before building | `false` |
| `no-strip` | Do not strip binaries | `false` |
| `verbose` | Use verbose output | `false` |

## Outputs

| Output | Description |
|--------|-------------|
| `targets` | Targets that were processed |

## Advanced Examples

### Build with Features

```yaml
- name: Build with features
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    features: feature1,feature2
    no-default-features: true
```

### Build Specific Binary from Workspace

```yaml
- name: Build specific binary
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    package: my-package
    bin: my-binary
```

### Android Build

```yaml
- name: Build for Android
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      aarch64-linux-android
      armv7-linux-androideabi
    # ndk-version: r29  # Optional: specify NDK version (default: r27d LTS)
```

### Custom Compiler

```yaml
- name: Build with custom compiler
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-gnu
    cc: /usr/bin/custom-gcc
    cxx: /usr/bin/custom-g++
```

### Static/Dynamic Linking Configuration

> **Note**: The default linking behavior varies by target. Most musl targets default to static linking, but not all. Use `crt-static` to explicitly control the behavior.

```yaml
# Force static linking for musl target
- name: Build musl with static linking
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    crt-static: true

# Force dynamic linking for musl target
- name: Build musl with dynamic linking
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    crt-static: false

# GNU targets: dynamic by default, set to true for static linking
- name: Build GNU with static linking
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-gnu
    crt-static: true

# Leave empty to use target's default behavior
- name: Build with default linking
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      x86_64-unknown-linux-musl
      x86_64-unknown-linux-gnu
    # crt-static not specified - uses target defaults
```

### Custom Glibc Version

The cross-make toolchains support multiple glibc versions (2.28 to 2.42). Use the `glibc-version` parameter to specify a particular version for GNU targets.

```yaml
# Use glibc 2.31 (Ubuntu 20.04 compatible)
- name: Build with glibc 2.31
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-gnu
    glibc-version: "2.31"

# Use latest glibc 2.42
- name: Build with glibc 2.42
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      x86_64-unknown-linux-gnu
      aarch64-unknown-linux-gnu
    glibc-version: "2.42"

# Leave empty for default glibc version (2.28 for most targets)
- name: Build with default glibc
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-gnu
    # glibc-version not specified - uses default
```

Supported glibc versions: 2.28 (default), 2.31, 2.32, 2.33, 2.34, 2.35, 2.36, 2.37, 2.38, 2.39, 2.40, 2.41, 2.42

### Custom iPhone SDK Version

You can specify a specific iPhone SDK version using the `iphone-sdk-version` parameter:

- **On non-macOS**: Uses bundled SDK versions for cross-compilation. Only supported versions can be used.
- **On macOS**: Uses installed Xcode SDK. If the specified version is not found, falls back to system default with a warning.

```yaml
# Use iPhone SDK 18.2
- name: Build with iPhone SDK 18.2
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: aarch64-apple-ios
    iphone-sdk-version: "18.2"

# Use iPhone SDK 17.5
- name: Build with iPhone SDK 17.5
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      aarch64-apple-ios
      aarch64-apple-ios-sim
    iphone-sdk-version: "17.5"

# Leave empty or use default (26.2)
- name: Build with default iPhone SDK
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: aarch64-apple-ios
    # iphone-sdk-version not specified - uses default 26.2
```

Supported iPhone SDK versions: 17.0, 17.2, 17.4, 17.5, 18.0, 18.1, 18.2, 18.4, 18.5, 26.0, 26.1, 26.2 (default)

### Custom macOS SDK Version

You can specify a specific macOS SDK version using the `macos-sdk-version` parameter:

- **On non-macOS**: Uses bundled SDK versions for cross-compilation via osxcross. Only supported versions can be used.
- **On macOS**: Uses installed Xcode SDK. If the specified version is not found, falls back to system default with a warning.

```yaml
# Use macOS SDK 15.2
- name: Build with macOS SDK 15.2
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: aarch64-apple-darwin
    macos-sdk-version: "15.2"

# Use macOS SDK 14.0
- name: Build with macOS SDK 14.0
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      x86_64-apple-darwin
      aarch64-apple-darwin
    macos-sdk-version: "14.0"

# Leave empty or use default (26.2)
- name: Build with default macOS SDK
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: aarch64-apple-darwin
    # macos-sdk-version not specified - uses default 26.2
```

Supported macOS SDK versions (for non-macOS cross-compilation): 14.0, 14.2, 14.4, 14.5, 15.0, 15.1, 15.2, 15.4, 15.5, 26.0, 26.1, 26.2 (default)

On macOS, any SDK version installed via Xcode can be used.

### Custom FreeBSD Version

You can specify a specific FreeBSD version using the `freebsd-version` parameter. Available versions are 13, 14, and 15:

```yaml
# Use FreeBSD 15 (latest)
- name: Build with FreeBSD 15
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-freebsd
    freebsd-version: "15"

# Use FreeBSD 13 (default)
- name: Build with FreeBSD 13
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      x86_64-unknown-freebsd
      aarch64-unknown-freebsd
    freebsd-version: "13"

# Leave empty for default (FreeBSD 13)
- name: Build with default FreeBSD
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-freebsd
    # freebsd-version not specified - uses default 13
```

Supported FreeBSD versions: 13 (default), 14, 15

### NetBSD Build

NetBSD support is provided through pre-built cross-compilation toolchains. Currently only x86_64 is supported:

```yaml
- name: Build for NetBSD
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-netbsd
```

### Custom Rustflags

```yaml
- name: Build with custom rustflags
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    rustflags: "-C opt-level=3 -C codegen-units=1"
```

### Custom Cross-Make Version

You can specify a different cross-make toolchain version using the `cross-make-version` parameter:

```yaml
# Use a specific cross-make version
- name: Build with cross-make v0.7.7
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    cross-make-version: "v0.7.7"

# Use latest version
- name: Build with latest cross-make
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: |
      x86_64-unknown-linux-musl
      aarch64-unknown-linux-musl
    cross-make-version: "v0.7.7"

# Leave empty for default (v0.7.7)
- name: Build with default cross-make
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    # cross-make-version not specified - uses default v0.7.7
```

### Build Standard Library from Source

```yaml
# Build with default std crates
- name: Build with build-std (default)
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    build-std: true
    toolchain: nightly

# Build with specific crates
- name: Build with build-std (custom crates)
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    build-std: core,alloc
    toolchain: nightly
```

### Matrix Build

```yaml
jobs:
  build:
    strategy:
      matrix:
        target:
          - x86_64-unknown-linux-musl
          - aarch64-unknown-linux-musl
          - x86_64-pc-windows-gnu
          - x86_64-apple-darwin
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Build
        uses: zijiren233/cargo-cross@v1
        with:
          command: build
          targets: ${{ matrix.target }}
          
      - name: Upload
        uses: actions/upload-artifact@v3
        with:
          name: ${{ matrix.target }}
          path: target/${{ matrix.target }}/release/*
```

### Test Across Multiple Targets

```yaml
- name: Test cross-platform
  uses: zijiren233/cargo-cross@v1
  with:
    command: test
    targets: |
      x86_64-unknown-linux-musl
      aarch64-unknown-linux-musl
```

### Check Code Quality

```yaml
- name: Check code
  uses: zijiren233/cargo-cross@v1
  with:
    command: check
    targets: x86_64-unknown-linux-musl
    all-features: true
```

### Use Nightly Toolchain

```yaml
- name: Build with nightly
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    toolchain: nightly
```

### Reproducible Builds with CARGO_TRIM_PATHS

```yaml
- name: Build with reproducible paths
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    cargo-trim-paths: all
```

### Build without Metadata Embedding

```yaml
- name: Build without embedding metadata
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    no-embed-metadata: true
    toolchain: nightly
```

### Build with RUSTC_BOOTSTRAP

The RUSTC_BOOTSTRAP environment variable tells rustc to act as if it is a nightly compiler, allowing use of `#![feature(...)]` attributes and `-Z` flags even on the stable release channel.

```yaml
# Enable nightly features for all crates
- name: Build with nightly features on stable
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    rustc-bootstrap: "1"

# Enable nightly features for specific crate
- name: Build with nightly features for specific crate
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    rustc-bootstrap: "my_crate_name"

# Force stable behavior even on nightly
- name: Build with stable behavior on nightly
  uses: zijiren233/cargo-cross@v1
  with:
    command: build
    targets: x86_64-unknown-linux-musl
    toolchain: nightly
    rustc-bootstrap: "-1"
```

## Toolchain Versions

This action uses the following toolchain versions from [cross-make](https://github.com/zijiren233/cross-make) v0.7.7 by default. You can specify a different version using the `cross-make-version` parameter:

### Core Components

| Component | Version |
|-----------|---------|
| GCC | 15.2.0 |
| Binutils | 2.45.1 |
| GMP | 6.3.0 |
| MPC | 1.3.1 |
| MPFR | 4.2.2 |
| ISL | 0.27 |
| Zstd | 1.5.7 |

### Platform-Specific

| Platform | C Library / SDK | Version |
|----------|-----------------|---------|
| Linux musl | musl | 1.2.5 |
| Linux GNU | glibc | 2.28 (default), 2.31-2.42 available |
| Linux | Linux Headers | 6.12.59 |
| Windows | MinGW-w64 | v13.0.0 |
| FreeBSD 13 | FreeBSD | 13.5 |
| FreeBSD 14 | FreeBSD | 14.3 |
| FreeBSD 15 | FreeBSD | 15.0 |
| NetBSD | NetBSD | 10.1 |
| macOS | macOS SDK | 26.2 (default), 14.0-26.2 available |
| iOS | iPhone SDK | 26.2 (default), 17.0-26.2 available |
| Android | NDK | r27d LTS (default), r29 stable available |

### Supported Glibc Versions

For GNU libc targets, use `glibc-version` parameter to select:

| Version | Compatible With |
|---------|-----------------|
| 2.28 | Debian 10, Ubuntu 18.04, RHEL 8 |
| 2.31 | Ubuntu 20.04, Debian 11 |
| 2.34 | RHEL 9, Ubuntu 22.04 |
| 2.35 | Ubuntu 22.04 |
| 2.36 | Debian 12 |
| 2.38 | Ubuntu 24.04 |
| 2.39-2.42 | Latest distributions |

### Supported iPhone SDK Versions

For iOS targets, use `iphone-sdk-version` parameter to select the SDK version. On non-macOS hosts, only the following bundled versions are available:

| Version | Notes |
|---------|-------|
| 17.0 | iOS 17.0 SDK |
| 17.2 | iOS 17.2 SDK |
| 17.4 | iOS 17.4 SDK |
| 17.5 | iOS 17.5 SDK |
| 18.0 | iOS 18.0 SDK |
| 18.1 | iOS 18.1 SDK |
| 18.2 | iOS 18.2 SDK |
| 18.4 | iOS 18.4 SDK |
| 18.5 | iOS 18.5 SDK |
| 26.0 | iOS 26.0 SDK |
| 26.1 | iOS 26.1 SDK |
| 26.2 | iOS 26.2 SDK (default) |

On macOS, any SDK version installed via Xcode can be used. If the specified version is not found, the system default SDK will be used with a warning.

### Supported macOS SDK Versions

For macOS (Darwin) targets, use `macos-sdk-version` parameter to select the SDK version. On non-macOS hosts, only the following bundled versions are available:

| Version | Notes |
|---------|-------|
| 14.0 | macOS 14.0 (Sonoma) SDK |
| 14.2 | macOS 14.2 SDK |
| 14.4 | macOS 14.4 SDK |
| 14.5 | macOS 14.5 SDK |
| 15.0 | macOS 15.0 (Sequoia) SDK |
| 15.1 | macOS 15.1 SDK |
| 15.2 | macOS 15.2 SDK |
| 15.4 | macOS 15.4 SDK |
| 15.5 | macOS 15.5 SDK |
| 26.0 | macOS 26.0 SDK |
| 26.1 | macOS 26.1 SDK |
| 26.2 | macOS 26.2 SDK (default) |

On macOS, any SDK version installed via Xcode can be used.

### Supported FreeBSD Versions

For FreeBSD targets, use `freebsd-version` parameter to select the FreeBSD version:

| Version | Notes |
|---------|-------|
| 13 | FreeBSD 13.5 (default) |
| 14 | FreeBSD 14.3 |
| 15 | FreeBSD 15.0 |

## How It Works

1. **Command Detection**: The action detects the requested command (build, test, or check)
2. **Target Detection**: The action detects the requested target platforms
3. **Toolchain Setup**: Automatically downloads and configures the necessary cross-compilation toolchains
4. **Environment Configuration**: Sets up the correct environment variables for cross-compilation
5. **Command Execution**: Runs the specified cargo command with the appropriate flags and configuration
6. **Artifact Output**: Built binaries and libraries are placed in `target/{target}/{profile}/` directories following Cargo's standard structure

## Troubleshooting

### Build fails with "linker not found"

Make sure you're running on a supported host OS. Linux hosts support the most targets. For macOS and Windows targets, you may need to run on the respective OS runners.

### Binary is too large

Use `profile: release` and ensure stripping is enabled (default). Note that:

- **musl targets** usually produce statically linked binaries by default (varies by target), which are larger but completely self-contained
- **GNU targets** produce dynamically linked binaries by default, which are smaller but require system libraries
- You can explicitly configure the linking behavior using the `crt-static` parameter

### Android build fails

Ensure you have enough disk space for the Android NDK download. You can also try a different NDK version with the `ndk-version` input.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Credits

This action uses cross-compilation toolchains from:

- [cross-make]https://github.com/zijiren233/cross-make for Linux/Windows/FreeBSD/NetBSD targets
- [osxcross]https://github.com/zijiren233/osxcross for macOS targets
- [cctools-port]https://github.com/zijiren233/cctools-port for ios targets
- Android NDK for Android targets