-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.gradle
195 lines (175 loc) · 8.78 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/
apply plugin: "com.diffplug.spotless"
spotless {
format 'rust', {
// Files to apply the 'rust' format scheme to
target 'src/**/*.rs'
targetExclude('src/core_api/generated/**/*.rs')
// Steps to apply to the files
var firstNoneHeaderLineRegex = '^.[^*].*$' // Is at least 2 characters, the second of which is not a *
licenseHeaderFile("${project.rootDir}/licence-header.txt", firstNoneHeaderLineRegex)
}
format 'misc', {
// Files to apply the `misc` format scheme to
target '*.gradle', '*.md', '.gitignore'
// Steps to apply to the files
trimTrailingWhitespace()
indentWithSpaces() // Takes an integer argument if you don't like 4
endWithNewline()
}
}
task runUnitTests(type: Exec) {
commandLine 'cargo', 'test'
}
spotlessRustApply.dependsOn("runRustFormat")
spotlessRustApply.dependsOn("runRustClippy")
task runRustFormat(type: Exec) {
commandLine 'cargo', 'fmt'
}
task runRustClippy(type: Exec) {
commandLine 'cargo', 'clippy', '--fix', '--allow-dirty', '--allow-staged'
}
// TBC - We should consider using some kind of gradle rust build plug-in
task buildRustDebug(type: Exec) {
commandLine 'cargo', 'build'
}
task buildRustForDocker(type: Exec) {
def target = "x86_64-unknown-linux-gnu"
def dockerPlatform = "linux/amd64"
def tagSuffix = "linux-amd64"
if (System.getProperty("os.arch") == "aarch64") {
target = "aarch64-unknown-linux-gnu"
dockerPlatform = "linux/arm64"
tagSuffix = "linux-arm64"
}
doFirst {
project.logger.lifecycle("Building Rust for docker:")
project.logger.lifecycle("Building for own target: $target")
project.logger.lifecycle("Building for own docker platform: $dockerPlatform")
}
workingDir rootProject.projectDir
def outputDir = "core-rust/target/$target/${project.property("rustBinaryBuildType")}"
// Trigger a custom error message on failure...
ignoreExitValue true
if (project.hasProperty('ci')) {
def envRustProfile =
(project.property("rustBinaryBuildType") == "" || project.property("rustBinaryBuildType") == null) ? "release"
: project.property("rustBinaryBuildType") == "debug" ? "dev"
: project.property("rustBinaryBuildType")
project.logger.lifecycle("Running build in CI:")
// Use local cache instead remote cache.
// Remote cache has shown to be too expensive in the long run.
// Might be reintroduced with private DockerHub Images if sufficient image-pulls are available
def dockerMultiStageCmd = """
set -ex
if [ -d $outputDir ]; then rm -Rf $outputDir; fi
export DOCKER_BUILDKIT=1
docker buildx build \
--file Dockerfile \
--build-arg RUST_PROFILE=$envRustProfile \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=local,src=/tmp/outputs/cache/docker \
--cache-to type=local,dest=/tmp/outputs/cache/docker,mode=max \
--platform $dockerPlatform \
--target library-container \
--output type=local,dest=$outputDir/ \
.
[ -f $outputDir/libcorerust.so ]
"""
commandLine 'sh', '-c', dockerMultiStageCmd
} else {
def envRustProfile = project.property("rustBinaryBuildType") == "debug" ? "dev" : project.property("rustBinaryBuildType")
// Change clean to "TRUE" to clear out the current build cache - eg if there is some corruption in the volume
def clean = "FALSE"
def dockerComposeRun = """
set -ex
docker compose -f ./docker/local-cached-rust-build.yaml build
docker compose -f ./docker/local-cached-rust-build.yaml run \
--rm \
--env CARGO_CLEAN=$clean \
--env TARGET=$target \
--env RUST_PROFILE=$envRustProfile \
--env BINARY_BUILD_TYPE=$rustBinaryBuildType \
--env BUILD_ARTIFACT=libcorerust.so \
--volume "${rootProject.projectDir}/$outputDir:/output" \
build-rust
"""
commandLine 'sh', '-c', dockerComposeRun
}
doLast {
if (executionResult.get().getExitValue() != 0) {
logger.error(String.format(
"\n!!! SPECIFIC HELP FOR THIS ERROR" +
"\n!!!\n!!! The docker compose command failed. If the above error suggests that compose is not a command," +
"\n!!! ensure you have `docker --version 20.10.10` or newer installed." +
"\n!!!\n!!! The following command failed with exit value %s:" +
"\n!!! %s",
executionResult.get().getExitValue(),
commandLine
))
executionResult.get().assertNormalExitValue()
}
}
}