diff --git a/Makefile b/Makefile index 4487f0a..b797d07 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file +endif + +# Target iOS + +libsds-ios: | deps + $(ENV_SCRIPT) nim libsdsIOS $(NIM_PARAMS) sds.nims + diff --git a/sds.nimble b/sds.nimble index 3e70507..c4b47f1 100644 --- a/sds.nimble +++ b/sds.nimble @@ -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")