From 96f16ba8fdcef9c9732ae7ddff2fcf0bdab7a947 Mon Sep 17 00:00:00 2001 From: Domas Kalinauskas Date: Sun, 7 Jan 2024 20:50:22 +0200 Subject: [PATCH 1/2] make_lib_rust - compile with -fPIC --- constantine.nimble | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index fd007509b..ddcc27bbb 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -228,12 +228,13 @@ proc genDynamicLib(outdir, nimcache: string) = else: compile "libconstantine.so" -proc genStaticLib(outdir, nimcache: string) = +proc genStaticLib(outdir, nimcache: string, extFlags = "") = proc compile(libName: string, flags = "") = echo &"Compiling static library: {outdir}/" & libName exec "nim c " & flags & + extFlags & releaseBuildOptions(bmStaticLib) & " --threads:on " & " --noMain --app:staticlib " & @@ -271,7 +272,8 @@ task make_lib, "Build Constantine library": task make_lib_rust, "Build Constantine library (use within a Rust build.rs script)": doAssert existsEnv"OUT_DIR", "Cargo needs to set the \"OUT_DIR\" environment variable" let rustOutDir = getEnv"OUT_DIR" - genStaticLib(rustOutDir, rustOutDir/"nimcache") + # Compile as position independent, since rust does the same by default + genStaticLib(rustOutDir, rustOutDir/"nimcache", "--passC:-fPIC") proc testLib(path, testName: string, useGMP: bool) = let dynlibName = if defined(windows): "constantine.dll" From ad8e2d9106066d2ebcea036d7258e7bfe1db621e Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Tue, 9 Jan 2024 08:45:52 +0100 Subject: [PATCH 2/2] -fPIC: Windows is fully position independent, some compiler may error on -fPIC --- constantine.nimble | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index ddcc27bbb..184102469 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -272,8 +272,10 @@ task make_lib, "Build Constantine library": task make_lib_rust, "Build Constantine library (use within a Rust build.rs script)": doAssert existsEnv"OUT_DIR", "Cargo needs to set the \"OUT_DIR\" environment variable" let rustOutDir = getEnv"OUT_DIR" - # Compile as position independent, since rust does the same by default - genStaticLib(rustOutDir, rustOutDir/"nimcache", "--passC:-fPIC") + # Compile as position independent, since rust does the same by default + let extflags = if defined(windows): "" # Windows is fully position independent, flag is a no-op or on error depending on compiler. + else: "--passC:-fPIC" + genStaticLib(rustOutDir, rustOutDir/"nimcache", extflags) proc testLib(path, testName: string, useGMP: bool) = let dynlibName = if defined(windows): "constantine.dll"