Skip to content

Commit c59e47b

Browse files
committed
create universal macOS builds
1 parent 56139d4 commit c59e47b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ jobs:
3636
- uses: actions/checkout@v3
3737

3838
- name: Configure project
39-
run: cmake --preset dev
39+
run: cmake --preset dev -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'
4040

4141
- name: Build project
4242
run: cmake --build --preset dev
43+
env:
44+
UNIVERSAL_BUILD: 1
4345

4446
- name: Run tests
4547
run: ruby test/rj_test.rb

mruby_config.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,35 @@
88
# C compiler settings
99
conf.enable_cxx_abi
1010
conf.enable_cxx_exception
11+
12+
if ENV.key?("UNIVERSAL_BUILD")
13+
conf.cc.flags << %w(-arch arm64 -arch x86_64)
14+
conf.cxx.flags << %w(-arch arm64 -arch x86_64)
15+
conf.linker.flags << %w(-arch arm64 -arch x86_64)
16+
end
17+
end
18+
19+
return unless ENV.key?("UNIVERSAL_BUILD")
20+
21+
# Hack to fix the preprocessor command in universal builds:
22+
23+
class MRuby::Command::Compiler
24+
# https://github.com/mruby/mruby/blob/3.1.0/lib/mruby/build/command.rb#L87-L100
25+
def run(outfile, infile, _defines=[], _include_paths=[], _flags=[])
26+
mkdir_p File.dirname(outfile)
27+
flags = all_flags(_defines, _include_paths, _flags)
28+
if object_ext?(outfile)
29+
label = @label
30+
opts = compile_options
31+
else
32+
label = "CPP"
33+
opts = preprocess_options
34+
flags << " -DMRB_PRESYM_SCANNING"
35+
# need to remove the `-arch` flags from the preprocessor command here as clang errors out otherwise:
36+
# clang: error: cannot use 'c++-cpp-output' output with multiple -arch options
37+
flags = flags.sub('-arch arm64 -arch x86_64', '')
38+
end
39+
_pp label, infile.relative_path, outfile.relative_path
40+
_run opts, flags: flags, infile: filename(infile), outfile: filename(outfile)
41+
end
1142
end

0 commit comments

Comments
 (0)