Skip to content

Commit 395edc7

Browse files
committed
Major overhaul of how native targets are calculated and used with new NativeTarget class
1 parent c5bdcd2 commit 395edc7

File tree

12 files changed

+655
-60
lines changed

12 files changed

+655
-60
lines changed

.blaze/blaze.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
blaze.dependencies = [
2+
"com.fizzed:blaze-ssh:1.1.0"
3+
"com.fizzed:buildx:0.0.3-SNAPSHOT"
4+
"com.fizzed:jne:3.3.1-SNAPSHOT"
5+
]
6+
7+
container-prefix = jne

.blaze/blaze.java

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
import com.fizzed.blaze.Task;
2+
import com.fizzed.jne.NativeTarget;
3+
4+
import java.util.List;
5+
import static java.util.Arrays.asList;
6+
import java.nio.file.Path;
7+
8+
import static com.fizzed.blaze.Contexts.withBaseDir;
9+
import static com.fizzed.blaze.Systems.exec;
10+
import static com.fizzed.blaze.SecureShells.sshConnect;
11+
import static com.fizzed.blaze.SecureShells.sshExec;
12+
import com.fizzed.buildx.*;
13+
14+
public class blaze {
15+
16+
private final Path projectDir = withBaseDir("../").toAbsolutePath();
17+
private final NativeTarget localNativeTarget = NativeTarget.detect();
18+
19+
@Task(order = 2)
20+
public void test() throws Exception {
21+
/*exec("env")
22+
.workingDir(projectDir)
23+
.run();*/
24+
exec("mvn", "test")
25+
.workingDir(projectDir)
26+
.run();
27+
}
28+
29+
private final List<Target> targets = asList(
30+
//
31+
// Linux
32+
//
33+
34+
new Target("linux", "x64", "ubuntu16.04, jdk11")
35+
.setTags("build")
36+
.setContainerImage("fizzed/buildx:x64-ubuntu16-jdk11-buildx-linux-x64"),
37+
38+
new Target("linux", "arm64", "ubuntu16.04, jdk11")
39+
.setTags("build")
40+
.setContainerImage("fizzed/buildx:x64-ubuntu16-jdk11-buildx-linux-arm64"),
41+
42+
/*new Target("linux", "armhf")
43+
.setTags("build")
44+
.setContainerImage("fizzed/buildx:amd64-ubuntu16-jdk11-cross-build"),
45+
46+
new Target("linux", "armel")
47+
.setTags("build")
48+
.setContainerImage("fizzed/buildx:amd64-ubuntu16-jdk11-cross-build"),
49+
50+
// NOTE: ubuntu18 added support for riscv64
51+
new Target("linux", "riscv64")
52+
.setTags("build")
53+
.setContainerImage("fizzed/buildx:amd64-ubuntu18-jdk11-cross-build"),*/
54+
55+
//
56+
// Linux (w/ MUSL)
57+
//
58+
59+
new Target("linux_musl", "x64", "ubuntu16.04, jdk11")
60+
.setTags("build")
61+
.setContainerImage("fizzed/buildx:x64-ubuntu16-jdk11-buildx-linux_musl-x64"),
62+
63+
new Target("linux_musl", "arm64", "ubuntu16.04, jdk11")
64+
.setTags("build")
65+
.setContainerImage("fizzed/buildx:x64-ubuntu16-jdk11-buildx-linux_musl-arm64"),
66+
67+
//
68+
// FreeBSD
69+
//
70+
71+
/*new Target("freebsd", "x64")
72+
.setTags("build", "test")
73+
.setHost("bmh-build-x64-freebsd12-1"),
74+
75+
new Target("freebsd", "arm64")
76+
.setTags("build", "test")
77+
.setHost("bmh-build-arm64-freebsd13-1"),*/
78+
79+
//
80+
// OpenBSD
81+
//
82+
83+
/*new Target("openbsd", "x64")
84+
.setTags("build", "test")
85+
.setHost("bmh-build-x64-openbsd67-1"),
86+
87+
new Target("openbsd", "arm64")
88+
.setTags("build", "test")
89+
.setHost("bmh-build-arm64-openbsd72-1"),*/
90+
91+
//
92+
// MacOS
93+
//
94+
95+
/*new Target("macos", "x64")
96+
.setTags("build", "test")
97+
.setHost("bmh-build-x64-macos1013-1"),
98+
99+
new Target("macos", "arm64")
100+
.setTags("build", "test")
101+
.setHost("bmh-build-arm64-macos12-1"),*/
102+
103+
//
104+
// Windows
105+
//
106+
107+
/*new Target("windows", "x64")
108+
.setTags("build", "test")
109+
.setHost("bmh-build-x64-win11-1"),
110+
111+
new Target("windows", "arm64")
112+
.setTags("build")
113+
.setHost("bmh-build-x64-win11-1"),*/
114+
115+
//
116+
// test-only containers
117+
//
118+
119+
new Target(localNativeTarget.toJneOsAbi(), localNativeTarget.toJneArch(), "local machine")
120+
.setTags("test"),
121+
122+
new Target("linux", "x64", "ubuntu16.04, jdk11")
123+
.setTags("test")
124+
.setContainerImage("fizzed/buildx:x64-ubuntu16-jdk11"),
125+
126+
new Target("linux", "x64", "ubuntu22.04, jdk8")
127+
.setTags("test")
128+
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk8"),
129+
130+
new Target("linux", "x64", "ubuntu22.04, jdk11")
131+
.setTags("test")
132+
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk11"),
133+
134+
new Target("linux", "x64", "ubuntu22.04, jdk17")
135+
.setTags("test")
136+
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk17"),
137+
138+
new Target("linux", "x64", "ubuntu22.04, jdk21")
139+
.setTags("test")
140+
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk21"),
141+
142+
/*new Target("linux", "arm64")
143+
.setTags("test")
144+
.setHost("bmh-build-arm64-ubuntu22-1"),*/
145+
146+
new Target("linux", "arm64", "ubuntu16.04, jdk11")
147+
.setTags("test")
148+
.setContainerImage("fizzed/buildx:arm64-ubuntu16-jdk11"),
149+
150+
151+
new Target("windows", "x64", "win10")
152+
.setTags("test")
153+
.setHost("bmh-build-x64-win10-1"),
154+
155+
156+
new Target("linux_musl", "x64", "alpine3.11, jdk11")
157+
.setTags("test")
158+
.setContainerImage("fizzed/buildx:x64-alpine3.11-jdk11"),
159+
160+
new Target("linux_musl", "arm64", "alpine3.11, jdk11")
161+
.setTags("test")
162+
// faster to run on an arm64 box?
163+
//.setHost("bmh-build-arm64-ubuntu22-1")
164+
.setContainerImage("fizzed/buildx:arm64v8-alpine3.11-jdk11")
165+
166+
/*
167+
168+
169+
170+
new Target("windows", "arm64-test", "win11")
171+
.setTags("test")
172+
.setHost("bmh-build-arm64-win11-1")*/
173+
174+
/*
175+
new Target("linux", "armhf-test")
176+
.setTags("test")
177+
.setContainerImage("fizzed/buildx:arm32v7-ubuntu18-jdk11"),
178+
179+
new Target("linux", "armel-test")
180+
.setTags("test")
181+
.setContainerImage("fizzed/buildx:arm32v5-debian11-jdk11"),
182+
183+
new Target("linux", "armel-test")
184+
.setTags("test")
185+
.setContainerImage("fizzed/buildx:arm32v5-debian11-jdk11"),
186+
187+
new Target("linux", "riscv64-test")
188+
.setTags("test")
189+
.setContainerImage("fizzed/buildx:riscv64-ubuntu20-jdk19"),
190+
191+
192+
193+
new Target("windows", "x64-test", "win10")
194+
.setTags("test")
195+
.setHost("bmh-build-x64-win10-1"),
196+
197+
new Target("windows", "x64-test", "win7")
198+
.setTags("test")
199+
.setHost("bmh-build-x64-win7-1"),
200+
*/
201+
);
202+
203+
@Task(order = 50)
204+
public void cross_build_containers() throws Exception {
205+
final String user = System.getenv("USER");
206+
final String userId = exec("id", "-u", user).runCaptureOutput().toString();
207+
new Buildx(targets)
208+
.onlyWithContainers()
209+
.execute((target, project) -> {
210+
String dockerFile = "setup/Dockerfile.linux";
211+
if (target.getContainerImage().contains("alpine")) {
212+
dockerFile = "setup/Dockerfile.linux_musl";
213+
}
214+
215+
project.exec("docker", "build",
216+
"-f", dockerFile,
217+
"--build-arg", "FROM_IMAGE="+target.getContainerImage(),
218+
"--build-arg", "USERID="+userId,
219+
"--build-arg", "USERNAME="+user,
220+
"-t", project.getContainerName(),
221+
"setup")
222+
.run();
223+
});
224+
}
225+
226+
@Task(order = 51)
227+
public void cross_build_natives() throws Exception {
228+
new Buildx(targets)
229+
.setTags("build")
230+
.execute((target, project) -> {
231+
String buildScript = "setup/build-native-lib-linux-action.sh";
232+
if (target.getOs().equals("macos")) {
233+
buildScript = "setup/build-native-lib-macos-action.sh";
234+
} else if (target.getOs().equals("windows")) {
235+
buildScript = "setup/build-native-lib-windows-action.bat";
236+
}
237+
238+
project.action(buildScript, target.getOs(), target.getArch()).run();
239+
240+
// we know that the only modified file will be in the artifact dir
241+
final String artifactRelPath = "src/test/resources/jne/" + target.getOs() + "/" + target.getArch() + "/";
242+
project.rsync(artifactRelPath, artifactRelPath).run();
243+
});
244+
}
245+
246+
@Task(order = 53)
247+
public void cross_tests() throws Exception {
248+
new Buildx(targets)
249+
.setTags("test")
250+
.execute((target, project) -> {
251+
project.action("java", "-jar", "blaze.jar", "test")
252+
.run();
253+
});
254+
}
255+
256+
}

.blaze/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>blaze</groupId>
8+
<artifactId>jne-blaze</artifactId>
9+
<name>jne-blaze</name>
10+
<version>0.0.1</version>
11+
12+
<properties>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<maven.compiler.source>1.8</maven.compiler.source>
15+
</properties>
16+
17+
<build>
18+
<sourceDirectory>${project.basedir}</sourceDirectory>
19+
</build>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.fizzed</groupId>
24+
<artifactId>blaze-lite</artifactId>
25+
<version>1.1.0</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.fizzed</groupId>
29+
<artifactId>blaze-ssh</artifactId>
30+
<version>1.1.0</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.fizzed</groupId>
34+
<artifactId>buildx</artifactId>
35+
<version>0.0.3-SNAPSHOT</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.fizzed</groupId>
39+
<artifactId>jne</artifactId>
40+
<version>3.3.1-SNAPSHOT</version>
41+
</dependency>
42+
</dependencies>
43+
44+
</project>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.iml
44
native/libhelloj/helloj/HelloLib.class
55
.temp-m2
6+
.buildx

blaze.jar

1.92 MB
Binary file not shown.

setup/build-native-lib-linux-action.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/sh -l
22
set -e
33

44
BASEDIR=$(dirname "$0")
@@ -9,11 +9,13 @@ BUILDOS=$1
99
BUILDARCH=$2
1010

1111
# Setup cross compile environment
12-
if [ -f /opt/setup-cross-build-environment.sh ]; then
13-
. /opt/setup-cross-build-environment.sh $BUILDOS $BUILDARCH
14-
fi
12+
#if [ -f /opt/setup-cross-build-environment.sh ]; then
13+
# . /opt/setup-cross-build-environment.sh $BUILDOS $BUILDARCH
14+
#fi
1515

16-
. setup/setup-environment.sh
16+
#. setup/setup-environment.sh
17+
18+
#env
1719

1820
mkdir -p target
1921
rsync -avrt --delete ./native/ ./target/
@@ -28,5 +30,6 @@ make
2830

2931
cd ..
3032
OUTPUT_DIR="../src/test/resources/jne/${BUILDOS}/${BUILDARCH}"
33+
mkdir -p "$OUTPUT_DIR"
3134
cp jcat/jcat "$OUTPUT_DIR"
3235
cp libhelloj/libhelloj.so "$OUTPUT_DIR"

src/main/java/com/fizzed/jne/ABI.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ public enum ABI {
3030
MUSL,
3131
MSVC;
3232

33+
static public ABI resolve(String value) {
34+
for (ABI abi : ABI.values()) {
35+
if (abi.name().equalsIgnoreCase(value)) {
36+
return abi;
37+
}
38+
}
39+
return null;
40+
}
41+
3342
}

0 commit comments

Comments
 (0)