forked from smithy-lang/smithy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
120 lines (103 loc) · 4.03 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
id "application"
id "org.beryx.runtime" version "1.12.7"
}
description = "This module implements the Smithy command line interface."
ext {
displayName = "Smithy :: CLI"
moduleName = "software.amazon.smithy.cli"
imageJreVersion = "17"
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)) {
if (Os.isArch("aarch64")) {
ext.set("imageOs", "osx-aarch_64")
} else if (Os.isArch("x86_64")) {
ext.set("imageOs", "osx-x86_64")
} else {
println("No JDK for ${System.getProperty("os.arch")}")
ext.set("imageOs", "")
}
} 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 {
implementation project(":smithy-model")
implementation project(":smithy-build")
implementation project(":smithy-linters")
implementation project(":smithy-diff")
}
application {
mainClass = "software.amazon.smithy.cli.SmithyCli"
applicationName = "smithy"
}
runtime {
addOptions("--compress", "0", "--strip-debug", "--no-header-files", "--no-man-pages")
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")
}
targetPlatform("osx-aarch_64") {
jdkHome = jdkDownload("${correttoRoot}-aarch64-macos-jdk.tar.gz")
}
targetPlatform("win64") {
jdkHome = jdkDownload("${correttoRoot}-x64-windows-jdk.zip")
}
}
// First, call validate with no args and create a class list to 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")
}
// 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")
}