Skip to content

Commit 9da6040

Browse files
committed
chore_: add mobile library build logic
- status-im/status-desktop#18377
1 parent 909987e commit 9da6040

File tree

3 files changed

+209
-7
lines changed

3 files changed

+209
-7
lines changed

Makefile

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: statusgo all test clean help
2-
.PHONY: statusgo-android statusgo-ios
2+
.PHONY: statusgo-android statusgo-ios statusgo-ios-library statusgo-android-library
33
.PHONY: build-libwaku test-libwaku clean-libwaku rebuild-libwaku
44

55
# Clear any GOROOT set outside of the Nix shell
@@ -40,6 +40,12 @@ else
4040
detected_OS := $(strip $(shell uname))
4141
endif
4242

43+
ifeq ($(ARCH),x86_64)
44+
MOBILE_GOARCH := amd64
45+
else
46+
MOBILE_GOARCH := $(ARCH)
47+
endif
48+
4349
ifeq ($(detected_OS),Darwin)
4450
GOBIN_SHARED_LIB_EXT := dylib
4551
LIBWAKU_EXT := so
@@ -211,11 +217,13 @@ statusgo-ios: ##@cross-compile Build status-go for iOS
211217
github.com/status-im/status-go/mobile
212218
@echo "iOS framework cross compilation done in build/bin/Statusgo.xcframework"
213219

214-
statusgo-library: generate
215-
statusgo-library: $(LIBWAKU) ##@cross-compile Build status-go as static library for current platform
220+
statusgo-c-bindings:
216221
## cmd/library/README.md explains the magic incantation behind this
217222
mkdir -p build/bin/statusgo-lib
218223
go run cmd/library/*.go > build/bin/statusgo-lib/main.go
224+
225+
statusgo-library: generate
226+
statusgo-library: statusgo-c-bindings $(LIBWAKU) ##@cross-compile Build status-go as static library for current platform
219227
@echo "Building static library..."
220228
go build \
221229
-tags '$(BUILD_TAGS)' \
@@ -229,10 +237,7 @@ statusgo-library: $(LIBWAKU) ##@cross-compile Build status-go as static library
229237
build-libwaku: $(LIBWAKU)
230238

231239
statusgo-shared-library: generate
232-
statusgo-shared-library: $(LIBWAKU) ##@cross-compile Build status-go as shared library for current platform
233-
## cmd/library/README.md explains the magic incantation behind this
234-
mkdir -p build/bin/statusgo-lib
235-
go run cmd/library/*.go > build/bin/statusgo-lib/main.go
240+
statusgo-shared-library: statusgo-c-bindings $(LIBWAKU) ##@cross-compile Build status-go as shared library for current platform
236241
@echo "Building shared library..."
237242
@echo "Tags: $(BUILD_TAGS)"
238243
$(GOBIN_SHARED_LIB_CFLAGS) $(GOBIN_SHARED_LIB_CGO_LDFLAGS) go build \
@@ -250,6 +255,27 @@ endif
250255
@echo "Shared library built:"
251256
@ls -la build/bin/libstatus.*
252257

258+
statusgo-android-library: ANDROID_NDK_ROOT ?= /opt/android-sdk/ndk/27.2.12479018 ANDROID_API ?= 28 HOST_OS ?= linux ARCH ?= arm64
259+
statusgo-android-library: CC ?= $(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(HOST_OS)-x86_64/bin/aarch64-linux-android$(ANDROID_API)-clang
260+
statusgo-android-library: GOFLAGS ?= "" CGO_CFLAGS ?= "-Os -flto" CGO_LDFLAGS ?= "-Os -flto" CGO_ENABLED ?= 1 GOOS ?= android GOARCH ?= $(MOBILE_GOARCH)
261+
statusgo-android-library: generate statusgo-c-bindings $(LIBWAKU) ##@cross-compile Build status-go as Android mobile library
262+
@echo "Building Android mobile library..."
263+
go build -buildmode=c-shared -tags 'gowaku_no_rln nowatchdog disable_torrent' \
264+
-ldflags="-checklinkname=0 -X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=true" \
265+
-o "build/bin/libstatus.so" ./build/bin/statusgo-lib
266+
@echo "Android library built"
267+
268+
statusgo-ios-library: IPHONE_SDK ?= iphoneos IOS_TARGET ?= 13.0 ARCH ?= arm64
269+
statusgo-ios-library: CC ?= $(shell xcrun --sdk $(IPHONE_SDK) --find clang)
270+
statusgo-ios-library: CGO_CFLAGS ?= -Os -flto -arch $(ARCH) -isysroot $(shell xcrun --sdk $(IPHONE_SDK) --show-sdk-path) -miphoneos-version-min=$(IOS_TARGET) -fembed-bitcode
271+
statusgo-ios-library: CGO_LDFLAGS ?= -Os -flto GOFLAGS ?= "" CGO_ENABLED ?= 1 GOOS ?= ios GOARCH ?= $(MOBILE_GOARCH)
272+
statusgo-ios-library: generate statusgo-c-bindings $(LIBWAKU) ##@cross-compile Build status-go as iOS mobile library
273+
@echo "Building iOS mobile library..."
274+
go build -buildmode=c-archive -tags 'gowaku_no_rln nowatchdog disable_torrent' \
275+
-ldflags="-checklinkname=0 -X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=true" \
276+
-o "build/bin/libstatus.a" ./build/bin/statusgo-lib
277+
@echo "iOS library built"
278+
253279
docker-image: SHELL := /bin/sh
254280
docker-image: BUILD_TARGET ?= cmd
255281
docker-image: ##@docker Build docker image (use DOCKER_IMAGE_NAME to set the image name)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env groovy
2+
3+
4+
pipeline {
5+
agent { label 'linux && x86_64 && nix-2.24' }
6+
7+
parameters {
8+
string(
9+
name: 'BRANCH',
10+
defaultValue: 'develop',
11+
description: 'Name of branch to build.'
12+
)
13+
booleanParam(
14+
name: 'RELEASE',
15+
defaultValue: false,
16+
description: 'Enable to create build for release.',
17+
)
18+
}
19+
20+
options {
21+
timestamps()
22+
ansiColor('xterm')
23+
/* Prevent Jenkins jobs from running forever */
24+
timeout(time: 10, unit: 'MINUTES')
25+
disableConcurrentBuilds()
26+
disableRestartFromStage()
27+
/* manage how many builds we keep */
28+
buildDiscarder(logRotator(
29+
numToKeepStr: '5',
30+
daysToKeepStr: '30',
31+
artifactNumToKeepStr: '1',
32+
))
33+
}
34+
35+
environment {
36+
PLATFORM = 'android'
37+
TMPDIR = "${WORKSPACE_TMP}"
38+
GOPATH = "${WORKSPACE_TMP}/go"
39+
GOCACHE = "${WORKSPACE_TMP}/gocache"
40+
PATH = "${PATH}:${GOPATH}/bin"
41+
REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go"
42+
VERSION = sh(script: "./_assets/scripts/version.sh", returnStdout: true)
43+
ARTIFACT = utils.pkgFilename(
44+
name: 'status-go',
45+
type: env.PLATFORM,
46+
version: env.VERSION,
47+
ext: 'so',
48+
)
49+
/* prevent sharing cache dir across different jobs */
50+
GO_GENERATE_FAST_DIR = "${env.WORKSPACE_TMP}/go-generate-fast"
51+
}
52+
53+
stages {
54+
stage('Setup') {
55+
steps { /* Go needs to find status-go in GOPATH. */
56+
sh "mkdir -p \$(dirname ${REPO_SRC})"
57+
sh "ln -s ${WORKSPACE} ${REPO_SRC}"
58+
}
59+
}
60+
61+
stage('Compile') {
62+
steps { script {
63+
nix.develop('make statusgo-android-library', pure: false)
64+
sh "mv build/bin/libstatus.so ${ARTIFACT}"
65+
} }
66+
}
67+
68+
stage('Archive') {
69+
steps { script {
70+
archiveArtifacts(ARTIFACT)
71+
} }
72+
}
73+
74+
stage('Upload') {
75+
steps { script {
76+
env.PKG_URL = s5cmd.upload(ARTIFACT)
77+
} }
78+
}
79+
} // stages
80+
post {
81+
success { script { github.notifyPR(true) } }
82+
failure { script { github.notifyPR(false) } }
83+
cleanup {
84+
cleanWs()
85+
dir("${env.WORKSPACE}@tmp") { deleteDir() }
86+
}
87+
} // post
88+
} // pipeline

_assets/ci/Jenkinsfile.ios-library

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env groovy
2+
3+
4+
pipeline {
5+
agent { label 'macos && aarch64 && xcode-16.2 && nix-2.24' }
6+
7+
parameters {
8+
string(
9+
name: 'BRANCH',
10+
defaultValue: 'develop',
11+
description: 'Name of branch to build.'
12+
)
13+
booleanParam(
14+
name: 'RELEASE',
15+
defaultValue: false,
16+
description: 'Enable to create build for release.',
17+
)
18+
}
19+
20+
options {
21+
timestamps()
22+
ansiColor('xterm')
23+
/* Prevent Jenkins jobs from running forever */
24+
timeout(time: 10, unit: 'MINUTES')
25+
disableConcurrentBuilds()
26+
disableRestartFromStage()
27+
/* manage how many builds we keep */
28+
buildDiscarder(logRotator(
29+
numToKeepStr: '5',
30+
daysToKeepStr: '30',
31+
artifactNumToKeepStr: '1',
32+
))
33+
}
34+
35+
environment {
36+
PLATFORM = 'ios'
37+
TMPDIR = "${WORKSPACE_TMP}"
38+
GOPATH = "${WORKSPACE_TMP}/go"
39+
GOCACHE = "${WORKSPACE_TMP}/gocache"
40+
PATH = "${PATH}:${GOPATH}/bin"
41+
REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go"
42+
VERSION = sh(script: "./_assets/scripts/version.sh", returnStdout: true)
43+
ARTIFACT = utils.pkgFilename(
44+
name: 'status-go',
45+
type: env.PLATFORM,
46+
version: env.VERSION,
47+
ext: 'a',
48+
)
49+
/* prevent sharing cache dir across different jobs */
50+
GO_GENERATE_FAST_DIR = "${env.WORKSPACE_TMP}/go-generate-fast"
51+
}
52+
53+
stages {
54+
stage('Prep') {
55+
steps { /* Go needs to find status-go in GOPATH. */
56+
sh "mkdir -p \$(dirname ${REPO_SRC})"
57+
sh "ln -s ${WORKSPACE} ${REPO_SRC}"
58+
}
59+
}
60+
61+
stage('Compile') {
62+
steps { script {
63+
nix.develop('make statusgo-ios-library', pure: false, sandbox: false)
64+
sh "mv build/bin/libstatus.a ${ARTIFACT}"
65+
} }
66+
}
67+
68+
stage('Archive') {
69+
steps { script {
70+
archiveArtifacts(ARTIFACT)
71+
} }
72+
}
73+
74+
stage('Upload') {
75+
steps { script {
76+
env.PKG_URL = s5cmd.upload(ARTIFACT)
77+
} }
78+
}
79+
} // stages
80+
post {
81+
success { script { github.notifyPR(true) } }
82+
failure { script { github.notifyPR(false) } }
83+
cleanup {
84+
cleanWs()
85+
dir("${env.WORKSPACE}@tmp") { deleteDir() }
86+
}
87+
} // post
88+
} // pipeline

0 commit comments

Comments
 (0)