From 89d32a9a974eb21ebe04420ed1ed09eb94ebe80b Mon Sep 17 00:00:00 2001 From: Domas Kalinauskas Date: Tue, 9 Jan 2024 10:56:12 +0200 Subject: [PATCH] make_lib_rust - use position independent code (#334) * make_lib_rust - compile with -fPIC * -fPIC: Windows is fully position independent, some compiler may error on -fPIC --------- Co-authored-by: Mamy Ratsimbazafy --- constantine.nimble | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index fd007509..18410246 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,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" - genStaticLib(rustOutDir, rustOutDir/"nimcache") + # 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"