|
| 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 | +} |
0 commit comments