forked from r12f/rnp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.toml
More file actions
260 lines (213 loc) · 8.42 KB
/
Makefile.toml
File metadata and controls
260 lines (213 loc) · 8.42 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
[env]
# Directories
BUILD_CONFIG = { source = "${PROFILE_NAME}", default_value = "debug", mapping = {"production" = "release" } }
BUILD_DIR = "target/${CARGO_MAKE_RUST_TARGET_TRIPLE}/${BUILD_CONFIG}"
PUBLISH_DIR = "./publish/${CARGO_MAKE_RUST_TARGET_TRIPLE}"
PACKAGE_DIR = "${PUBLISH_DIR}/packages"
# Build settings
GCC_XCOMPILER_ID = { source = "${CARGO_MAKE_RUST_TARGET_TRIPLE}", default_value = "", mapping = {"i686-unknown-linux-gnu" = "x86_64-linux-gnu", "arm-unknown-linux-gnueabi" = "arm-linux-gnueabi", "aarch64-unknown-linux-gnu" = "aarch64-linux-gnu" } }
BUILD_ARCH = { source = "${CARGO_MAKE_RUST_TARGET_ARCH}", default_value = "${CARGO_MAKE_RUST_TARGET_ARCH}", mapping = {"x86_64" = "x64"} }
BUILD_FLAVOR = "${CARGO_MAKE_RUST_TARGET_OS}.${BUILD_ARCH}"
BUILD_VERSION = "0.1.0"
BUILD_BRANCH = "main"
BUILD_TAG = "${BUILD_VERSION}.${BUILD_BRANCH}"
BUILD_TARGET = "${CARGO_MAKE_RUST_TARGET_TRIPLE}"
RNP_FILE_NAME = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "rnp", mapping = {"windows" = "rnp.exe" } }
# Sign settings (Use RNP_SIGNING_URL as enablement key.)
RNP_SIGNING_URL = { value = "${RNP_SIGNING_URL}", condition = { env_set = ["RNP_SIGNING_URL"] } }
RNP_SIGNING_VAULT_URL = { value = "", condition = { env_not_set = ["RNP_SIGNING_VAULT_URL"] } }
RNP_SIGNING_CLIENT_ID = { value = "", condition = { env_not_set = ["RNP_SIGNING_CLIENT_ID"] } }
RNP_SIGNING_CLIENT_SECRET = { value = "", condition = { env_not_set = ["RNP_SIGNING_CLIENT_SECRET"] } }
RNP_SIGNING_CERT_NAME = { value = "", condition = { env_not_set = ["RNP_SIGNING_CERT_NAME"] } }
##############################################
# Build
#
[tasks.build]
description = "Build the program."
clear = true
dependencies = ["format", "cargo-build", "make-symbol", "sign"]
# Format the code in dev profile.
[tasks.format]
description = "Use rustfmt to format the code."
condition = { profiles = ["development"] }
install_crate = "rustfmt"
command = "cargo"
args = ["fmt", "--", "--emit=files"]
# Cargo build
[tasks.cargo-build]
description = "Run cargo build."
run_task = [
{ name = "cargo-build-dev", condition = { profiles = ["development"] } },
{ name = "cargo-build-release", condition = { profiles = ["production"] } },
]
[tasks.cargo-build-dev]
description = "Run cargo build with dev profile."
command = "cargo"
args = ["build", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]
[tasks.cargo-build-release]
description = "Run cargo build with release profile."
command = "cargo"
args = ["build", "--release", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]
# Make symbols
[tasks.make-symbol]
windows_alias = "make-symbol-win"
linux_alias = "make-symbol-linux"
mac_alias = "make-symbol-mac"
[tasks.make-symbol-win]
script_runner = "@duckscript"
script = '''
echo "Windows builds generates PDB by default, so nothing to generate here."
'''
[tasks.make-symbol-linux]
script_runner="bash"
script = '''
GCC_PREFIX=""
if [[ "${GCC_XCOMPILER_ID}" -ne "" ]]; then GCC_PREFIX="${GCC_XCOMPILER_ID}-"; fi
echo "Removing existing symbol file: ${BUILD_DIR}/rnp.debug"
rm -f ${BUILD_DIR}/rnp.debug
echo "Generating new symbol file: ${BUILD_DIR}/rnp.debug"
${GCC_PREFIX}objcopy --only-keep-debug ${BUILD_DIR}/rnp ${BUILD_DIR}/rnp.debug
${GCC_PREFIX}strip --strip-debug --strip-unneeded -p ${BUILD_DIR}/rnp
${GCC_PREFIX}objcopy --add-gnu-debuglink=${BUILD_DIR}/rnp.debug ${BUILD_DIR}/rnp
'''
[tasks.make-symbol-mac]
script = '''
brew install binutils
echo "Removing existing symbol file: ${BUILD_DIR}/rnp.debug"
rm -f ${BUILD_DIR}/rnp.debug
echo "Generating new symbol file: ${BUILD_DIR}/rnp.debug"
/usr/local/opt/binutils/bin/gobjcopy --only-keep-debug ${BUILD_DIR}/rnp ${BUILD_DIR}/rnp.debug
strip -S ${BUILD_DIR}/rnp
/usr/local/opt/binutils/bin/gobjcopy --add-gnu-debuglink=${BUILD_DIR}/rnp.debug ${BUILD_DIR}/rnp
'''
# Sign
[tasks.sign]
description = "Run AzureSignTool to sign the binaries."
condition = { platforms = ["windows"], env_set = [ "RNP_SIGNING_URL" ] }
command = "AzureSignTool"
args = ["sign", "-du", "${RNP_SIGNING_URL}", "-kvu", "${RNP_SIGNING_VAULT_URL}", "-kvi", "${RNP_SIGNING_CLIENT_ID}", "-kvs", "${RNP_SIGNING_CLIENT_SECRET}", "-kvc", "${RNP_SIGNING_CERT_NAME}", "-v", "${BUILD_DIR}/rnp.exe"]
# Pack packages for each platform
[tasks.pack]
description = "Pack binaries into packages."
run_task = [
{ name = ["pack-prepare", "pack-binaries", "pack-symbols", "pack-zip", "pack-nuget", "pack-msix"], condition = { platforms = ["windows"] } },
{ name = ["pack-prepare", "pack-binaries", "pack-symbols", "pack-tar", "pack-nuget"], condition = { platforms = ["linux", "macos"] } },
]
[tasks.pack-prepare]
description = "Prepare environments for pack."
script_runner = "@duckscript"
script = '''
echo "Removing publish directory: ${PUBLISH_DIR}"
rm -r ${PUBLISH_DIR}
if not is_dir ${PUBLISH_DIR}
echo "Creating publish directory: ${PUBLISH_DIR}"
mkdir ${PUBLISH_DIR}
end
if not is_dir ${PACKAGE_DIR}
echo "Creating package directory: ${PACKAGE_DIR}"
mkdir ${PACKAGE_DIR}
end
'''
[tasks.pack-binaries]
description = "Pack binaries."
script_runner = "@duckscript"
script = '''
OUT_DIR = set "${PUBLISH_DIR}/bin"
if not is_dir ${OUT_DIR}
echo "Creating output directory: ${OUT_DIR}"
mkdir ${OUT_DIR}
end
echo "Copying binaries from build output: ${BUILD_DIR}"
cp ${BUILD_DIR}/${RNP_FILE_NAME} ${OUT_DIR}/${RNP_FILE_NAME}
echo "Copying key documents from source code"
cp README.md ${OUT_DIR}/README.md
cp LICENSE.txt ${OUT_DIR}/LICENSE.txt
'''
[tasks.pack-symbols]
description = "Pack symbol files."
script_runner = "@duckscript"
script = '''
OUT_DIR = set "${PUBLISH_DIR}/symbols"
if not is_dir ${OUT_DIR}
echo "Creating output directory: ${OUT_DIR}"
mkdir ${OUT_DIR}
end
if is_path_exists ${BUILD_DIR}/rnp.pdb
cp ${BUILD_DIR}/rnp.pdb ${OUT_DIR}/rnp.pdb
end
if is_path_exists ${BUILD_DIR}/rnp.debug
cp ${BUILD_DIR}/rnp.debug ${OUT_DIR}/rnp.debug
end
'''
[tasks.pack-zip]
description = "Pack zip package."
script_runner = "@duckscript"
script = '''
ZIP_FILE_PATH = set "${PACKAGE_DIR}/rnp.${BUILD_TAG}.${BUILD_FLAVOR}.zip"
echo "Pack binaries to ${ZIP_FILE_PATH}"
exec 7z -tzip a ${ZIP_FILE_PATH} ./${PUBLISH_DIR}/bin/*
'''
[tasks.pack-tar]
description = "Pack tar package."
script_runner = "@duckscript"
script = '''
TAR_FILE_PATH = set "${PACKAGE_DIR}/rnp.${BUILD_TAG}.${BUILD_FLAVOR}.tar.gz"
echo "Pack binaries to ${TAR_FILE_PATH}"
exec tar -cvzf ${TAR_FILE_PATH} --directory ${PUBLISH_DIR}/bin *
'''
[tasks.pack-nuget]
description = "Pack nuget package."
script_runner = "@duckscript"
script = '''
!include_files ./build/pack/pack_utils.ds
INT_DIR = set "${BUILD_DIR}/nuget"
echo "Removing intermediate directory: ${INT_DIR}"
rm -r ${INT_DIR}
echo "Copying bin output as intermediate directory: ${INT_DIR}"
cp ${PUBLISH_DIR}/bin ${INT_DIR}
eval_build_template_file "./build/templates/nuget_packages/rnp_nupkg.csproj" ${INT_DIR}/rnp_nupkg.csproj
OUT_DIR = set "${PUBLISH_DIR}/nuget"
if not is_dir ${OUT_DIR}
echo "Creating output directory: ${OUT_DIR}"
mkdir ${OUT_DIR}
end
exec dotnet pack ${INT_DIR}/rnp_nupkg.csproj -o ${OUT_DIR}
'''
[tasks.pack-msix]
description = "Pack msix package."
script_runner = "@duckscript"
script = '''
!include_files ./build/pack/pack_utils.ds
INT_DIR = set "${BUILD_DIR}/msix"
echo "Removing intermediate directory: ${INT_DIR}"
rm -r ${INT_DIR}
echo "Copying bin output as intermediate directory: ${INT_DIR}"
cp ${PUBLISH_DIR}/bin ${INT_DIR}
cp ./assets ${INT_DIR}
eval_build_template_file "./build/templates/msix/appxmanifest.xml" ${INT_DIR}/appxmanifest.xml
eval_build_template_file "./build/templates/msix/appxmappings-make.txt" ${INT_DIR}/appxmappings.txt
OUT_DIR = set "${PUBLISH_DIR}/msix"
if not is_dir ${OUT_DIR}
echo "Creating output directory: ${OUT_DIR}"
mkdir ${OUT_DIR}
end
exec "C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x64/makeappx.exe" pack /m "${INT_DIR}/appxmanifest.xml" /f "${INT_DIR}/appxmappings.txt" /p "${OUT_DIR}/rnp.${BUILD_TAG}.${BUILD_FLAVOR}.msix"
'''
##############################################
# Test
#
[tasks.test]
description = "Run all tests."
clear = true
run_task = [
{ name = "test-dev", condition = { profiles = ["development"] } },
{ name = "test-release", condition = { profiles = ["production"] } },
]
[tasks.test-dev]
description = "Run all tests with dev profile."
command = "cargo"
args = ["test", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]
[tasks.test-release]
description = "Run all tests with release profile."
command = "cargo"
args = ["test", "--release", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"]