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

Setup cross platform builds of the CLI #832

Merged
merged 2 commits into from
Jun 14, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Java ${{ matrix.java }} ${{ matrix.os }}
strategy:
matrix:
java: [8, 11, 15]
java: [8, 11, 16]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
Expand Down
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM gradle:5.4.1-jdk12
USER root
ADD ./ /smithy
FROM amazonlinux:2
ADD smithy-cli/build/image/smithy-cli-linux-x86_64 /smithy
WORKDIR /smithy
RUN gradle :smithy-cli:runtime
WORKDIR /work

ENTRYPOINT [ "/smithy/smithy-cli/build/image/bin/smithy" ]
# Build application class data sharing archive using smithy validate as the baseline.
RUN SMITHY_OPTS="-XX:DumpLoadedClassList=/smithy/lib/smithy.lst" \
/smithy/bin/smithy validate
RUN SMITHY_OPTS="-Xshare:dump -XX:SharedArchiveFile=/smithy/lib/smithy.jsa -XX:SharedClassListFile=/smithy/lib/smithy.lst" \
/smithy/bin/smithy validate

ENTRYPOINT [ "/smithy/bin/smithy" ]
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ plugins {
id "signing"
id "checkstyle"
id "jacoco"
id "com.github.spotbugs" version "4.6.0"
id "io.codearte.nexus-staging" version "0.21.0"
id "me.champeau.jmh" version "0.6.4"
id "com.github.spotbugs" version "4.7.1"
id "io.codearte.nexus-staging" version "0.30.0"
id "me.champeau.jmh" version "0.6.5"
}

ext {
Expand Down
6 changes: 4 additions & 2 deletions docs/source/implementations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ Build tooling

.. code-block:: none

cd smithy-cli/build/runtime/bin
./smithy-cli --help
smithy-cli/build/image/smithy-cli-osx-x86_64/bin/smithy --help
smithy-cli/build/image/smithy-cli-win64/bin/smithy --help
smithy-cli/build/image/smithy-cli-linux-x86_64/bin/smithy --help
smithy-cli/build/image/smithy-cli-linux-aarch_64/bin/smithy --help


---------------
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
71 changes: 65 additions & 6 deletions smithy-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,40 @@
* permissions and limitations under the License.
*/

import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id "application"
id "org.beryx.runtime" version "1.8.4"
id "org.beryx.runtime" version "1.12.5"
}

description = "This module implements the Smithy command line interface."

ext {
displayName = "Smithy :: CLI"
moduleName = "software.amazon.smithy.cli"
imageJreVersion = "16"
correttoRoot = "https://corretto.aws/downloads/latest/amazon-corretto-${imageJreVersion}"
}

// Detect which OS and arch is running to create an application class data sharing
// archive for the current platform.
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ext.set("imageOs", "win64")
} else if (Os.isFamily(Os.FAMILY_MAC)) {
ext.set("imageOs", "osx-x86_64")
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
if (Os.isArch("aarch")) {
ext.set("imageOs", "linux-aarch_64")
} else if (Os.isArch("x86_64")) {
ext.set("imageOs", "linux-x86_64")
} else {
println("No JDK for ${System.getProperty("os.arch")}")
ext.set("imageOs", "")
}
} else {
println("Unknown OS and arch: ${System.getProperty("os.name")}")
ext.set("imageOs", "")
}

dependencies {
Expand All @@ -35,16 +59,51 @@ dependencies {
application {
mainClass = "software.amazon.smithy.cli.SmithyCli"
applicationName = "smithy"
applicationDefaultJvmArgs = ["-Xshare:auto"]
}

runtime {
addOptions("--compress", "0", "--strip-debug", "--no-header-files", "--no-man-pages")
addModules("java.logging")
addModules("java.logging", "java.xml")

launcher {
jvmArgs = [
'-Xshare:auto',
'-XX:SharedArchiveFile={{BIN_DIR}}/../lib/smithy.jsa'
]
}

targetPlatform("linux-x86_64") {
jdkHome = jdkDownload("${correttoRoot}-x64-linux-jdk.tar.gz")
}

targetPlatform("linux-aarch_64") {
jdkHome = jdkDownload("${correttoRoot}-aarch64-linux-jdk.tar.gz")
}

targetPlatform("osx-x86_64") {
jdkHome = jdkDownload("${correttoRoot}-x64-macos-jdk.tar.gz")
JordonPhillips marked this conversation as resolved.
Show resolved Hide resolved
}

targetPlatform("win64") {
jdkHome = jdkDownload("${correttoRoot}-x64-windows-jdk.zip")
}
}

tasks.register("optimizeCli", Exec) {
commandLine("${project.buildDir}/image/bin/java", "-Xshare:dump")
// First, call validate with no args and create a class list to use use application class data sharing.
tasks.register("createClassList", Exec) {
environment("SMITHY_OPTS", "-XX:DumpLoadedClassList=${project.buildDir}/image/smithy-cli-${imageOs}/lib/smithy.lst")
commandLine("${project.buildDir}/image/smithy-cli-${imageOs}/bin/smithy", "validate")
}

tasks["runtime"].finalizedBy("optimizeCli")
// Next, actually dump out the archive of the collected classes. This is platform specific,
// so it can only be done for the current OS+architecture.
tasks.register("dumpArchive", Exec) {
environment("SMITHY_OPTS", "-Xshare:dump -XX:SharedArchiveFile=${project.buildDir}/image/smithy-cli-${imageOs}/lib/smithy.jsa -XX:SharedClassListFile=${project.buildDir}/image/smithy-cli-${imageOs}/lib/smithy.lst")
commandLine("${project.buildDir}/image/smithy-cli-${imageOs}/bin/smithy", "validate")
}

// Can't do CDS if the OS and architecture is not one of our targets.
if (!imageOs.isEmpty()) {
tasks["dumpArchive"].dependsOn("createClassList")
tasks["runtime"].finalizedBy("dumpArchive")
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void getsAsBoolean() {

@Test
public void getsAsBoxedBoolean() {
LiteralExpression node = new LiteralExpression(new Boolean(true));
LiteralExpression node = new LiteralExpression(true);

node.expectBooleanValue();
assertThat(node.isBooleanValue(), is(true));
Expand Down