Skip to content

Commit

Permalink
build(libcore): use Makefile to build core
Browse files Browse the repository at this point in the history
Now you can build with `debug` tag. (Although sing-box pprof should be enabled by options)
  • Loading branch information
xchacha20-poly1305 committed Dec 1, 2024
1 parent ac1e2ae commit cace12e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Native Build
if: steps.cache.outputs.cache-hit != 'true'
run: |
./run lib core
make libcore
- name: Upload libcore
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Native Build
if: steps.cache.outputs.cache-hit != 'true'
run: |
./run lib core
make libcore
- name: Upload libcore
uses: actions/upload-artifact@v4
with:
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.PHONY: update libcore apk apk_debug assets lint_go test_go plugin generate_option
LIBCORE_DIR := ./libcore/

.PHONY: libcore libcore_debug apk apk_debug assets lint_go test_go plugin generate_option

build: libcore assets apk

libcore:
./run lib core
$(MAKE) -C $(LIBCORE_DIR) all

libcore_debug:
$(MAKE) -C $(LIBCORE_DIR) debug

apk:
BUILD_PLUGIN=none ./gradlew app:assembleFossRelease
Expand All @@ -12,8 +19,6 @@ apk_debug:
assets:
./run lib assets

build: libcore assets apk

update:
./run lib update

Expand Down
4 changes: 0 additions & 4 deletions buildScript/lib/core.sh

This file was deleted.

8 changes: 0 additions & 8 deletions buildScript/lib/core/build.sh

This file was deleted.

8 changes: 0 additions & 8 deletions buildScript/lib/core/init.sh

This file was deleted.

37 changes: 37 additions & 0 deletions libcore/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
NDK_ENV := ../buildScript/init/env_ndk.sh
BOX_VERSION = $(shell go run ./cmd/boxversion/)
LIB_DIR = $(shell realpath ../app/libs)
TAGS := with_conntrack,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,with_ech

# -buildvcs require: https://github.com/SagerNet/gomobile/commit/6bc27c2027e816ac1779bf80058b1a7710dad260
# CGO_FLAGS require Go 1.23: https://go.dev/doc/go1.23#cgo
# max-page-size: https://developer.android.com/guide/practices/page-sizes
CGO_LDFLAGS := -Wl,-z,max-page-size=16384
LDFLAGS := -X github.com/sagernet/sing-box/constant.Version=$(BOX_VERSION) -s -w -buildid=
ANDROID_API := 21
INIT_DONE := inited

.PHONY: all build copy

all: $(INIT_DONE) build copy

build:
. $(NDK_ENV) && \
export CGO_LDFLAGS="$(CGO_LDFLAGS)" && export CGO_ENABLED=1 && export GO386=softfloat && \
gomobile bind -v -androidapi $(ANDROID_API) -trimpath -buildvcs=false -ldflags="$(LDFLAGS)" -tags="$(TAGS)" .


$(INIT_DONE):
CGO_ENABLED=0 go install -v -trimpath -ldflags="-w -s" github.com/sagernet/gomobile/cmd/[email protected]
CGO_ENABLED=0 go install -v -trimpath -ldflags="-w -s" github.com/sagernet/gomobile/cmd/[email protected]
gomobile init
touch $(INIT_DONE)

debug:
$(MAKE) TAGS="$(TAGS),debug" all

copy:
@rm -f libcore-sources.jar
@cp -f libcore.aar $(LIB_DIR)
echo ">> install $(realpath $(LIB_DIR))/libcore.aar"
sha256sum libcore.aar
35 changes: 0 additions & 35 deletions libcore/build.sh

This file was deleted.

11 changes: 0 additions & 11 deletions libcore/init.sh

This file was deleted.

0 comments on commit cace12e

Please sign in to comment.