diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a1159a..a8af399 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] java: [8, 17-ea] - go: ['1.15', '1.17', '1.19'] + go: ['1.16', '1.17', '1.19'] # Run all tests even if one fails fail-fast: false name: Test with JDK ${{ matrix.java }}, Go ${{ matrix.go }}, ${{ matrix.os }} @@ -40,28 +40,3 @@ jobs: - name: Test run: | make test - - deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Go - uses: actions/setup-go@v3.3.0 - with: - go-version: 1.15 - - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 8 - cache: 'maven' - - - name: Publish to GitHub Packages Apache Maven - env: - GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - make deploy diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f6a644d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3.3.0 + with: + go-version: 1.16 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 8 + cache: 'maven' + + - name: Publish to GitHub Packages Apache Maven + env: + GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + make deploy diff --git a/.gitignore b/.gitignore index 597e5d3..aa4a4ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -go/awesome.so -go/awesome.h -awesome.so +go/libawesome.so +go/libawesome.dylib +go/awesome.dll +go/*.h +libawesome.* target/* .classpath diff --git a/Makefile b/Makefile index 3989124..02fca4f 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,41 @@ # init command params GO := go +OS_NAME := linux +NATIVE_LIB := awesome.so + +ifeq ($(OS),Windows_NT) + OS_NAME = win32 + NATIVE_LIB = awesome.dll +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + OS_NAME = linux + NATIVE_LIB = libawesome.so + endif + ifeq ($(UNAME_S),Darwin) + OS_NAME = darwin + NATIVE_LIB = libawesome.dylib + endif +endif # env export GO111MODULE := on build-go: ## build go shared library - cd go && $(GO) build -o awesome.so -buildmode=c-shared awesome.go - cp go/awesome.so src/main/resources/ + cd go && $(GO) build -o $(NATIVE_LIB) -buildmode=c-shared awesome.go + cp go/$(NATIVE_LIB) src/main/resources/$(OS_NAME)-x86-64 build: ## build jar make build-go mvn clean package assembly:single deploy: ## deploy - make build-go + cd go && $(GO) build -o libawesome.so -buildmode=c-shared awesome.go + cd go && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 $(GO) build -o libawesome.dylib -buildmode=c-shared awesome.go + cd go && CGO_ENABLED=1 GOOS=windows GOARCH=amd64 $(GO) build -o libawesome.dll -buildmode=c-shared awesome.go + cp go/libawesome.so src/main/resources/linux-x86-64/ + cp go/libawesome.dylib src/main/resources/darwin-x86-64/ + cp go/awesome.dll src/main/resources/win32-x86-64/ mvn deploy test: ## test diff --git a/go/go.mod b/go/go.mod index fdf9ad8..11652be 100644 --- a/go/go.mod +++ b/go/go.mod @@ -1,3 +1,3 @@ module github.com/superbear/java-call-go/go -go 1.15 \ No newline at end of file +go 1.16 \ No newline at end of file diff --git a/src/main/java/go/Client.java b/src/main/java/go/Client.java index dfa7df8..5aa9ffa 100644 --- a/src/main/java/go/Client.java +++ b/src/main/java/go/Client.java @@ -11,7 +11,7 @@ public class Client { static { try { - File file = Native.extractFromResourcePath("/awesome.so", Client.class.getClassLoader()); + File file = Native.extractFromResourcePath("awesome", Client.class.getClassLoader()); Awesome lib = Native.load(file.getAbsolutePath(), Awesome.class); handle = (Awesome)Native.synchronizedLibrary(lib); } catch (Exception e) { diff --git a/src/main/resources/darwin-x86-64/.gitkeep b/src/main/resources/darwin-x86-64/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/linux-x86-64/.gitkeep b/src/main/resources/linux-x86-64/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/win32-x86-64/.gitkeep b/src/main/resources/win32-x86-64/.gitkeep new file mode 100644 index 0000000..e69de29