Skip to content

Commit

Permalink
NVGT now creates universal MacOS binaries!
Browse files Browse the repository at this point in the history
Co-Authored-By: Patrick <65868806+braillescreen@users.noreply.github.com>
  • Loading branch information
samtupy and braillescreen committed Oct 5, 2024
1 parent a1a4d48 commit fa1627e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 13 deletions.
4 changes: 2 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ else:
env.Append(CXXFLAGS = ["-fms-extensions", "-std=c++20", "-fpermissive", "-O2", "-Wno-narrowing", "-Wno-int-to-pointer-cast", "-Wno-delete-incomplete", "-Wno-unused-result"], LIBS = ["m"])
if env["PLATFORM"] == "darwin":
# homebrew paths and other libraries/flags for MacOS
env.Append(CPPPATH = ["/opt/homebrew/include"], CCFLAGS = ["-mmacosx-version-min=14.0"], LIBPATH = ["/opt/homebrew/lib"])
env.Append(CCFLAGS = ["-mmacosx-version-min=14.0", "-arch", "arm64", "-arch", "x86_64"], LINKFLAGS = ["-arch", "arm64", "-arch", "x86_64"])
# The following, to say the least, is absolutely not ideal. In some cases we have both static and dynamic libraries on the system and must explicitly choose the static one. The normal :libname.a trick doesn't seem to work on clang, we're just informed that libs couldn't be found. If anybody knows a better way to force static library linkage on MacOS particularly without the absolute paths, please let me know!
env.Append(LIBS = [File("/usr/local/lib/libangelscript.a"), File("/usr/local/lib/libenet.a"), File("/usr/local/lib/libSDL3.a"), File("/opt/homebrew/lib/libcrypto.a"), File("/opt/homebrew/lib/libssl.a"), "iconv"])
env.Append(LIBS = [File("/usr/local/lib/libangelscript.a"), File("/usr/local/lib/libenet.a"), File("/usr/local/lib/libSDL3.a"), File("/usr/local/lib/libcrypto.a"), File("/usr/local/lib/libssl.a"), "iconv"])
elif env["PLATFORM"] == "posix":
# enable the gold linker to silence seemingly pointless warnings about symbols in the bass libraries, strip the resulting binaries, and add /usr/local/lib to the libpath because it seems we aren't finding libraries unless we do manually.
env.Append(CPPPATH = ["/usr/local/include"], LIBPATH = ["/usr/local/lib"], LINKFLAGS = ["-fuse-ld=gold", "-g" if ARGUMENTS.get("debug", 0) == "1" else "-s"])
Expand Down
64 changes: 58 additions & 6 deletions build/build_macos.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,64 @@
#!/bin/zsh

function setup_homebrew {
brew install autoconf automake libtool openssl libgit2 bullet upx libplist
brew install autoconf automake libtool upx
}

function setup_openssl {
echo Installing OpenSSL...
curl -s -O -L https://github.com/openssl/openssl/releases/download/openssl-3.3.2/openssl-3.3.2.tar.gz
tar -xzf openssl-3.3.2.tar.gz
mv openssl-3.3.2 openssl-3.3.2-arm||true
tar -xzf openssl-3.3.2.tar.gz
mv openssl-3.3.2 openssl-3.3.2-x64||true
cd openssl-3.3.2-arm
./Configure enable-rc5 zlib darwin64-arm64-cc no-asm no-apps no-docs no-filenames no-shared --release
make -j$(nsysctl -n hw.ncpu)
sudo make install
cd ../openssl-3.3.2-x64
./Configure darwin64-x86_64-cc no-apps no-docs no-filenames --release
make -j$(nsysctl -n hw.ncpu)
cd ..
mkdir -p openssl-fat
lipo -create openssl-3.3.2-arm/libcrypto.a openssl-3.3.2-x64/libcrypto.a -output openssl-fat/libcrypto.a
lipo -create openssl-3.3.2-arm/libssl.a openssl-3.3.2-x64/libssl.a -output openssl-fat/libssl.a
sudo cp openssl-fat/*.a /usr/local/lib
rm openssl-3.3.2.tar.gz
echo OpenSSL installed.
}

function setup_angelscript {
echo Installing Angelscript...
git clone --depth 1 https://github.com/codecat/angelscript-mirror||true
git clone https://github.com/codecat/angelscript-mirror||true
cd "angelscript-mirror/sdk/angelscript/projects/cmake"
git checkout 270b98a332faa57a747c9265086c7bce49c041d9
mkdir -p build
cd build
cmake ..
cmake .. -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build .
sudo cmake --install .
cd ../../../../../..
echo Angelscript installed.
}

function setup_bullet {
echo Installing bullet3...
git clone --depth 1 https://github.com/bulletphysics/bullet3||true
cd bullet3
mkdir build_cmake
cd build_cmake
cmake -S.. -B. -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_UNIT_TESTS=OFF -DBUILD_CPU_DEMOS=OFF -DBUILD_ENET=OFF -DBUILD_CLSOCKET=OFF -DBUILD_EGL=OFF -DBUILD_OPENGL3_DEMOS=OFF -DBUILD_BULLET2_DEMOS=OFF -DBUILD_EXTRAS=OFF -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build .
sudo cmake --install .
cd ../..
}

function setup_enet {
echo Installing enet...
git clone --depth 1 https://github.com/lsalzman/enet||true
cd enet
autoreconf -vfi
./configure
./configure CC="clang -arch x86_64 -arch arm64" CXX="clang++ -arch x86_64 -arch arm64" CPP="clang -E" CXXCPP="clang++ -E"
make -j$(nsysctl -n hw.ncpu)
sudo make install
cd ..
Expand All @@ -35,13 +71,26 @@ function setup_libgit2 {
cd libgit2-1.8.1
mkdir -p build
cd build
cmake .. -DBUILD_TESTS=OFF -DUSE_ICONV=OFF -DBUILD_CLI=OFF -DCMAKE_BUILD_TYPE=Release
cmake .. -DBUILD_TESTS=OFF -DUSE_ICONV=OFF -DBUILD_CLI=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build .
sudo cmake --install .
cd ../..
rm v1.8.1.tar.gz
}

function setup_libplist {
echo Installing libplist...
curl -s -O -L https://github.com/libimobiledevice/libplist/releases/download/2.6.0/libplist-2.6.0.tar.bz2
tar -xf libplist-2.6.0.tar.bz2
cd libplist-2.6.0
./configure --without-cython CC="clang -arch x86_64 -arch arm64" CXX="clang++ -arch x86_64 -arch arm64" CPP="clang -E" CXXCPP="clang++ -E"
make
sudo make install
cd ..
rm libplist-2.6.0.tar.bz2
echo libplist installed.
}

function setup_poco {
curl -s -O https://pocoproject.org/releases/poco-1.13.3/poco-1.13.3-all.tar.gz
tar -xzf poco-1.13.3-all.tar.gz
Expand Down Expand Up @@ -99,11 +148,14 @@ function main {
mkdir -p deps
cd deps
setup_homebrew
setup_openssl
setup_angelscript
setup_bullet
setup_enet
#setup_libgit2
setup_libgit2
setup_poco
setup_sdl
setup_libplist
setup_nvgt
echo Success!
exit 0
Expand Down
2 changes: 1 addition & 1 deletion plugin/git/_SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if ARGUMENTS.get("no_shared_plugins", "0") == "0":
static = env.Object("git_static", "git.cpp", CPPDEFINES = [("NVGT_PLUGIN_STATIC", "git2nvgt")])
static = env.StaticLibrary("#build/lib/git2nvgt", [static])
if env["PLATFORM"] == "darwin":
nvgt_env.Append(LINKFLAGS = ["-weak_library", "/opt/homebrew/lib/libgit2.dylib"])
nvgt_env.Append(LINKFLAGS = ["-weak_library", "/usr/local/lib/libgit2.dylib"])
else:
static = [static, "git2"]
Return("static")
2 changes: 1 addition & 1 deletion src/bundling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class nvgt_compilation_output_mac : public nvgt_compilation_output_impl {
string sout, serr;
File dmg_out = Path(final_output_path).makeFile().setExtension("dmg").toString();
if (dmg_out.exists()) dmg_out.remove(true);
if (!system_command("hdiutil", {"create", "-srcfolder", bundle_mode < 3? workplace.path() : Path(workplace.Path()).makeParent().toString(), "-volname", Path(workplace.path()).makeFile.getBaseName(), dmg_out.path()}, sout, serr)) throw Exception(format("Unable to execute hdiutil for .dmg generation: %s", serr));
if (!system_command("hdiutil", {"create", "-srcfolder", bundle_mode < 3? workplace.path() : Path(workplace.path()).makeParent().toString(), "-volname", Path(workplace.path()).makeFile().getBaseName(), dmg_out.path()}, sout, serr)) throw Exception(format("Unable to execute hdiutil for .dmg generation: %s", serr));
output_path = dmg_out.path();
#else
File zip_out = Path(final_output_path).makeFile().setExtension("app.zip").toString();
Expand Down
2 changes: 1 addition & 1 deletion src/tts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class tts_voice {
blastspeak* inst;
#elif defined(__APPLE__)
AVTTSVoice* inst;
#elifdef __ANDROID__
#elif defined(__ANDROID__)
jclass TTSClass;
jmethodID constructor, midIsActive, midIsSpeaking, midSpeak, midSilence, midGetVoice, midSetRate, midSetPitch, midSetPan, midSetVolume, midGetVoices, midSetVoice, midGetMaxSpeechInputLength, midGetPitch, midGetPan, midGetRate, midGetVolume;
JNIEnv* env;
Expand Down
4 changes: 2 additions & 2 deletions test/case/calendar.nvgt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
void mod_calendar(calendar@ c, int seconds) {
c += timespan(seconds, 0);
c += timespan(0, 0, 0, seconds, 0);
}

void test_calendar() {
Expand All @@ -8,7 +8,7 @@ void test_calendar() {
int m = c.minute;
mod_calendar(c, 120);
calendar c2;
assert(m + 2 == c.minute or c.minute < 2);
assert(m + 2 == c.minute or c.minute < 2, "m=" + m + ", c.minute=" + c.minute);
assert (c2 < c);
c.set(2020, 1, 1, 0, 0, 0);
assert (c.year == 2020 and c.hour == 0);
Expand Down

0 comments on commit fa1627e

Please sign in to comment.