From 406647ff2cfdb8a6efb778a47689afccf62478c2 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Thu, 16 May 2024 13:42:47 +0100 Subject: [PATCH] [make] Generate haxelib binary with `nekotools boot -c` on Mac/Linux (#11653) * [make] Generate haxelib binary with `nekotools boot -c` on Mac/Linux `nekotools boot` is a bit of a hack and some tools that deal with executables on linux can strip away the haxelib bytecode if it is done this way. `nekotools boot -c` will generate a .c file which can then be compiled manually. * [make] Fix for unix platforms if PLATFORM is defined * [make] Set the HAXE_STD_PATH while building haxelib Otherwise it doesn't work if haxe isn't already installed, or it might use the wrong version of the standard library * [ci] Install missing neko headers during setup They are now needed for compiling haxelib * [ci] Ensure /usr/local/include exists before installing neko * [ci] Install neko headers for earthly builds as well * [make] Omit HAXE_STD_PATH when building haxelib on windows For some reason this environment variable isn't working here on Windows * [ci] Continue building x64 haxelib on mac arm64 for now We don't have neko binaries for mac arm64 yet `nekotools boot run.n` was previously also producing an x64 binary * [make] Set rpath on mac when building haxelib It looks like /usr/local/lib is no longer used as a default path in some cases. * [make] Set std path for haxelib build on windows --- .github/workflows/main.yml | 12 +++++++++++- Earthfile | 1 + Makefile | 20 +++++++++++++++++--- Makefile.win | 7 +++++++ extra/github-actions/build-mac.yml | 2 +- extra/github-actions/install-neko-unix.yml | 2 ++ 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 79b8b50ab79..f5b78342357 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -283,9 +283,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -398,9 +400,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -474,9 +478,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -610,9 +616,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -670,7 +678,7 @@ jobs: set -ex eval $(opam env) opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/lib/libz.a /usr/local/lib/libpcre2-8.a /usr/local/lib/libmbedtls.a /usr/local/lib/libmbedcrypto.a /usr/local/lib/libmbedx509.a -cclib '-framework Security -framework CoreFoundation'" haxe - opam config exec -- make -s haxelib + opam config exec -- arch -x86_64 make -s haxelib make -s package_unix package_installer_mac ls -l out otool -L ./haxe @@ -949,9 +957,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV diff --git a/Earthfile b/Earthfile index dda473f6c60..af649bf118c 100644 --- a/Earthfile +++ b/Earthfile @@ -146,6 +146,7 @@ INSTALL_NEKO: ARG PREFIX=/usr/local RUN bash -c "ln -s \"$NEKOPATH\"/{neko,nekoc,nekoml,nekotools} \"$PREFIX/bin/\"" RUN bash -c "ln -s \"$NEKOPATH\"/libneko.* \"$PREFIX/lib/\"" + RUN bash -c "ln -s \"$NEKOPATH\"/*.h \"$PREFIX/include/\"" RUN mkdir -p "$PREFIX/lib/neko/" RUN bash -c "ln -s \"$NEKOPATH\"/*.ndll \"$PREFIX/lib/neko/\"" RUN ldconfig diff --git a/Makefile b/Makefile index a3b86a753a9..0588e7c5eb1 100644 --- a/Makefile +++ b/Makefile @@ -104,10 +104,24 @@ copy_haxetoolkit: /cygdrive/c/HaxeToolkit/haxe/haxe.exe cp $< $@ endif +ifeq ($(SYSTEM_NAME),Mac) +# This assumes that haxelib and neko will both be installed into INSTALL_DIR, +# which is the case when installing using the mac installer package +HAXELIB_LFLAGS= -Wl,-rpath,$(INSTALL_DIR)/lib +endif + +haxelib_unix: + cd $(CURDIR)/extra/haxelib_src && \ + HAXE_STD_PATH=$(CURDIR)/std $(CURDIR)/$(HAXE_OUTPUT) client.hxml && \ + nekotools boot -c run.n + $(CC) $(CURDIR)/extra/haxelib_src/run.c -o $(HAXELIB_OUTPUT) -lneko $(HAXELIB_LFLAGS) + # haxelib should depends on haxe, but we don't want to do that... -haxelib: - (cd $(CURDIR)/extra/haxelib_src && $(CURDIR)/$(HAXE_OUTPUT) client.hxml && nekotools boot run.n) - mv extra/haxelib_src/run$(EXTENSION) $(HAXELIB_OUTPUT) +ifeq ($(SYSTEM_NAME),Windows) +haxelib: haxelib_$(PLATFORM) +else +haxelib: haxelib_unix +endif tools: haxelib diff --git a/Makefile.win b/Makefile.win index 95500b63536..fdb34b4342b 100644 --- a/Makefile.win +++ b/Makefile.win @@ -53,6 +53,13 @@ PACKAGE_FILES=$(HAXE_OUTPUT) $(HAXELIB_OUTPUT) std \ "$$(cygcheck $(CURDIR)/$(HAXE_OUTPUT) | grep libmbedtls.dll | sed -e 's/^\s*//')" \ "$$(cygcheck $(CURDIR)/$(HAXE_OUTPUT) | grep libmbedx509.dll | sed -e 's/^\s*//')" +# haxelib should depends on haxe, but we don't want to do that... +haxelib_win: + cd $(CURDIR)/extra/haxelib_src && \ + HAXE_STD_PATH=$$(cygpath -m $(CURDIR)/std) $(CURDIR)/$(HAXE_OUTPUT) client.hxml && \ + nekotools boot run.n + mv extra/haxelib_src/run$(EXTENSION) $(HAXELIB_OUTPUT) + echo_package_files: echo $(PACKAGE_FILES) diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index 65dcc41b4d8..01de55b7171 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -49,7 +49,7 @@ set -ex eval $(opam env) opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/lib/libz.a /usr/local/lib/libpcre2-8.a /usr/local/lib/libmbedtls.a /usr/local/lib/libmbedcrypto.a /usr/local/lib/libmbedx509.a -cclib '-framework Security -framework CoreFoundation'" haxe - opam config exec -- make -s haxelib + opam config exec -- arch -x86_64 make -s haxelib make -s package_unix package_installer_mac ls -l out otool -L ./haxe diff --git a/extra/github-actions/install-neko-unix.yml b/extra/github-actions/install-neko-unix.yml index ab8eb43b2d9..5946d3c7fc0 100644 --- a/extra/github-actions/install-neko-unix.yml +++ b/extra/github-actions/install-neko-unix.yml @@ -6,9 +6,11 @@ tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV