From 35c5a33b4fa1953795b41625f916f02e075dfb5b Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 17 Nov 2025 14:26:17 +0100 Subject: [PATCH] Adds nimleopard_portable_build nimflag to disable native arch in cmake build --- leopard/wrapper.nim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/leopard/wrapper.nim b/leopard/wrapper.nim index 258b255..cb58911 100644 --- a/leopard/wrapper.nim +++ b/leopard/wrapper.nim @@ -100,7 +100,33 @@ const LeopardExtraLinkerFlags {.strdefine.} = "" +proc overrideCMakeMarch() = + # vendor/leopard/CMakeLists.txt defined "-march=native" explicitly + # it provides no means to override this. + # Because of this, when we build binaries intended to be delivered + # they may contain instructions available on the build system that are + # not necessarily available on the user system. + # To be able to build portable binaries, we have no choice but + # to modify the CMakeLists.txt + when defined(nimleopard_portable_build): + if defined(windows) or defined(unix): + let + cmakeFile = joinPath(LeopardDir, "CMakeLists.txt") + searchTarget = " -march=native" + replaceTarget = " -march=x86-64-v3" + + echo "Applying portable-build override on CMakeLists.txt..." + + try: + let replaced = readFile(cmakeFile).replace(searchTarget, replaceTarget) + + writeFile(cmakeFile, replaced) + except IOError as err: + raiseAssert("Failed to modify CMakeLists.txt for portable build: " & err.msg) + + static: + overrideCMakeMarch() if defined(windows): func pathUnix2Win(path: string): string = gorge("cygpath -w " & path.strip).strip