adapt Makefile and sds.nimble to support iOS target

This commit is contained in:
Ivan Folgueira Bande 2025-11-27 23:01:39 +01:00
parent b643126011
commit b4cb634a51
No known key found for this signature in database
GPG Key ID: 3C117481F89E24A7
2 changed files with 50 additions and 1 deletions

View File

@ -73,6 +73,7 @@ ifeq ($(detected_OS),Windows)
BUILD_COMMAND := $(BUILD_COMMAND)Windows
else ifeq ($(detected_OS),Darwin)
BUILD_COMMAND := $(BUILD_COMMAND)Mac
export IOS_SDK_PATH := $(shell xcrun --sdk iphoneos --show-sdk-path)
else ifeq ($(detected_OS),Linux)
BUILD_COMMAND := $(BUILD_COMMAND)Linux
endif
@ -170,4 +171,10 @@ else
$(error Unsupported ARCH '$(ARCH)'. Please set ARCH to one of: arm64, arm, amd64, x86)
endif
endif
endif
# Target iOS
libsds-ios: | deps
$(ENV_SCRIPT) nim libsdsIOS $(NIM_PARAMS) sds.nims

View File

@ -91,6 +91,48 @@ task libsdsStaticMac, "Generate bindings":
"""-d:chronicles_line_numbers --warning:Deprecated:off --warning:UnusedImport:on -d:chronicles_log_level=TRACE """,
"static"
# Build Mobile iOS
proc buildMobileIOS(srcDir = ".", sdkPath = "") =
echo "Building iOS libsds library"
let outDir = "build"
if not dirExists outDir:
mkDir outDir
if sdkPath.len == 0:
quit "Error: Xcode/iOS SDK not found"
# The output static library
let cFile = outDir & "/nimcache/@mlibsds.nim.c"
let oFile = outDir & "/libsds.o"
let aFile = outDir & "/libsds.a"
# 1) Generate C sources from Nim (no linking)
exec "nim c" &
" --nimcache:build/nimcache --os:ios --cpu:arm64" &
" --compileOnly:on" &
" --noMain --mm:refc" &
" --threads:on --opt:size --header" &
" --nimMainPrefix:libsds --skipParentCfg:on" &
" --cc:clang" &
" --out:" & cFile & " " &
srcDir & "/libsds.nim"
exec "clang -arch arm64" &
" -isysroot " & sdkPath &
" -I./vendor/nimbus-build-system/vendor/Nim/lib/" &
" -fembed-bitcode -c " & cFile &
" -o " & oFile
exec "ar rcs " & aFile & " " & oFile
echo "✔ iOS library created: " & aFile
task libsdsIOS, "Build the mobile bindings for iOS":
let srcDir = "./library"
let sdkPath = getEnv("IOS_SDK_PATH")
buildMobileIOS srcDir, sdkPath
### Mobile Android
proc buildMobileAndroid(srcDir = ".", params = "") =
let cpu = getEnv("CPU")