Add native macOS build scripts (2.7.2-psx, 2.7.2-cdk, 2.8.1-psx)#34
Conversation
Produces native Mach-O arm64/x86_64 cc1 binaries on macOS without Docker.
Approach:
- Replace config.guess/config.sub with modern versions + psx* OS entry
- Add xm-darwin.h (LP64 host descriptor) and patch configure for *-apple-darwin*
- Pass --host/--build explicitly to avoid multi-arg config.sub calls
- Export CFLAGS=-std=gnu89 so configure's compiler test (main(){}) passes clang
- 2.7.2-cdk: requires byacc, single-threaded build (yacc race), __eprintf stub
- 2.8.1-psx: touch insn-config.h, unset CC/CXX, prepend system PATH
Also adds Makefile PLATFORM=macos support and a build-macos.yml GitHub Actions
workflow (macos-latest runner, matrix: 2.7.2-psx, 2.7.2-cdk, 2.8.1-psx).
Closes decompals#33
|
Note on approach vs. what was discussed in #33 In #33 I proposed two options and you indicated a preference for option 2 ("macOS Dockerfiles"). I should have flagged this before opening the PR: option 2 as I described it isn't really practical for a public repo. Cross-compiling to macOS from a Linux Docker container requires osxcross, which in turn requires Apple's macOS SDK — and Apple doesn't permit redistributing the SDK. So any Dockerfile using osxcross would be self-contained for the maintainer but not for anyone else without the SDK. That makes it significantly more complex than the existing Dockerfiles. What I've implemented here (shell scripts + Apologies for not raising this before opening the PR. Happy to close it and discuss further in #33 if you'd prefer a different approach. |
| # macOS: replace config.guess/config.sub with modern versions that know | ||
| # about aarch64-apple-darwin, then add psx* to the OS list. | ||
| chmod +w config.guess config.sub | ||
| curl -fsL "https://raw.githubusercontent.com/gcc-mirror/gcc/master/config.guess" -o config.guess |
There was a problem hiding this comment.
these two curls feel quite fragile (using the git hash would be less fragile)
There was a problem hiding this comment.
Good point; pinned both to specific commits (config.guess: 74af13c, config.sub: 6fad101) in the latest push.
|
|
||
| # Build single-threaded: parallel yacc invocations race on y.tab.h, | ||
| # causing bi-parser.h to be generated with the wrong grammar. | ||
| make cc1 \ |
There was a problem hiding this comment.
did you get anywhere trying to build the other binaries? gcc/g++/etc?
There was a problem hiding this comment.
Only cc1 initially, but I just updated the scripts to build cpp/cc1/xgcc/cc1plus/g++ to match the Dockerfiles.
|
So this is Option 1 then really? Not Option 2 - because there's no way to create a docker image that includes osxcross due to Apply restrictions? |
|
|
||
| # Apply the same patches as the Linux Dockerfile | ||
| python3 -c " | ||
| import glob, os, stat |
There was a problem hiding this comment.
any reason not to use grep + sed?
There was a problem hiding this comment.
No good reason, I was originally written inside a nix shell where GNU sed was in PATH and sed -i '' is BSD-only syntax, so I fell back to Python. Since these scripts run natively on macOS, sed is fine.
I now switched to grep+sed for the varargs substitution and awk for the configure patch in the latest push.
- Pin config.guess/config.sub fetches to specific commits (74af13c, 6fad101)
instead of tracking master, for reproducibility
- Replace Python text substitutions with grep+sed (varargs) and awk (configure
patch); add PATH=/usr/bin:... to all scripts so BSD sed is used
- Build cpp/cc1/xgcc/cc1plus/g++ to match the Linux Dockerfiles; fixes needed:
- sys_nerr declared 'const int' in macOS SDKs — patch gcc.c and cp/g++.c
- __eprintf in eprintf-darwin.c marked weak so tree.o's strong definition
wins in cdk (avoids duplicate symbol error when linking cc1plus)
- awk configure patch made context-aware: buffer each \t*) line and only
insert *-apple-darwin* before the one followed by the "not supported" echo
(2.8.1 configure has an unrelated \t*) earlier that fooled the first pass)
correct, unfortunately I've found no way around it for github actions; seems like it was possible some time ago, but then github removed it for licensing issues |
No problem - just wanted to make sure I understood the situation 👍 Given the constraints I think this PR is ace. I'll merge it and tag a release - thank you! |
Closes #33.
Following @mkst's suggestion in #33 to go with option 2 (separate scripts, similar to existing Dockerfiles), this PR adds native macOS build scripts that produce Mach-O arm64/x86_64
cc1binaries without requiring Docker.What's included
gcc-2.7.2-psx-macos.shgcc-2.7.2-cdk-macos.shgcc-2.8.1-psx-macos.shpatches/xm-darwin.h— LP64 host descriptor for macOS Darwinpatches/eprintf-darwin.c—__eprintfstub (removed from macOS SDKs post-10.14, needed by 2.7.2-cdk)Makefile—PLATFORM=macossupport (make VERSION=2.8.1-psx PLATFORM=macos).github/workflows/build-macos.yml— CI onmacos-latest, publishesgcc-VERSION-macos.tar.gzto releases on tagsmacOS-specific patches applied by the scripts
psx*added to config.sub OS list*-apple-darwin*case added to host machine selection, pointing to newxm-darwin.hFALSE,TRUE,HAVE_VPRINTF,HAVE_STRERROR,POSIX,BSTRING--host/--buildpassed explicitly (avoids multi-argconfig.subcall that modern config.sub rejects); CFLAGS exported so the configure compiler test (main(){}) passes modern clangbyacc, single-threaded build (parallelyaccinvocations race ony.tab.h),__eprintfstub linked in viaLDFLAGStouch insn-config.hbefore build,unset CC CXX, system PATH prependedAll three scripts have been tested on macOS 15 (Apple Silicon, arm64) and produce binaries that pass the same test suite as the Dockerfiles.
This is motivated by the need to build ser-pounce/rood-reverse natively on macOS — see ser-pounce/rood-reverse#9 for context.