mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-04-03 06:18:45 +00:00
Support building cosmocc on MacOS (#1365)
Some checks are pending
build / matrix_on_mode () (push) Waiting to run
build / matrix_on_mode (optlinux) (push) Waiting to run
build / matrix_on_mode (rel) (push) Waiting to run
build / matrix_on_mode (tiny) (push) Waiting to run
build / matrix_on_mode (tinylinux) (push) Waiting to run
Some checks are pending
build / matrix_on_mode () (push) Waiting to run
build / matrix_on_mode (optlinux) (push) Waiting to run
build / matrix_on_mode (rel) (push) Waiting to run
build / matrix_on_mode (tiny) (push) Waiting to run
build / matrix_on_mode (tinylinux) (push) Waiting to run
This updates the cosmocc toolchain packaging script to work on MacOS. It has been tested on GitHub Actions macos-13 (x86_64) and macos-14 (arm64) runners, and is verified to still work on Ubuntu (GitHub Actions runners ubuntu-24.04 and ubuntu-24.04-arm). It'll help bring cosmocc to MacPorts by running the packaging script. We favor `gmake` rather than the `make` command because it distinguishes GNU Make from BSD Make, and Xcode Make. Additionally, APE loader from the bootstrapper toolchain is used instead of a system APE, which may not be available.
This commit is contained in:
parent
42a9ed0131
commit
10a92cee94
1 changed files with 44 additions and 12 deletions
|
@ -15,17 +15,49 @@ mode() {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_nproc() {
|
||||||
|
case $(uname -s) in
|
||||||
|
Darwin) sysctl -n hw.logicalcpu ;;
|
||||||
|
*) nproc ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
TMPDIR=${TMPDIR:-/tmp}
|
||||||
OUTDIR=${1:-cosmocc}
|
OUTDIR=${1:-cosmocc}
|
||||||
APELINK=o/$(mode)/tool/build/apelink
|
APELINK=o/$(mode)/tool/build/apelink
|
||||||
AMD64=${2:-x86_64}
|
AMD64=${2:-x86_64}
|
||||||
ARM64=${3:-aarch64}
|
ARM64=${3:-aarch64}
|
||||||
NPROC=$(($(nproc)/2))
|
NPROC=$(($(_nproc)/2))
|
||||||
GCCVER=14.1.0
|
GCCVER=14.1.0
|
||||||
|
|
||||||
make -j$NPROC m= \
|
if ! MAKE=$(command -v gmake); then
|
||||||
|
if ! MAKE=$(command -v make); then
|
||||||
|
echo please install gnu make >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
$MAKE -j$NPROC m= \
|
||||||
$APELINK
|
$APELINK
|
||||||
|
|
||||||
make -j$NPROC m=$AMD64 \
|
if ! APE=$(command -v ape); then
|
||||||
|
case $(uname -s) in
|
||||||
|
Darwin)
|
||||||
|
case $(mode) in
|
||||||
|
aarch64)
|
||||||
|
cc -O -o "$TMPDIR/ape.$$" .cosmocc/current/bin/ape-m1.c || exit
|
||||||
|
trap 'rm "$TMPDIR/ape.$$"' EXIT
|
||||||
|
APE=$TMPDIR/ape.$$
|
||||||
|
;;
|
||||||
|
*) APE=.cosmocc/current/bin/ape-x86_64.macho ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*) APE=.cosmocc/current/bin/ape-$(uname -m).elf ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
stat $APE
|
||||||
|
|
||||||
|
$MAKE -j$NPROC m=$AMD64 \
|
||||||
o/cosmocc.h.txt \
|
o/cosmocc.h.txt \
|
||||||
o/$AMD64/ape/ape.lds \
|
o/$AMD64/ape/ape.lds \
|
||||||
o/$AMD64/libc/crt/crt.o \
|
o/$AMD64/libc/crt/crt.o \
|
||||||
|
@ -62,7 +94,7 @@ make -j$NPROC m=$AMD64 \
|
||||||
o/$AMD64/third_party/make/make.dbg \
|
o/$AMD64/third_party/make/make.dbg \
|
||||||
o/$AMD64/third_party/ctags/ctags.dbg
|
o/$AMD64/third_party/ctags/ctags.dbg
|
||||||
|
|
||||||
make -j$NPROC m=$AMD64-tiny \
|
$MAKE -j$NPROC m=$AMD64-tiny \
|
||||||
o/cosmocc.h.txt \
|
o/cosmocc.h.txt \
|
||||||
o/$AMD64-tiny/ape/ape.lds \
|
o/$AMD64-tiny/ape/ape.lds \
|
||||||
o/$AMD64-tiny/libc/crt/crt.o \
|
o/$AMD64-tiny/libc/crt/crt.o \
|
||||||
|
@ -74,7 +106,7 @@ make -j$NPROC m=$AMD64-tiny \
|
||||||
o/$AMD64-tiny/cosmopolitan.a \
|
o/$AMD64-tiny/cosmopolitan.a \
|
||||||
o/$AMD64-tiny/third_party/libcxx/libcxx.a \
|
o/$AMD64-tiny/third_party/libcxx/libcxx.a \
|
||||||
|
|
||||||
make -j$NPROC m=$AMD64-dbg \
|
$MAKE -j$NPROC m=$AMD64-dbg \
|
||||||
o/cosmocc.h.txt \
|
o/cosmocc.h.txt \
|
||||||
o/$AMD64-dbg/ape/ape.lds \
|
o/$AMD64-dbg/ape/ape.lds \
|
||||||
o/$AMD64-dbg/libc/crt/crt.o \
|
o/$AMD64-dbg/libc/crt/crt.o \
|
||||||
|
@ -86,7 +118,7 @@ make -j$NPROC m=$AMD64-dbg \
|
||||||
o/$AMD64-dbg/cosmopolitan.a \
|
o/$AMD64-dbg/cosmopolitan.a \
|
||||||
o/$AMD64-dbg/third_party/libcxx/libcxx.a \
|
o/$AMD64-dbg/third_party/libcxx/libcxx.a \
|
||||||
|
|
||||||
make CONFIG_TARGET_ARCH= -j$NPROC m=$AMD64-optlinux \
|
$MAKE CONFIG_TARGET_ARCH= -j$NPROC m=$AMD64-optlinux \
|
||||||
o/cosmocc.h.txt \
|
o/cosmocc.h.txt \
|
||||||
o/$AMD64-optlinux/ape/ape.lds \
|
o/$AMD64-optlinux/ape/ape.lds \
|
||||||
o/$AMD64-optlinux/libc/crt/crt.o \
|
o/$AMD64-optlinux/libc/crt/crt.o \
|
||||||
|
@ -98,7 +130,7 @@ make CONFIG_TARGET_ARCH= -j$NPROC m=$AMD64-optlinux \
|
||||||
o/$AMD64-optlinux/cosmopolitan.a \
|
o/$AMD64-optlinux/cosmopolitan.a \
|
||||||
o/$AMD64-optlinux/third_party/libcxx/libcxx.a \
|
o/$AMD64-optlinux/third_party/libcxx/libcxx.a \
|
||||||
|
|
||||||
make -j$NPROC m=$ARM64 \
|
$MAKE -j$NPROC m=$ARM64 \
|
||||||
o/$ARM64/ape/ape.elf \
|
o/$ARM64/ape/ape.elf \
|
||||||
o/$ARM64/ape/aarch64.lds \
|
o/$ARM64/ape/aarch64.lds \
|
||||||
o/$ARM64/libc/crt/crt.o \
|
o/$ARM64/libc/crt/crt.o \
|
||||||
|
@ -130,21 +162,21 @@ make -j$NPROC m=$ARM64 \
|
||||||
o/$ARM64/third_party/make/make.dbg \
|
o/$ARM64/third_party/make/make.dbg \
|
||||||
o/$ARM64/third_party/ctags/ctags.dbg
|
o/$ARM64/third_party/ctags/ctags.dbg
|
||||||
|
|
||||||
make -j$NPROC m=$ARM64-tiny \
|
$MAKE -j$NPROC m=$ARM64-tiny \
|
||||||
o/$ARM64-tiny/ape/ape.elf \
|
o/$ARM64-tiny/ape/ape.elf \
|
||||||
o/$ARM64-tiny/ape/aarch64.lds \
|
o/$ARM64-tiny/ape/aarch64.lds \
|
||||||
o/$ARM64-tiny/libc/crt/crt.o \
|
o/$ARM64-tiny/libc/crt/crt.o \
|
||||||
o/$ARM64-tiny/cosmopolitan.a \
|
o/$ARM64-tiny/cosmopolitan.a \
|
||||||
o/$ARM64-tiny/third_party/libcxx/libcxx.a \
|
o/$ARM64-tiny/third_party/libcxx/libcxx.a \
|
||||||
|
|
||||||
make -j$NPROC m=$ARM64-dbg \
|
$MAKE -j$NPROC m=$ARM64-dbg \
|
||||||
o/$ARM64-dbg/ape/ape.elf \
|
o/$ARM64-dbg/ape/ape.elf \
|
||||||
o/$ARM64-dbg/ape/aarch64.lds \
|
o/$ARM64-dbg/ape/aarch64.lds \
|
||||||
o/$ARM64-dbg/libc/crt/crt.o \
|
o/$ARM64-dbg/libc/crt/crt.o \
|
||||||
o/$ARM64-dbg/cosmopolitan.a \
|
o/$ARM64-dbg/cosmopolitan.a \
|
||||||
o/$ARM64-dbg/third_party/libcxx/libcxx.a \
|
o/$ARM64-dbg/third_party/libcxx/libcxx.a \
|
||||||
|
|
||||||
make -j$NPROC m=$ARM64-optlinux \
|
$MAKE -j$NPROC m=$ARM64-optlinux \
|
||||||
o/$ARM64-optlinux/ape/ape.elf \
|
o/$ARM64-optlinux/ape/ape.elf \
|
||||||
o/$ARM64-optlinux/ape/aarch64.lds \
|
o/$ARM64-optlinux/ape/aarch64.lds \
|
||||||
o/$ARM64-optlinux/libc/crt/crt.o \
|
o/$ARM64-optlinux/libc/crt/crt.o \
|
||||||
|
@ -272,7 +304,7 @@ cp -f o/$ARM64/ape/ape.elf "$OUTDIR/bin/ape-aarch64.elf"
|
||||||
for x in assimilate march-native mktemper fixupobj zipcopy apelink pecheck mkdeps zipobj \
|
for x in assimilate march-native mktemper fixupobj zipcopy apelink pecheck mkdeps zipobj \
|
||||||
ar chmod cocmd cp echo gzip objbincopy package rm touch mkdir compile sha256sum \
|
ar chmod cocmd cp echo gzip objbincopy package rm touch mkdir compile sha256sum \
|
||||||
resymbol; do
|
resymbol; do
|
||||||
ape $APELINK \
|
$APE $APELINK \
|
||||||
-l o/$AMD64/ape/ape.elf \
|
-l o/$AMD64/ape/ape.elf \
|
||||||
-l o/$ARM64/ape/ape.elf \
|
-l o/$ARM64/ape/ape.elf \
|
||||||
-M ape/ape-m1.c \
|
-M ape/ape-m1.c \
|
||||||
|
@ -286,7 +318,7 @@ for x in ar chmod cp echo gzip package rm touch mkdir compile sha256sum; do
|
||||||
done
|
done
|
||||||
|
|
||||||
for x in make ctags; do
|
for x in make ctags; do
|
||||||
ape $APELINK \
|
$APE $APELINK \
|
||||||
-l o/$AMD64/ape/ape.elf \
|
-l o/$AMD64/ape/ape.elf \
|
||||||
-l o/$ARM64/ape/ape.elf \
|
-l o/$ARM64/ape/ape.elf \
|
||||||
-M ape/ape-m1.c \
|
-M ape/ape-m1.c \
|
||||||
|
|
Loading…
Add table
Reference in a new issue