Skip to content

Commit

Permalink
Introduce cosmocc and cosmoc++ toolchain commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Sep 20, 2022
1 parent bfb85fe commit 6cc9e08
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libc/sysv/consts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ syscon alg ALG_SET_DRBG_ENTROPY 6 0 0 0 0 0
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon tcp TCP_NODELAY 1 1 1 1 1 1 # strong consensus for disabling nagle's algorithm; so be sure to disable it by turning this on
syscon tcp TCP_CORK 3 4 4 16 0 0 # nagle's algorithm strikes again; TCP_NOPUSH on BSD; be sure to turn it off; protip: mmap+writev vs. write+sendfile; see also /proc/sys/net/ipv4/tcp_autocorking; netbsd is 4 but not implemented
syscon tcp TCP_CORK 3 4 4 16 4 0 # nagle's algorithm strikes again; TCP_NOPUSH on BSD; be sure to turn it off; protip: mmap+writev vs. write+sendfile; see also /proc/sys/net/ipv4/tcp_autocorking; netbsd is 4 but not implemented
syscon tcp TCP_MAXSEG 2 2 2 2 2 0 # reduces tcp segment size; see also tcp offloading
syscon tcp TCP_FASTOPEN 23 0 0x0401 0 0 15 # reduces roundtrips; for listener; Linux 3.7+ (c. 2012) / or is windows it 0x22? /proc/sys/net/ipv4/tcp_fastopen TODO(jart): MSG_FASTOPEN; XNU sources say 261 but not sure if that's true
syscon tcp TCP_FASTOPEN_CONNECT 30 0 0 0 0 0 # reduces roundtrips; for listener; Linux 3.7+ (c. 2012) / or is windows it 0x22? /proc/sys/net/ipv4/tcp_fastopen TODO(jart): MSG_FASTOPEN; XNU sources say 261 but not sure if that's true
Expand Down
2 changes: 1 addition & 1 deletion libc/sysv/consts/TCP_CORK.s
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon tcp,TCP_CORK,3,4,4,16,0,0
.syscon tcp,TCP_CORK,3,4,4,16,4,0
70 changes: 70 additions & 0 deletions tool/scripts/cosmoc++
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh
# replacement for c++ command
#
# we assume you run the following beforehand
#
# sudo chmod 1777 /opt
# cd /opt
# git clone https://github.com/jart/cosmopolitan cosmo
# cd cosmo
# make -j
#
# you can then use it to build open source projects, e.g.
#
# export CC=cosmocc
# export CXX=cosmoc++
# export LD=cosmoc++
# ./configure --prefix=/opt/cosmos
# make -j
# make install
#

if [ "$1" = "--version" ]; then
cat <<'EOF'
x86_64-unknown-cosmo-g++ (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit 0
fi

CXX="/opt/cosmo/o/third_party/gcc/bin/x86_64-linux-musl-g++"
CCFLAGS="-O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CXXFLAGS="-fno-exceptions -fuse-cxa-atexit -fno-threadsafe-statics"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem /opt/cosmos/include -isystem /opt/cosmo/libc/isystem -include libc/integral/normalize.inc"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -L/opt/cosmos/lib -Wl,-T,/opt/cosmo/o/ape/public/ape.lds /opt/cosmo/o/ape/ape-no-modify-self.o /opt/cosmo/o/libc/crt/crt.o"
LDLIBS="/opt/cosmo/o/third_party/libcxx/libcxx.a /opt/cosmo/o/cosmopolitan.a"

HAS_C=0
HAS_O=0
HAS_E=0
FIRST=1
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
if [ "$x" = "-c" ]; then
HAS_C=1
fi
if [ "$x" = "-E" ]; then
HAS_E=1
fi
if [ "$x" = "-o" ] || [ "${x#-o}" != "$x" ]; then
HAS_O=1
fi
set -- "$@" "$x"
done

if [ "$HAS_E" = "1" ]; then
set -- $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CCFLAGS $CXXFLAGS $CPPFLAGS "$@"
else
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
fi

set -- "$CXX" "$@"
printf '(cd %s; %s)\n' "$PWD" "$*" >>/tmp/build.log
exec "$@"
69 changes: 69 additions & 0 deletions tool/scripts/cosmocc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh
# replacement for cc command
#
# we assume you run the following beforehand
#
# sudo chmod 1777 /opt
# cd /opt
# git clone https://github.com/jart/cosmopolitan cosmo
# cd cosmo
# make -j
#
# you can then use it to build open source projects, e.g.
#
# export CC=cosmocc
# export CXX=cosmoc++
# export LD=cosmoc++
# ./configure --prefix=/opt/cosmos
# make -j
# make install
#

if [ "$1" = "--version" ]; then
cat <<'EOF'
x86_64-unknown-cosmo-gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit 0
fi

CC="/opt/cosmo/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
CFLAGS="-g -O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem /opt/cosmos/include -isystem /opt/cosmo/libc/isystem -include libc/integral/normalize.inc"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -L/opt/cosmos/lib -Wl,-T,/opt/cosmo/o/ape/public/ape.lds /opt/cosmo/o/ape/ape-no-modify-self.o /opt/cosmo/o/libc/crt/crt.o"
LDLIBS="/opt/cosmo/o/cosmopolitan.a"

HAS_C=0
HAS_O=0
HAS_E=0
FIRST=1
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
if [ "$x" = "-c" ]; then
HAS_C=1
fi
if [ "$x" = "-E" ]; then
HAS_E=1
fi
if [ "$x" = "-o" ] || [ "${x#-o}" != "$x" ]; then
HAS_O=1
fi
set -- "$@" "$x"
done

if [ "$HAS_E" = "1" ]; then
set -- $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CFLAGS $CPPFLAGS "$@"
else
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
fi

set -- "$CC" "$@"
printf '(cd %s; %s)\n' "$PWD" "$*" >>/tmp/build.log
exec "$@"

0 comments on commit 6cc9e08

Please sign in to comment.