Skip to content

Add native macOS build scripts (2.7.2-psx, 2.7.2-cdk, 2.8.1-psx)#34

Merged
mkst merged 2 commits into
decompals:masterfrom
andreadellacorte:macos-native-build
Apr 6, 2026
Merged

Add native macOS build scripts (2.7.2-psx, 2.7.2-cdk, 2.8.1-psx)#34
mkst merged 2 commits into
decompals:masterfrom
andreadellacorte:macos-native-build

Conversation

@andreadellacorte
Copy link
Copy Markdown
Contributor

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 cc1 binaries without requiring Docker.

What's included

  • gcc-2.7.2-psx-macos.sh
  • gcc-2.7.2-cdk-macos.sh
  • gcc-2.8.1-psx-macos.sh
  • patches/xm-darwin.h — LP64 host descriptor for macOS Darwin
  • patches/eprintf-darwin.c__eprintf stub (removed from macOS SDKs post-10.14, needed by 2.7.2-cdk)
  • MakefilePLATFORM=macos support (make VERSION=2.8.1-psx PLATFORM=macos)
  • .github/workflows/build-macos.yml — CI on macos-latest, publishes gcc-VERSION-macos.tar.gz to releases on tags

macOS-specific patches applied by the scripts

  1. config.guess/config.sub — replaced with modern versions (knows about aarch64-apple-darwin); psx* added to config.sub OS list
  2. configure*-apple-darwin* case added to host machine selection, pointing to new xm-darwin.h
  3. xm-darwin.h — host descriptor for LP64 macOS (int=32-bit, long=64-bit); defines FALSE, TRUE, HAVE_VPRINTF, HAVE_STRERROR, POSIX, BSTRING
  4. configure invocation--host/--build passed explicitly (avoids multi-arg config.sub call that modern config.sub rejects); CFLAGS exported so the configure compiler test (main(){}) passes modern clang
  5. 2.7.2-cdk specific — requires byacc, single-threaded build (parallel yacc invocations race on y.tab.h), __eprintf stub linked in via LDFLAGS
  6. 2.8.1-psx specifictouch insn-config.h before build, unset CC CXX, system PATH prepended

All 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.

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
@andreadellacorte
Copy link
Copy Markdown
Contributor Author

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 + macos-latest GitHub Actions runner) is effectively what option 2 would produce — native Mach-O cc1 binaries published to releases — just without going through Docker. The scripts play the same role as the Dockerfiles do for Linux: they encode all the build steps reproducibly and CI runs them automatically.

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.

Comment thread gcc-2.7.2-cdk-macos.sh Outdated
# 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two curls feel quite fragile (using the git hash would be less fragile)

Copy link
Copy Markdown
Contributor Author

@andreadellacorte andreadellacorte Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; pinned both to specific commits (config.guess: 74af13c, config.sub: 6fad101) in the latest push.

Comment thread gcc-2.7.2-cdk-macos.sh Outdated

# Build single-threaded: parallel yacc invocations race on y.tab.h,
# causing bi-parser.h to be generated with the wrong grammar.
make cc1 \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you get anywhere trying to build the other binaries? gcc/g++/etc?

Copy link
Copy Markdown
Contributor Author

@andreadellacorte andreadellacorte Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only cc1 initially, but I just updated the scripts to build cpp/cc1/xgcc/cc1plus/g++ to match the Dockerfiles.

@mkst
Copy link
Copy Markdown
Contributor

mkst commented Apr 6, 2026

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?

Comment thread gcc-2.8.1-psx-macos.sh Outdated

# Apply the same patches as the Linux Dockerfile
python3 -c "
import glob, os, stat
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to use grep + sed?

Copy link
Copy Markdown
Contributor Author

@andreadellacorte andreadellacorte Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@andreadellacorte
Copy link
Copy Markdown
Contributor Author

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?

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

@andreadellacorte andreadellacorte requested a review from mkst April 6, 2026 19:39
@mkst
Copy link
Copy Markdown
Contributor

mkst commented Apr 6, 2026

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!

@mkst mkst merged commit b2f1008 into decompals:master Apr 6, 2026
25 checks passed
@andreadellacorte andreadellacorte deleted the macos-native-build branch May 13, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS native binaries in releases

2 participants