mirror of
https://github.com/logos-messaging/nim-sds.git
synced 2026-01-03 22:53:12 +00:00
Merge pull request #24 from waku-org/add-android-support
Add android support
This commit is contained in:
commit
1b005ee9ab
91
Makefile
91
Makefile
@ -61,4 +61,93 @@ else
|
||||
echo -e $(BUILD_MSG) "build/$@.so" && \
|
||||
$(ENV_SCRIPT) nim libsdsDynamic $(NIM_PARAMS) sds.nims
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
#####################
|
||||
## Mobile Bindings ##
|
||||
#####################
|
||||
.PHONY: libsds-android \
|
||||
libsds-android-precheck \
|
||||
libsds-android-arm64 \
|
||||
libsds-android-amd64 \
|
||||
libsds-android-x86 \
|
||||
libsds-android-arm \
|
||||
build-libsds-for-android-arch
|
||||
|
||||
ANDROID_TARGET ?= 30
|
||||
ifeq ($(detected_OS),Darwin)
|
||||
ANDROID_TOOLCHAIN_DIR := $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/darwin-x86_64
|
||||
else
|
||||
ANDROID_TOOLCHAIN_DIR := $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/linux-x86_64
|
||||
endif
|
||||
|
||||
libsds-android-precheck:
|
||||
ifndef ANDROID_NDK_HOME
|
||||
$(error ANDROID_NDK_HOME is not set)
|
||||
endif
|
||||
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passC="--sysroot=$(ANDROID_TOOLCHAIN_DIR)/sysroot"
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passL="--sysroot=$(ANDROID_TOOLCHAIN_DIR)/sysroot"
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passC="--target=$(ANDROID_ARCH)$(ANDROID_TARGET)"
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passL="--target=$(ANDROID_ARCH)$(ANDROID_TARGET)"
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passC="-I$(ANDROID_TOOLCHAIN_DIR)/sysroot/usr/include"
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passC="-I$(ANDROID_TOOLCHAIN_DIR)/sysroot/usr/include/$(ARCH_DIRNAME)"
|
||||
build-libsds-for-android-arch: NIM_PARAMS := $(NIM_PARAMS) --passL="-L$(ANDROID_TOOLCHAIN_DIR)/sysroot/usr/lib/$(ARCH_DIRNAME)/$(ANDROID_TARGET)"
|
||||
build-libsds-for-android-arch:
|
||||
CPU=$(CPU) ABIDIR=$(ABIDIR) \
|
||||
ARCH_DIRNAME=$(ARCH_DIRNAME) \
|
||||
ANDROID_ARCH=$(ANDROID_ARCH) \
|
||||
ANDROID_COMPILER=$(ANDROID_COMPILER) \
|
||||
ANDROID_TOOLCHAIN_DIR=$(ANDROID_TOOLCHAIN_DIR) $(ENV_SCRIPT) \
|
||||
nim libsdsAndroid $(NIM_PARAMS) sds.nims
|
||||
|
||||
libsds-android-arm64: ANDROID_ARCH=aarch64-linux-android
|
||||
libsds-android-arm64: CPU=arm64
|
||||
libsds-android-arm64: ABIDIR=arm64-v8a
|
||||
libsds-android-arm64: ARCH_DIRNAME=aarch64-linux-android
|
||||
libsds-android-arm64: | libsds-android-precheck build deps
|
||||
$(MAKE) build-libsds-for-android-arch ANDROID_ARCH=$(ANDROID_ARCH) CROSS_TARGET=$(ANDROID_ARCH) \
|
||||
CPU=$(CPU) ABIDIR=$(ABIDIR) ARCH_DIRNAME=$(ARCH_DIRNAME) ANDROID_COMPILER=$(ANDROID_ARCH)$(ANDROID_TARGET)-clang
|
||||
|
||||
libsds-android-amd64: ANDROID_ARCH=x86_64-linux-android
|
||||
libsds-android-amd64: CPU=amd64
|
||||
libsds-android-amd64: ABIDIR=x86_64
|
||||
libsds-android-amd64: ARCH_DIRNAME=x86_64-linux-android
|
||||
libsds-android-amd64: | libsds-android-precheck build deps
|
||||
$(MAKE) build-libsds-for-android-arch ANDROID_ARCH=$(ANDROID_ARCH) CROSS_TARGET=$(ANDROID_ARCH) \
|
||||
CPU=$(CPU) ABIDIR=$(ABIDIR) ARCH_DIRNAME=$(ARCH_DIRNAME) ANDROID_COMPILER=$(ANDROID_ARCH)$(ANDROID_TARGET)-clang
|
||||
|
||||
libsds-android-x86: ANDROID_ARCH=i686-linux-android
|
||||
libsds-android-x86: CPU=i386
|
||||
libsds-android-x86: ABIDIR=x86
|
||||
libsds-android-x86: ARCH_DIRNAME=i686-linux-android
|
||||
libsds-android-x86: | libsds-android-precheck build deps
|
||||
$(MAKE) build-libsds-for-android-arch ANDROID_ARCH=$(ANDROID_ARCH) CROSS_TARGET=$(ANDROID_ARCH) \
|
||||
CPU=$(CPU) ABIDIR=$(ABIDIR) ARCH_DIRNAME=$(ARCH_DIRNAME) ANDROID_COMPILER=$(ANDROID_ARCH)$(ANDROID_TARGET)-clang
|
||||
|
||||
libsds-android-arm: ANDROID_ARCH=armv7a-linux-androideabi
|
||||
libsds-android-arm: CPU=arm
|
||||
libsds-android-arm: ABIDIR=armeabi-v7a
|
||||
libsds-android-arm: ARCH_DIRNAME=arm-linux-androideabi
|
||||
libsds-android-arm: | libsds-android-precheck build deps
|
||||
# cross-rs target architecture name does not match the one used in android
|
||||
$(MAKE) build-libsds-for-android-arch ANDROID_ARCH=$(ANDROID_ARCH) \
|
||||
CROSS_TARGET=armv7-linux-androideabi CPU=$(CPU) ABIDIR=$(ABIDIR) ARCH_DIRNAME=$(ARCH_DIRNAME) \
|
||||
ANDROID_COMPILER=$(ANDROID_ARCH)$(ANDROID_TARGET)-clang
|
||||
|
||||
libsds-android:
|
||||
ifeq ($(ARCH),arm64)
|
||||
$(MAKE) libsds-android-arm64
|
||||
else ifeq ($(ARCH),amd64)
|
||||
$(MAKE) libsds-android-amd64
|
||||
else ifeq ($(ARCH),x86)
|
||||
$(MAKE) libsds-android-x86
|
||||
# else ifeq ($(ARCH),arm)
|
||||
# $(MAKE) libsds-android-arm
|
||||
# This target is disabled because on recent versions of cross-rs complain with the following error
|
||||
# relocation R_ARM_THM_ALU_PREL_11_0 cannot be used against symbol 'stack_init_trampoline_return'; recompile with -fPIC
|
||||
# It's likely this architecture is not used so we might just not support it.
|
||||
else
|
||||
$(error Unsupported ARCH '$(ARCH)'. Please set ARCH to one of: arm64, arm, amd64, x86)
|
||||
endif
|
||||
|
||||
|
||||
27
sds.nimble
27
sds.nimble
@ -20,11 +20,11 @@ proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") =
|
||||
extra_params &= " " & paramStr(i)
|
||||
if `type` == "static":
|
||||
exec "nim c" & " --out:build/" & name &
|
||||
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --undef:metrics --nimMainPrefix:libsds --skipParentCfg:on " &
|
||||
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --nimMainPrefix:libsds --skipParentCfg:on " &
|
||||
extra_params & " " & srcDir & name & ".nim"
|
||||
else:
|
||||
exec "nim c" & " --out:build/" & name &
|
||||
".so --threads:on --app:lib --opt:size --noMain --mm:refc --header --undef:metrics --nimMainPrefix:libsds --skipParentCfg:on " &
|
||||
".so --threads:on --app:lib --opt:size --noMain --mm:refc --header --nimMainPrefix:libsds --skipParentCfg:on " &
|
||||
extra_params & " " & srcDir & name & ".nim"
|
||||
|
||||
# Tasks
|
||||
@ -44,3 +44,26 @@ task libsdsDynamic, "Generate bindings":
|
||||
--warning:UnusedImport:on \
|
||||
-d:chronicles_log_level=TRACE """,
|
||||
"dynamic"
|
||||
|
||||
### Mobile Android
|
||||
proc buildMobileAndroid(srcDir = ".", params = "") =
|
||||
let cpu = getEnv("CPU")
|
||||
|
||||
let outDir = "build/"
|
||||
if not dirExists outDir:
|
||||
mkDir outDir
|
||||
|
||||
var extra_params = params
|
||||
for i in 2 ..< paramCount():
|
||||
extra_params &= " " & paramStr(i)
|
||||
|
||||
exec "nim c" & " --out:" & outDir &
|
||||
"/libsds.so --threads:on --app:lib --opt:size --noMain --mm:refc --nimMainPrefix:libsds " &
|
||||
"-d:chronicles_sinks=textlines[dynamic] --header --passL:-L" & outdir &
|
||||
" --passL:-llog --cpu:" & cpu & " --os:android -d:androidNDK " & extra_params & " " &
|
||||
srcDir & "/libsds.nim"
|
||||
|
||||
task libsdsAndroid, "Build the mobile bindings for Android":
|
||||
let srcDir = "./library"
|
||||
let extraParams = "-d:chronicles_log_level=ERROR"
|
||||
buildMobileAndroid srcDir, extraParams
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user