Skip to content

Commit 941ae3f

Browse files
committed
update arch in macos ci
1 parent daca759 commit 941ae3f

1 file changed

Lines changed: 140 additions & 88 deletions

File tree

.github/workflows/ci.yml

Lines changed: 140 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,126 +6,178 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
env:
10+
CARGO_TERM_COLOR: always
11+
912
jobs:
1013
build:
14+
name: Build (${{ matrix.os }})
1115
strategy:
1216
matrix:
1317
os: [windows-latest, ubuntu-latest, macos-latest]
14-
fail-fast: false # Don't cancel other jobs if one fails
18+
fail-fast: false
1519
runs-on: ${{ matrix.os }}
16-
continue-on-error: ${{ matrix.os != 'windows-latest' }} # Allow Linux/macOS to fail
17-
20+
continue-on-error: ${{ matrix.os != 'windows-latest' }}
21+
1822
steps:
19-
- uses: actions/checkout@v4
20-
21-
- name: Build project
22-
run: cargo build --verbose
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Rust
27+
uses: actions-rust-lang/setup-rust-toolchain@v1
28+
with:
29+
cache: true
30+
31+
- name: Build project
32+
run: cargo build --verbose
2333

2434
test:
35+
name: Test (${{ matrix.os }})
2536
strategy:
2637
matrix:
2738
os: [windows-latest, ubuntu-latest, macos-latest]
28-
fail-fast: false # Don't cancel other jobs if one fails
39+
fail-fast: false
2940
runs-on: ${{ matrix.os }}
30-
continue-on-error: ${{ matrix.os != 'windows-latest' }} # Allow Linux/macOS to fail
41+
continue-on-error: ${{ matrix.os != 'windows-latest' }}
3142
needs: build
32-
43+
3344
steps:
34-
- uses: actions/checkout@v4
35-
36-
- name: Run tests
37-
run: cargo test --verbose
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Rust
49+
uses: actions-rust-lang/setup-rust-toolchain@v1
50+
with:
51+
cache: true
3852

39-
run-and-execute:
53+
- name: Run tests
54+
run: cargo test --verbose
55+
56+
compile-and-execute:
57+
name: Compile & Execute (${{ matrix.platform_name }})
4058
strategy:
4159
matrix:
4260
include:
4361
- os: windows-latest
62+
platform_name: Windows x64
4463
target: windows-x64
4564
nasm_format: win64
46-
executable_ext: .exe
65+
gcc_arch: ""
66+
executable_name: output.exe
67+
nasm_output: output.obj
68+
gcc_flags: "-lmsvcrt"
4769
continue_on_error: false
4870
- os: ubuntu-latest
71+
platform_name: Linux x64
4972
target: linux-x64
5073
nasm_format: elf64
51-
executable_ext: ""
74+
gcc_arch: ""
75+
executable_name: output
76+
nasm_output: output.o
77+
gcc_flags: "-no-pie"
5278
continue_on_error: true
5379
- os: macos-latest
80+
platform_name: macOS (Rosetta 2)
5481
target: macos-auto
5582
nasm_format: macho64
56-
executable_ext: "_macos"
83+
gcc_arch: "-arch x86_64"
84+
executable_name: output_macos
85+
nasm_output: output_macos.o
86+
gcc_flags: ""
5787
continue_on_error: true
58-
fail-fast: false # Don't cancel other jobs if one fails
88+
fail-fast: false
5989
runs-on: ${{ matrix.os }}
60-
continue-on-error: ${{ matrix.continue_on_error }} # Allow Linux/macOS to fail
90+
continue-on-error: ${{ matrix.continue_on_error }}
6191
needs: test
6292

6393
steps:
64-
- uses: actions/checkout@v4
65-
66-
# Windows-specific dependencies
67-
- name: Install NASM (Windows)
68-
if: matrix.os == 'windows-latest'
69-
run: |
70-
choco install nasm
71-
& "C:\Program Files\NASM\nasm.exe" -v
72-
73-
# Linux-specific dependencies
74-
- name: Install NASM and GCC (Linux)
75-
if: matrix.os == 'ubuntu-latest'
76-
run: |
77-
sudo apt-get update
78-
sudo apt-get install -y nasm gcc
79-
nasm -v
80-
gcc --version
81-
82-
# macOS-specific dependencies
83-
- name: Install NASM and GCC (macOS)
84-
if: matrix.os == 'macos-latest'
85-
run: |
86-
brew install nasm gcc
87-
nasm -v
88-
gcc --version
89-
90-
- name: Run compiler to generate ASM for target
91-
run: cargo run -- --target ${{ matrix.target }}
92-
93-
# Windows assembly and linking
94-
- name: Compile ASM to object file (Windows)
95-
if: matrix.os == 'windows-latest'
96-
run: '& "C:\Program Files\NASM\nasm.exe" -f ${{ matrix.nasm_format }} build/output.asm -o build/output.obj'
97-
98-
- name: Link and create executable (Windows)
99-
if: matrix.os == 'windows-latest'
100-
run: gcc -o build/output${{ matrix.executable_ext }} build/output.obj -lmsvcrt
101-
102-
# Linux assembly and linking
103-
- name: Compile ASM to object file (Linux)
104-
if: matrix.os == 'ubuntu-latest'
105-
run: nasm -f ${{ matrix.nasm_format }} build/output.asm -o build/output.o
106-
107-
- name: Link and create executable (Linux)
108-
if: matrix.os == 'ubuntu-latest'
109-
run: gcc -o build/output${{ matrix.executable_ext }} build/output.o -no-pie
110-
111-
# macOS assembly and linking
112-
- name: Compile ASM to object file (macOS)
113-
if: matrix.os == 'macos-latest'
114-
run: nasm -f ${{ matrix.nasm_format }} build/output.asm -o build/output${{ matrix.executable_ext }}.o
115-
116-
- name: Link and create executable (macOS)
117-
if: matrix.os == 'macos-latest'
118-
run: gcc -arch arm64 -o build/output${{ matrix.executable_ext }} build/output${{ matrix.executable_ext }}.o
119-
120-
# Execute the binary (all platforms)
121-
- name: Execute the binary (Windows)
122-
if: matrix.os == 'windows-latest'
123-
run: .\build\output${{ matrix.executable_ext }}
124-
125-
- name: Execute the binary (Linux)
126-
if: matrix.os == 'ubuntu-latest'
127-
run: ./build/output${{ matrix.executable_ext }}
128-
129-
- name: Execute the binary (macOS)
130-
if: matrix.os == 'macos-latest'
131-
run: ./build/output${{ matrix.executable_ext }}
94+
- name: Checkout code
95+
uses: actions/checkout@v4
96+
97+
- name: Setup Rust
98+
uses: actions-rust-lang/setup-rust-toolchain@v1
99+
with:
100+
cache: true
101+
102+
- name: Install dependencies (Windows)
103+
if: matrix.os == 'windows-latest'
104+
run: |
105+
choco install nasm
106+
& "C:\Program Files\NASM\nasm.exe" -v
107+
108+
- name: Install dependencies (Linux)
109+
if: matrix.os == 'ubuntu-latest'
110+
run: |
111+
sudo apt-get update
112+
sudo apt-get install -y nasm gcc
113+
nasm -v
114+
gcc --version
115+
116+
- name: Install dependencies (macOS)
117+
if: matrix.os == 'macos-latest'
118+
run: |
119+
brew install nasm
120+
nasm -v
121+
gcc --version
122+
echo "Architecture: $(uname -m)"
123+
echo "Note: Compiling for x86_64 to run via Rosetta 2"
124+
125+
- name: Create build directory
126+
run: mkdir -p build
127+
128+
- name: Generate assembly code
129+
run: cargo run -- --target ${{ matrix.target }}
130+
131+
- name: Assemble to object file (Windows)
132+
if: matrix.os == 'windows-latest'
133+
run: '& "C:\Program Files\NASM\nasm.exe" -f ${{ matrix.nasm_format }} build/output.asm -o build/${{ matrix.nasm_output }}'
134+
135+
- name: Assemble to object file (Unix)
136+
if: matrix.os != 'windows-latest'
137+
run: nasm -f ${{ matrix.nasm_format }} build/output.asm -o build/${{ matrix.nasm_output }}
138+
139+
- name: Link executable
140+
run: gcc ${{ matrix.gcc_arch }} -o build/${{ matrix.executable_name }} build/${{ matrix.nasm_output }} ${{ matrix.gcc_flags }}
141+
142+
- name: Verify executable architecture (macOS)
143+
if: matrix.os == 'macos-latest'
144+
run: |
145+
file build/${{ matrix.executable_name }}
146+
echo "✓ Executable created for x86_64 architecture (will run via Rosetta 2)"
147+
148+
- name: Execute binary (Windows)
149+
if: matrix.os == 'windows-latest'
150+
run: .\build\${{ matrix.executable_name }}
151+
152+
- name: Execute binary (Unix)
153+
if: matrix.os != 'windows-latest'
154+
run: ./build/${{ matrix.executable_name }}
155+
156+
- name: Upload artifacts
157+
uses: actions/upload-artifact@v4
158+
if: always()
159+
with:
160+
name: executable-${{ matrix.os }}
161+
path: |
162+
build/${{ matrix.executable_name }}
163+
build/output.asm
164+
retention-days: 7
165+
166+
summary:
167+
name: Build Summary
168+
if: always()
169+
needs: [build, test, compile-and-execute]
170+
runs-on: ubuntu-latest
171+
172+
steps:
173+
- name: Summary
174+
run: |
175+
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
176+
echo "" >> $GITHUB_STEP_SUMMARY
177+
echo "| Platform | Build | Test | Compile & Execute |" >> $GITHUB_STEP_SUMMARY
178+
echo "|----------|-------|------|-------------------|" >> $GITHUB_STEP_SUMMARY
179+
echo "| Windows | ${{ needs.build.result == 'success' && '✅' || '❌' }} | ${{ needs.test.result == 'success' && '✅' || '❌' }} | ${{ contains(needs.compile-and-execute.result, 'success') && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY
180+
echo "| Linux | ${{ needs.build.result == 'success' && '✅' || '❌' }} | ${{ needs.test.result == 'success' && '✅' || '❌' }} | ${{ contains(needs.compile-and-execute.result, 'success') && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY
181+
echo "| macOS | ${{ needs.build.result == 'success' && '✅' || '❌' }} | ${{ needs.test.result == 'success' && '✅' || '❌' }} | ${{ contains(needs.compile-and-execute.result, 'success') && '✅' || '❌' }} |" >> $GITHUB_STEP_SUMMARY
182+
echo "" >> $GITHUB_STEP_SUMMARY
183+
echo "**Note:** macOS binaries are compiled for x86_64 and run via Rosetta 2 on ARM64 machines." >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)