Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmocc: build toolchain on MacOS #1365

Merged
merged 8 commits into from
Feb 8, 2025
Merged

Conversation

bjia56
Copy link
Contributor

@bjia56 bjia56 commented Feb 8, 2025

This updates the cosmocc toolchain packaging script to work on MacOS. Tested on GitHub Actions macos-13 (x86_64) and macos-14 (arm64) runners and verified to still work on Ubuntu (GitHub Actions runners ubuntu-24.04 and ubuntu-24.04-arm). End goal is to bring cosmocc to MacPorts by running the packaging script.

gmake is used instead of make because both Homebrew and MacPorts install newer make's with the g prefix.

Additionally, the APE loader from the bootstrapper toolchain is used instead of a system APE, which may not be available.

@github-actions github-actions bot added the tool label Feb 8, 2025
$APELINK

make -j$NPROC m=$AMD64 \
case $(uname -s) in
Copy link
Owner

Choose a reason for hiding this comment

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

Could you check if it's on the path first?

if ! APE=$(command -v ape); then
  # do your thing
fi

esac
}

which_make() {
Copy link
Owner

Choose a reason for hiding this comment

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

if ! MAKE=$(command -v gmake); then
  if ! MAKE=$(command -v make); then
    echo please install gnu make >&2
    exit 1
  fi
fi

On second thought, couldn't we just say

MAKE="$APE .cosmocc/current/bin/make"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I would prefer the first option, per reasoning below.

As things are built now, there's a chicken-and-egg problem when starting off of a fresh repo, such as building from a source release tarball. There is no guarantee of APE on the system, and a valid MAKE is required to launch the root Makefile to download the bootstrap cosmocc which has a valid APE and MAKE.

Calling download-cosmocc.sh from package.sh directly, before any MAKE invocations, could work, however as-is, there would be a duplication of specifying which bootstrap toolchain to use. We could update download-cosmocc.sh to be the authoritative source of which version to download, and modify the root Makefile to not provide any arguments, though I'm not sure how "generic" that script should be or if it's ok to impose a set of conventions. There would also need to be a way for the root Makefile to extract out of the script which version directory it is creating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I see there is a build/bootstrap directory which contains APE launchers. Could we add a blessed MAKE and ape-m1.c to that as well? In that case, the package.sh would first find/build APE (if one doesn't exist in PATH already), then use the MAKE inside build/bootstrap.

I see from git history that a MAKE was part of that folder at one point.

Copy link
Owner

Choose a reason for hiding this comment

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

I say just go with the first one. It's not too burdensome to ask for gmake if they're building a cosmocc toolchain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, in that case I think I applied the requested changes and this is ready for another review.

@jart jart merged commit 10a92ce into jart:master Feb 8, 2025
6 checks passed
@jart
Copy link
Owner

jart commented Feb 8, 2025

Thank you! Commit message edited to follow 72 column rule and use imperative tense in first line.

@bjia56 bjia56 deleted the cosmocc-build-on-macos branch February 8, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants