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

wip: cosmocc #46

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions _run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
echo "I/Setup ham environment"
. hat repos default shell_linter

echo "I/Run cosmo_pi.com"
(
set -x
time cosmo-run "$HAM_HOME/bin/cosmo_pi.com"
)

echo "I/Build ham"
(
set -x
Expand All @@ -22,10 +28,18 @@ echo "I/Run ham tests"
ham all
)

echo "I/Build and run pi with ham"
echo "I/Build and run pi with ham using the default toolset"
(
set -x
git-cleanup-repo doit "$HAM_HOME/sources/ham/tests/pi"
BUILD_TARGET=default hamx -dx :ham/sources/ham/tests/pi Run_pi
)

echo "I/Build and run pi with ham using the cosmocc toolset"
(
set -x
ham -X ham/sources/ham/tests/pi Run_pi
git-cleanup-repo doit "$HAM_HOME/sources/ham/tests/pi"
BUILD_TARGET=cosmocc hamx -dx :ham/sources/ham/tests/pi Run_pi
)

echo "I/Test examples"
Expand Down
61 changes: 61 additions & 0 deletions bin/cosmo-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
if [[ -z "$HAM_HOME" ]]; then
echo "E/HAM_HOME not set !"
exit 1
fi
. "$HAM_HOME/bin/ham-bash-setenv.sh"

usage() {
echo "usage:"
echo " cosmo-run COM PARAMS"
echo " Run the specified cosmocc executable."
echo " cosmo-run ape_install"
echo " Install the APE executable format handler on Linux. This enable using"
echo " cosmo exe on Linux without using cosmo-run. Requires sudo access."
exit 1
}

if [ "$1" == "ape_install" ]; then
log_info "Installing APE binary handler..."
case $HAM_OS in
LINUX*)
(
set -x
sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf
sudo chmod +x /usr/bin/ape
sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
)
log_info "Done."
;;
*)
log_info "APE binary handler install not needed on this platform '$HAM_OS'."
;;
esac
exit 0
fi

if [ -z "$1" ]; then
log_error "Com exe to run not specified."
usage
fi
COM=$1
shift

COM_PATH=$COM
if [ -e "$COM_PATH" ]; then
# log_info "Running '$COM_PATH'."
# log_info "In '$(pwd)'."
# set -x
case $HAM_OS in
LINUX*)
sh "$COM_PATH" "$@"
;;
*)
"$COM_PATH" "$@"
;;
esac
else
log_error "'$COM' not found."
exit 1
fi
Binary file added bin/cosmo_pi.com
Binary file not shown.
3 changes: 3 additions & 0 deletions bin/ham-cppm-get-toolset
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ case "$TARGET_BIN_LOA" in
ios-arm64)
TOOLSET_NAME=ios
;;
cosmocc)
TOOLSET_NAME=cosmocc
;;
*) ;;
esac

Expand Down
7 changes: 6 additions & 1 deletion bin/ham-install-os-packages
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi

# IMPORTANT: Update the tag date when you make any change to the list of
# packages installed. You can replace the date with the output of `arch_datez`
TAG="ham-install-os-packages-${HAM_OS}-v23_12_10"
TAG="ham-install-os-packages-${HAM_OS}-v24_04_01"
TAGFILE="$TEMPDIR/ham-install-os-packages-${HAM_OS}-tag.txt"

if [[ $(tagfile_status "$TAGFILE" "$TAG") == "up-to-date" ]]; then
Expand Down Expand Up @@ -37,6 +37,11 @@ case $HAM_OS in
;;
LINUX)
if [ "$(type apt-get 2>/dev/null | wc -l)" = 1 ]; then
echo "I/Installing Cosmo APE binary format handler"
(
set -ex
"$HAM_HOME/bin/cosmo-run" ape_install
)
echo "### Installing packages required by ham on Linux (apt-get) ###"
echo "I/Installing apt-get packages"
(
Expand Down
19 changes: 19 additions & 0 deletions rules/base-COSMOCC-rules.ham
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
actions together piecemeal Archive
{
$(AR) "$(<)" "$(>:T)"
}

actions DllLink bind NEEDLIBS
{
$(LINK) $(LINKFLAGS) $(LINKFLAGS_DLL) -fvisibility=hidden -shared -o "$(<)" $(UNDEFS) "$(>)" $(NEEDLIBS) $(LINKLIBS) $(SYSTEM_LINKLIBS)
}

actions Link bind NEEDLIBS
{
$(LINK) $(LINKFLAGS) $(LINKFLAGS_EXE) $(UNDEFS) "$(>)" $(NEEDLIBS) $(LINKLIBS) $(SYSTEM_LINKLIBS) -o "$(<)"
}

actions RunExe {
cd $(WORKDIR)
cosmo-run "./$(>)$(SUFEXE)" $(A0) $(A1) $(A2) $(A3) $(A4) $(A5) $(A6) $(A7) $(A8) $(A9)
}
24 changes: 24 additions & 0 deletions rules/base-COSMOCC.ham
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
COSMOCC = 1 ;
OSPLAT = COSMO ;

SLASH ?= / ;
SUFOBJ ?= .o ;
SUFLIB ?= .a ;
PREFIXDLL ?= ;
CHMOD ?= chmod ;
SUFEXE = .com ;
SUFDLL = .dll_not_supported ;

C++FLAGS ?= ;
CCFLAGS ?= ;

CC ?= cosmocc ;
C++ ?= cosmocc ;
LINK ?= cosmocc ;
AR ?= cosmoar ;

LINKFLAGS ?= "" ;
LINKLIBS ?= ;
OPTIM ?= "" ;
STDHDRS ?= ;
UNDEFFLAG ?= "-u _" ;
25 changes: 25 additions & 0 deletions rules/toolkit-base-cosmocc.ham
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#----------------------------------------------------------------------
# LOA
#----------------------------------------------------------------------
LOA_OS = cosmoc ;
LOA_LINKER = gcc ;
LOA_ARCH = unk ;

#----------------------------------------------------------------------
# DEFINES
#----------------------------------------------------------------------
DEFINES += niPosix COSMOCC=1 __COSMOCC__ _COMPILER_COSMOCC ;

#----------------------------------------------------------------------
# OS Variables
#----------------------------------------------------------------------
POSIX = 1 ;
EMBEDDED = 1 ;
NO_PCH = 1 ;

#----------------------------------------------------------------------
# TARGET FEATURES
#----------------------------------------------------------------------
TARGET_FEATURE_DLL = ; # DLL not supported
TARGET_FEATURE_EXE = 1 ;
TARGET_FEATURE_CONSOLE = 1 ;
87 changes: 87 additions & 0 deletions rules/toolkit-cpp-cosmocc.ham
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
STRICT_ALIASING_FLAGS = -fno-strict-aliasing ;

COSMOCC_CC_ARGS +=
-ffunction-sections
-fdata-sections
-fvisibility=hidden
-Wno-return-type-c-linkage
-Wno-switch
-Wno-#pragma-messages
-Wno-unused-value
-Wno-deprecated-declarations
-Wno-gnu-inline-cpp-without-extern
;
COSMOCC_CPP_ARGS +=
-std=$(C++VERSION)
-Werror=c++11-narrowing
;

LINKFLAGS +=
-fvisibility=hidden
-ffunction-sections
-fdata-sections
;

if $(FLYMAKE) = 1 {
# Happens when we're compiling header files with flymake since the temporary
# flymake file is a cpp file.
COSMOCC_CC_ARGS +=
-Wno-pragma-once-outside-header
;
}

CCFLAGS += $(COSMOCC_CC_ARGS) ;
C++FLAGS += $(COSMOCC_CC_ARGS) $(COSMOCC_CPP_ARGS) ;

if $(FLYMAKE) = 1 {
COSMOCC_DBG_ARGS = -O0 $(STRICT_ALIASING_FLAGS) ;
# COSMOCC_DBG_ARGS = -ggdb -O0 $(STRICT_ALIASING_FLAGS) ;
COSMOCC_OPT_ARGS = $(COSMOCC_DBG_ARGS) ;
}
else {
### "Debug" (da) build flags ###
COSMOCC_DBG_ARGS = -ggdb -O0 $(STRICT_ALIASING_FLAGS) ;
### Optimized (ra) build flags ###
COSMOCC_OPT_ARGS = -ggdb -O2 $(STRICT_ALIASING_FLAGS) ;
}

### Link flags ###
if $(COSMOCC_SANITIZE) = 1 {
LINKFLAGS += -fsanitize=address ;
}
LINKLIBS += ;

rule tkCC++Build
{
local t = $(<) ;
local strOpt = "" ;
# Set the debug infos generation
# Set the optimization flags
if $(DEBUG) = 1 {
PKGOPTIM += $(COSMOCC_DBG_ARGS) ;
strOpt += "(DebugOnly) " ;
}
# Set debug-only flags
else {
PKGOPTIM += $(COSMOCC_OPT_ARGS) ;
strOpt += "(Optimized) " ;
}
logVerbose "- CC++Build: " $(strOpt) ;
}

rule tkC++Exceptions {
ObjectC++Flags $(<) : -fexceptions ;
}
rule tkNoC++Exceptions {
ObjectC++Flags $(<) : -fno-exceptions ;
}

rule tkC++RTTI {
ObjectC++Flags $(<) : -frtti ;
}
rule tkNoC++RTTI {
ObjectC++Flags $(<) : -fno-rtti ;
}

rule tkCC++Lint {
}
29 changes: 29 additions & 0 deletions specs/toolsets/cosmocc/setup-toolset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# toolset
export HAM_TOOLSET=cosmocc
export HAM_TOOLSET_NAME=cosmocc
export HAM_TOOLSET_DIR="${HAM_HOME}/toolsets/cosmocc"

# path setup
export COSMOCC_DIR="${HAM_TOOLSET_DIR}/dist"
toolset_check_and_dl_ver cosmocc dist v3_3_3 || return 1

# path
pathenv_add "${COSMOCC_DIR}/bin"

# cpp compiler
export HAM_CPP_TOOLSET=COSMOCC
export HAM_CPP_TOOLSET_NAME=cosmocc

# version
VER="--- cosmocc -------------------------------"
if [ "$HAM_NO_VER_CHECK" != "1" ]; then
if ! VER="$VER
$(cosmocc --version | grep 'cosmocc ')"; then
echo "E/Can't cosmocc zig version."
return 1
fi
fi
export HAM_TOOLSET_VERSIONS="$HAM_TOOLSET_VERSIONS
$VER"
Loading