Skip to content

Commit bf5dab2

Browse files
authored
multiple platform (#1)
* multiple platform Co-authored-by: superbear <[email protected]>
1 parent fc9c424 commit bf5dab2

File tree

9 files changed

+66
-34
lines changed

9 files changed

+66
-34
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
matrix:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515
java: [8, 17-ea]
16-
go: ['1.15', '1.17', '1.19']
16+
go: ['1.16', '1.17', '1.19']
1717
# Run all tests even if one fails
1818
fail-fast: false
1919
name: Test with JDK ${{ matrix.java }}, Go ${{ matrix.go }}, ${{ matrix.os }}
@@ -40,28 +40,3 @@ jobs:
4040
- name: Test
4141
run: |
4242
make test
43-
44-
deploy:
45-
runs-on: ubuntu-latest
46-
steps:
47-
- name: Checkout
48-
uses: actions/checkout@v3
49-
50-
- name: Setup Go
51-
uses: actions/[email protected]
52-
with:
53-
go-version: 1.15
54-
55-
- name: Setup Java
56-
uses: actions/setup-java@v3
57-
with:
58-
distribution: 'temurin'
59-
java-version: 8
60-
cache: 'maven'
61-
62-
- name: Publish to GitHub Packages Apache Maven
63-
env:
64-
GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }}
65-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66-
run: |
67-
make deploy

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Go
17+
uses: actions/[email protected]
18+
with:
19+
go-version: 1.16
20+
21+
- name: Setup Java
22+
uses: actions/setup-java@v3
23+
with:
24+
distribution: 'temurin'
25+
java-version: 8
26+
cache: 'maven'
27+
28+
- name: Publish to GitHub Packages Apache Maven
29+
env:
30+
GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }}
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
make deploy

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
go/awesome.so
2-
go/awesome.h
3-
awesome.so
1+
go/libawesome.so
2+
go/libawesome.dylib
3+
go/awesome.dll
4+
go/*.h
5+
libawesome.*
46
target/*
57

68
.classpath

Makefile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
# init command params
22
GO := go
3+
OS_NAME := linux
4+
NATIVE_LIB := awesome.so
5+
6+
ifeq ($(OS),Windows_NT)
7+
OS_NAME = win32
8+
NATIVE_LIB = awesome.dll
9+
else
10+
UNAME_S := $(shell uname -s)
11+
ifeq ($(UNAME_S),Linux)
12+
OS_NAME = linux
13+
NATIVE_LIB = libawesome.so
14+
endif
15+
ifeq ($(UNAME_S),Darwin)
16+
OS_NAME = darwin
17+
NATIVE_LIB = libawesome.dylib
18+
endif
19+
endif
320

421
# env
522
export GO111MODULE := on
623

724
build-go: ## build go shared library
8-
cd go && $(GO) build -o awesome.so -buildmode=c-shared awesome.go
9-
cp go/awesome.so src/main/resources/
25+
cd go && $(GO) build -o $(NATIVE_LIB) -buildmode=c-shared awesome.go
26+
cp go/$(NATIVE_LIB) src/main/resources/$(OS_NAME)-x86-64
1027

1128
build: ## build jar
1229
make build-go
1330
mvn clean package assembly:single
1431

1532
deploy: ## deploy
16-
make build-go
33+
cd go && $(GO) build -o libawesome.so -buildmode=c-shared awesome.go
34+
cd go && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 $(GO) build -o libawesome.dylib -buildmode=c-shared awesome.go
35+
cd go && CGO_ENABLED=1 GOOS=windows GOARCH=amd64 $(GO) build -o libawesome.dll -buildmode=c-shared awesome.go
36+
cp go/libawesome.so src/main/resources/linux-x86-64/
37+
cp go/libawesome.dylib src/main/resources/darwin-x86-64/
38+
cp go/awesome.dll src/main/resources/win32-x86-64/
1739
mvn deploy
1840

1941
test: ## test

go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/superbear/java-call-go/go
22

3-
go 1.15
3+
go 1.16

src/main/java/go/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Client {
1111

1212
static {
1313
try {
14-
File file = Native.extractFromResourcePath("/awesome.so", Client.class.getClassLoader());
14+
File file = Native.extractFromResourcePath("awesome", Client.class.getClassLoader());
1515
Awesome lib = Native.load(file.getAbsolutePath(), Awesome.class);
1616
handle = (Awesome)Native.synchronizedLibrary(lib);
1717
} catch (Exception e) {

src/main/resources/darwin-x86-64/.gitkeep

Whitespace-only changes.

src/main/resources/linux-x86-64/.gitkeep

Whitespace-only changes.

src/main/resources/win32-x86-64/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)