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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions tool/cosmocc/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,49 @@ mode() {
esac
}

_nproc() {
case $(uname -s) in
Darwin) sysctl -n hw.logicalcpu ;;
*) nproc ;;
esac
}

TMPDIR=${TMPDIR:-/tmp}
OUTDIR=${1:-cosmocc}
APELINK=o/$(mode)/tool/build/apelink
AMD64=${2:-x86_64}
ARM64=${3:-aarch64}
NPROC=$(($(nproc)/2))
NPROC=$(($(_nproc)/2))
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

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/$AMD64/ape/ape.lds \
o/$AMD64/libc/crt/crt.o \
Expand Down Expand Up @@ -62,7 +94,7 @@ make -j$NPROC m=$AMD64 \
o/$AMD64/third_party/make/make.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/$AMD64-tiny/ape/ape.lds \
o/$AMD64-tiny/libc/crt/crt.o \
Expand All @@ -74,7 +106,7 @@ make -j$NPROC m=$AMD64-tiny \
o/$AMD64-tiny/cosmopolitan.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/$AMD64-dbg/ape/ape.lds \
o/$AMD64-dbg/libc/crt/crt.o \
Expand All @@ -86,7 +118,7 @@ make -j$NPROC m=$AMD64-dbg \
o/$AMD64-dbg/cosmopolitan.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/$AMD64-optlinux/ape/ape.lds \
o/$AMD64-optlinux/libc/crt/crt.o \
Expand All @@ -98,7 +130,7 @@ make CONFIG_TARGET_ARCH= -j$NPROC m=$AMD64-optlinux \
o/$AMD64-optlinux/cosmopolitan.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/aarch64.lds \
o/$ARM64/libc/crt/crt.o \
Expand Down Expand Up @@ -130,21 +162,21 @@ make -j$NPROC m=$ARM64 \
o/$ARM64/third_party/make/make.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/aarch64.lds \
o/$ARM64-tiny/libc/crt/crt.o \
o/$ARM64-tiny/cosmopolitan.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/aarch64.lds \
o/$ARM64-dbg/libc/crt/crt.o \
o/$ARM64-dbg/cosmopolitan.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/aarch64.lds \
o/$ARM64-optlinux/libc/crt/crt.o \
Expand Down Expand Up @@ -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 \
ar chmod cocmd cp echo gzip objbincopy package rm touch mkdir compile sha256sum \
resymbol; do
ape $APELINK \
$APE $APELINK \
-l o/$AMD64/ape/ape.elf \
-l o/$ARM64/ape/ape.elf \
-M ape/ape-m1.c \
Expand All @@ -286,7 +318,7 @@ for x in ar chmod cp echo gzip package rm touch mkdir compile sha256sum; do
done

for x in make ctags; do
ape $APELINK \
$APE $APELINK \
-l o/$AMD64/ape/ape.elf \
-l o/$ARM64/ape/ape.elf \
-M ape/ape-m1.c \
Expand Down