Skip to content

Commit 884ce6f

Browse files
authored
fix(ios): localize Nim runtime symbols in libsds static library (#84)
* fix(ios): localize Nim runtime symbols in libsds static library Replace libtool -exported_symbols_list (ignored for static archives on current Xcode, with a silent fallback to unlocalized objects) with ld -r -exported_symbol '_Sds*', so libsds.a no longer exports global Nim runtime symbols that collide with libnim_status_client.
1 parent b12f5ee commit 884ce6f

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

sds.nimble

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ proc buildMobileIOS(srcDir = ".", sdkPath = "") =
153153
quit "Error: Xcode/iOS SDK not found"
154154

155155
let aFile = outDir & "/libsds.a"
156-
let aFileTmp = outDir & "/libsds_tmp.a"
157156
let cpu = getMyCpu()
158157
let clangArch = if cpu == "amd64": "x86_64" else: cpu
159158

@@ -186,17 +185,17 @@ proc buildMobileIOS(srcDir = ".", sdkPath = "") =
186185
exec "clang " & clangFlags & " -c " & cFile & " -o " & oFile
187186
objectFiles.add(oFile)
188187

189-
# 3) Create static library from all object files
190-
exec "ar rcs " & aFileTmp & " " & objectFiles.join(" ")
191-
192-
# 4) Use libtool to localize all non-public symbols
193-
# Keep only Sds* functions as global, hide everything else to prevent conflicts
194-
# with nim runtime symbols from libnim_status_client
195-
let keepSymbols =
196-
"_Sds*:_libsdsNimMain:_libsdsDatInit*:_libsdsInit*:_NimMainModule__libsds*"
197-
exec "xcrun libtool -static -o " & aFile & " " & aFileTmp &
198-
" -exported_symbols_list /dev/stdin <<< '" & keepSymbols & "' 2>/dev/null || cp " &
199-
aFileTmp & " " & aFile
188+
# 3) Merge into one object exporting only the _Sds* API, so libsds's Nim runtime
189+
# can't clash with other static Nim libs (e.g. libnim_status_client).
190+
# (libtool -static ignores -exported_symbols_list on current Xcode; ld -r works.
191+
# Objects go through a response file: too many long paths for one command line.)
192+
let objListFile = outDir & "/objects.txt"
193+
writeFile(objListFile, objectFiles.join("\n"))
194+
let mergedObj = outDir & "/libsds_merged.o"
195+
exec "xcrun ld -r -arch " & clangArch & " -exported_symbol '_Sds*' -o " & mergedObj &
196+
" -filelist " & objListFile
197+
exec "ar rcs " & aFile & " " & mergedObj
198+
exec "rm -f " & mergedObj & " " & objListFile
200199

201200
echo "✔ iOS library created: " & aFile
202201

0 commit comments

Comments
 (0)