Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/blaze 1.5.0 #4

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .blaze/blaze.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
blaze.dependencies = [
"com.fizzed:blaze-ssh"
"com.fizzed:buildx:1.0.7"
"com.fizzed:jne:4.0.4"
]

java.source.version = 8
282 changes: 282 additions & 0 deletions .blaze/blaze.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
import com.fizzed.blaze.Contexts;
import com.fizzed.blaze.Task;
import com.fizzed.buildx.Buildx;
import com.fizzed.buildx.ContainerBuilder;
import com.fizzed.buildx.Target;
import com.fizzed.jne.NativeTarget;
import com.fizzed.jne.OperatingSystem;
import org.slf4j.Logger;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import static com.fizzed.blaze.Contexts.withBaseDir;
import static com.fizzed.blaze.Systems.*;
import static com.fizzed.blaze.util.Globber.globber;
import static java.util.Arrays.asList;

public class blaze {

private final Logger log = Contexts.logger();
private final Path projectDir = withBaseDir("../").toAbsolutePath();
private final NativeTarget localNativeTarget = NativeTarget.detect();
private final Path nativeDir = projectDir.resolve("native");
private final Path targetDir = projectDir.resolve("target");

@Task(order = 1)
public void build_natives() throws Exception {
final String targetStr = Contexts.config().value("target").orNull();
final NativeTarget nativeTarget = targetStr != null ? NativeTarget.fromJneTarget(targetStr) : NativeTarget.detect();

log.info("Building natives for target {}", nativeTarget.toJneTarget());

log.info("Copying native code to (cleaned) {} directory...", targetDir);
rm(targetDir).recursive().force().run();
mkdir(targetDir).parents().run();
cp(globber(nativeDir, "*")).target(targetDir).recursive().debug().run();

final String buildScript;
final String autoConfTarget;
if (nativeTarget.getOperatingSystem() == OperatingSystem.MACOS) {
buildScript = "setup/build-native-lib-macos-action.sh";
autoConfTarget = "";
} else if (nativeTarget.getOperatingSystem() == OperatingSystem.WINDOWS) {
buildScript = "setup/build-native-lib-windows-action.bat";
autoConfTarget = "";
} else {
buildScript = "setup/build-native-lib-linux-action.sh";
autoConfTarget = nativeTarget.toAutoConfTarget();
}

exec(buildScript, nativeTarget.toJneOsAbi(), nativeTarget.toJneArch(), autoConfTarget)
.workingDir(this.projectDir)
.verbose()
.run();
}

@Task(order = 2)
public void test() throws Exception {
exec("mvn", "clean", "test")
.workingDir(this.projectDir)
.verbose()
.run();
}

@Task(order = 3)
public void clean() throws Exception {
rm(this.targetDir)
.recursive()
.force()
.verbose()
.run();
}

private final List<Target> crossTargets = asList(

//
// Linux (18.04 supports libatomic, c++17)
//

new Target("linux", "x64", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux-x64"),

new Target("linux", "arm64", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux-arm64"),

new Target("linux", "armhf", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux-armhf"),

new Target("linux", "armel", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux-armel"),

new Target("linux", "riscv64", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux-riscv64"),

//
// Linux (w/ MUSL)
//

new Target("linux_musl", "x64", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux_musl-x64"),

new Target("linux_musl", "arm64", "x64 Ubuntu 18.04, JDK 11 cross compiler")
.setTags("build")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11-buildx-linux_musl-arm64"),

//
// FreeBSD (will not easily compile on freebsd)
//

/*new Target("freebsd", "x64")
.setTags("build", "test")
.setHost("bmh-build-x64-freebsd12-1"),

*new Target("freebsd", "arm64")
.setTags("build", "test")
.setHost("bmh-build-arm64-freebsd13-1"),*/

//
// OpenBSD (will not easily compile on openbsd)
//

/*new Target("openbsd", "x64")
.setTags("build", "test")
.setHost("bmh-build-x64-openbsd72-1"),

new Target("openbsd", "arm64")
.setTags("build", "test")
.setHost("bmh-build-arm64-openbsd72-1"),*/


//
// MacOS
//

new Target("macos", "x64", "MacOS 10.13")
.setTags("build", "test")
.setHost("bmh-build-x64-macos1013-1"),

new Target("macos", "arm64", "MacOS 12")
.setTags("build", "test")
.setHost("bmh-build-arm64-macos12-1"),

//
// Windows
//

new Target("windows", "x64", "Windows 11")
.setTags("build", "test")
.setHost("bmh-build-x64-win11-1"),

new Target("windows", "arm64", "Windows 11")
.setTags("build")
.setHost("bmh-build-x64-win11-1"),

//
// CI/Test Local Machine
//

new Target(localNativeTarget.toJneOsAbi(), localNativeTarget.toJneArch(), "local machine")
.setTags("test"),

//
// CI/Test Linux
//

new Target("linux", "x64", "Ubuntu 18.04, JDK 11")
.setTags("test")
.setContainerImage("fizzed/buildx:x64-ubuntu18-jdk11"),

new Target("linux", "x64", "Ubuntu 22.04, JDK 8")
.setTags("test")
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk8"),

new Target("linux", "x64", "Ubuntu 22.04, JDK 11")
.setTags("test")
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk11"),

new Target("linux", "x64", "Ubuntu 22.04, JDK 17")
.setTags("test")
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk17"),

new Target("linux", "x64", "Ubuntu 22.04, JDK 21")
.setTags("test")
.setContainerImage("fizzed/buildx:x64-ubuntu22-jdk21"),

new Target("linux", "arm64", "Ubuntu 18.04, JDK 11")
.setTags("test")
.setHost("bmh-hv-6")
.setContainerImage("fizzed/buildx:arm64-ubuntu18-jdk11"),

new Target("linux", "armhf", "Ubuntu 18.04, JDK 11")
.setTags("test")
.setHost("bmh-hv-6")
.setContainerImage("fizzed/buildx:armhf-ubuntu18-jdk11"),

new Target("linux", "armel", "Ubuntu 18.04, JDK 11")
.setTags("test")
.setHost("bmh-hv-6")
.setContainerImage("fizzed/buildx:armel-debian11-jdk11"),

new Target("linux", "riscv64", "Debian 11, JDK 21")
.setTags("test")
.setHost("bmh-build-riscv64-debian11-1"),

//
// CI/Test Linux w/ MUSL
//

new Target("linux_musl", "x64", "Alpine 3.11, JDK 11")
.setTags("test")
.setContainerImage("fizzed/buildx:x64-alpine3.11-jdk11"),

new Target("linux_musl", "arm64", "Alpine 3.11, JDK 11")
.setTags("test")
.setHost("bmh-hv-6")
.setContainerImage("fizzed/buildx:arm64-alpine3.11-jdk11"),

//
// CI/Test Windows
//

new Target("windows", "x64", "Windows 10")
.setTags("test")
.setHost("bmh-build-x64-win10-1"),

new Target("windows", "arm64", "Windows 11")
.setTags("test")
.setHost("bmh-build-arm64-win11-1")
);

@Task(order = 50)
public void cross_build_containers() throws Exception {
new Buildx(crossTargets)
.containersOnly()
.execute((target, project) -> {
/*
// no customization needed
Path installScript = Paths.get("setup/install-linux.sh");
if (target.getOs().equals("linux_musl")) {
installScript = Paths.get("setup/install-alpine.sh");
}*/

project.buildContainer(new ContainerBuilder()
//.setInstallScript(installScript)
);
});
}

@Task(order = 51)
public void cross_build_natives() throws Exception {
new Buildx(crossTargets)
.tags("build")
.execute((target, project) -> {
// delegate to blaze
project.action("java", "-jar", "blaze.jar", "build_natives", "--target", target.getOsArch())
.run();

// we know that the only modified file will be in the artifact dir
final String artifactRelPath = "tkrzw-" + target.getOsArch() + "/src/main/resources/jne/" + target.getOs() + "/" + target.getArch() + "/";
project.rsync(artifactRelPath, artifactRelPath)
.run();
});
}

@Task(order = 53)
public void cross_tests() throws Exception {
new Buildx(crossTargets)
.tags("test")
.execute((target, project) -> {
project.action("java", "-jar", "blaze.jar", "test")
.run();
});
}

}
79 changes: 79 additions & 0 deletions .blaze/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blaze</groupId>
<artifactId>tkrzw-blaze</artifactId>
<version>0.0.1</version>

<!--
THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND!

Edit or create a <blaze-script>.conf file, and re-run the generate-maven-project command.
-->

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<build>
<sourceDirectory>${project.basedir}</sourceDirectory>
</build>
<dependencies>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>blaze-ivy</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>blaze-core</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>blaze-ssh</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>buildx</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>jne</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>
</project>
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src
.buildx-cache
tkrzw-*
.blaze
native
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ target
nb-configuration.xml
*.idea
.temp-m2
.buildx
.buildx-cache
Binary file added blaze.jar
Binary file not shown.
Loading