-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
289 lines (257 loc) · 9.41 KB
/
Makefile
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
TOP_DIR := $(shell pwd)
DOCKER_REPO ?= filipfilmar
# The environment is slightly different from the "regular" environment when
# docker is started with "sudo". The settings below recover the original user
# name, UID, GID and home directory.
LOGNAME := $(shell logname)
LOGNAME_HOME := $(shell echo ~${LOGNAME})
UID := $(shell id -u ${LOGNAME})
GID := $(shell id -g ${LOGNAME})
INTERACTIVE:=$(shell [ -t 0 ] && echo 1)
ifeq (${INTERACTIVE},1)
TTY := --tty --interactive
else
TTY :=
endif
# The buildenv version that will be used to build and test. This allows us to
# update the buildenv code but not use it immediately. You can modify the
# buildenv version by passing its value through env variables like so:
#
# make USED_BUILDENV_VERSION=whatever-you-want docker-test
#
# NOTE: This version number is completely independent of the crate version.
USED_BUILDENV_VERSION ?= 1.82.0
CARGO_FEATURE_VERSION :=
ICU_VERSION ?= $(shell icu-config --version)
ICU_MAJOR_VERSION ?= $(basename ${ICU_VERSION})
ICU_LIBDIR := $(shell icu-config --libdir)
PKG_CONFIG_PATH := "${HOME}/local/lib/pkgconfig:${PKG_CONFIG_PATH}"
LD_LIBRARY_PATH := "${ICU_LIBDIR}"
test:
echo "ICU version detected: ${ICU_VERSION}" \
&& echo "ICU libdir: ${ICU_LIBDIR}" \
&& echo "ICU major version detected: ${ICU_MAJOR_VERSION}" \
&& echo "PKG_CONFIG_PATH: ${PKG_CONFIG_PATH}" \
&& PKG_CONFIG_PATH=${PKG_CONFIG_PATH} \
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} \
cargo test \
&& PKG_CONFIG_PATH=${PKG_CONFIG_PATH} \
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} \
cargo doc
.PHONY: test
# Run a test inside a Docker container. The --volume mounts attach local dirs
# so that as much as possible of the host configuration is retained.
TMP ?= /tmp
CARGO_TARGET_DIR := ${TMP}/rust_icu-${LOGNAME}-target
# The docker testing target. Used to run tests in a dockerized environment,
# based off of a fresh checkout of source in the current directory.
# Pass different values for DOCKER_TEST_ENV and DOCKER_TEST_CARGO_TEST_ARGS to
# test different configurations. This is useful in Travis CI matrix tests, for
# example.
RUST_ICU_MAJOR_VERSION_NUMBER ?= 74
DOCKER_TEST_ENV ?= rust_icu_testenv-${RUST_ICU_MAJOR_VERSION_NUMBER}
DOCKER_TEST_CARGO_TEST_ARGS ?=
docker-test:
mkdir -p ${CARGO_TARGET_DIR}
echo top_dir: ${TOP_DIR}
echo pwd: $(shell pwd)
docker run ${TTY} \
--user=${UID}:${GID} \
--volume=${TOP_DIR}:/src/rust_icu \
--volume=${CARGO_TARGET_DIR}:/build/cargo \
--volume=${LOGNAME_HOME}/.cargo:/usr/local/cargo \
--env="CARGO_TEST_ARGS=${DOCKER_TEST_CARGO_TEST_ARGS}" \
--env="RUST_ICU_MAJOR_VERSION_NUMBER=${RUST_ICU_MAJOR_VERSION_NUMBER}"\
--env="RUST_BACKTRACE=full" \
${DOCKER_REPO}/${DOCKER_TEST_ENV}:${USED_BUILDENV_VERSION}
.PHONY: docker-test
# Compiles and tests rust_icu code with the current head at ICU
docker-test-current:
mkdir -p ${CARGO_TARGET_DIR}
echo top_dir: ${TOP_DIR}
echo pwd: $(shell pwd)
docker run ${TTY} \
--user=${UID}:${GID} \
--volume=${TOP_DIR}:/src/rust_icu \
--volume=${CARGO_TARGET_DIR}:/build/cargo \
--volume=${LOGNAME_HOME}/.cargo:/usr/local/cargo \
--env="CARGO_TEST_ARGS=${DOCKER_TEST_CARGO_TEST_ARGS}" \
--env="RUST_ICU_MAJOR_VERSION_NUMBER=${RUST_ICU_MAJOR_VERSION_NUMBER}"\
--env="RUST_BACKTRACE=full" \
${DOCKER_REPO}/rust_icu_testenv-current:${USED_BUILDENV_VERSION}
.PHONY: docker-test-current
# Test with the homebrew version of icu4c on macOS with static linking (the default way of linking for distribution on Apple platforms)
macos-test:
brew install icu4c
RUST_ICU_LINK_SEARCH_DIR="$(shell brew --prefix)/opt/icu4c/lib" \
RUST_ICU_MAJOR_VERSION_NUMBER=${RUST_ICU_MAJOR_VERSION_NUMBER} \
cargo test --no-default-features --features=icu_version_64_plus,icu_version_67_plus,icu_version_68_plus,icu_version_in_env,renaming,static
.PHONY: macos-test
# Refreshes the static bindgen output (contents of ./rust_icu_sys/bindgen) based
# on the currently present ICU versions in the test environment.
#
# % is expected to be a number equal to a valid ICU major version number, such
# as "65" or such.
static-bindgen-%.stamp: rust_icu_sys/bindgen/run_bindgen.sh
mkdir -p ${CARGO_TARGET_DIR}
echo top_dir: ${TOP_DIR}
echo pwd: $(shell pwd)
docker run ${TTY} \
--user=${UID}:${GID} \
--volume=${TOP_DIR}:/src/rust_icu \
--env="RUST_ICU_MAJOR_VERSION_NUMBER=$*" \
--entrypoint="/bin/bash" \
${DOCKER_REPO}/rust_icu_testenv-$*:${USED_BUILDENV_VERSION} \
"-l" "-c" "env OUTPUT_DIR=./rust_icu/rust_icu_sys/bindgen \
./rust_icu/rust_icu_sys/bindgen/run_bindgen.sh"
touch $@
# Keep only the latest version of the library in the static-bindgen target,
# and any versions that do not have a lib.rs in rust_icu_sys/bindgen.
static-bindgen: \
static-bindgen-63.stamp \
static-bindgen-71.stamp \
static-bindgen-72.stamp \
static-bindgen-73.stamp \
static-bindgen-74.stamp
.PHONY: static-bindgen
static-bindgen-special-%.stamp: rust_icu_sys/bindgen_special/run_bindgen.sh
mkdir -p "${CARGO_TARGET_DIR}"
echo top_dir: "${TOP_DIR}"
echo pwd: "$(shell pwd)"
if [ "${ICU_SOURCE_DIR}" == "" ]; then exit 1; fi
docker run ${TTY} \
--user=${UID}:${GID} \
--volume=${TOP_DIR}:/src/rust_icu \
--volume=${LOGNAME_HOME}/.cargo:/usr/local/cargo \
--volume=${LOGNAME_HOME}/code/icu:/src/icu \
--env="RUST_ICU_MAJOR_VERSION_NUMBER=$*" \
--entrypoint="/bin/bash" \
${DOCKER_REPO}/rust_icu_testenv-$*:${USED_BUILDENV_VERSION} \
"-c" "env OUTPUT_DIR=./rust_icu/rust_icu_sys/bindgen_special \
./rust_icu/rust_icu_sys/bindgen_special/run_bindgen.sh"
touch $@
# Keep only the latest version of the library in the static-bindgen target,
# and any versions that do not have a lib.rs in rust_icu_sys/bindgen.
static-bindgen-special: \
static-bindgen-special-72.stamp \
static-bindgen-special-73.stamp \
static-bindgen-special-74.stamp
.PHONY: static-bindgen-special
# Builds and pushes the build environment containers. You would not normally
# need to do this.
buildenv:
make -C build DOCKER_REPO=${DOCKER_REPO} all
.PHONY: buildenv
clean:
rm -f *.stamp
cargo clean
.PHONY: clean
# Publishes all crates to crates.io.
#
# The sleep call is needed because we've observed that crates are sometimes
# not found by cargo immediately after a publish. Sleeping on this is bad,
# but there doesn't seem to be a much better option available.
define publishfn
( cd $(1) && cargo publish && sleep 30)
endef
######################################################################
## Targets for publishing crates to crates.io
# Everyone's dependency.
publish-rust_icu_sys.stamp:
$(call publishfn,rust_icu_sys)
touch $@
publish-rust_icu_common.stamp: \
publish-rust_icu_sys.stamp
$(call publishfn,rust_icu_common)
touch $@
publish-rust_icu_uenum.stamp: \
publish-rust_icu_common.stamp
$(call publishfn,rust_icu_uenum)
touch $@
publish-rust_icu_ustring.stamp: \
publish-rust_icu_uenum.stamp
$(call publishfn,rust_icu_ustring)
touch $@
publish-rust_icu_utext.stamp: \
publish-rust_icu_ustring.stamp
$(call publishfn,rust_icu_utext)
touch $@
publish-rust_icu_uloc.stamp: \
publish-rust_icu_utext.stamp
$(call publishfn,rust_icu_uloc)
touch $@
publish-rust_icu.stamp: \
publish-rust_icu_sys.stamp \
publish-rust_icu_common.stamp \
publish-rust_icu_uenum.stamp \
publish-rust_icu_utext.stamp \
publish-rust_icu_uloc.stamp
$(call publishfn,rust_icu_ucal)
$(call publishfn,rust_icu_udat)
$(call publishfn,rust_icu_udata)
$(call publishfn,rust_icu_ucol)
$(call publishfn,rust_icu_umsg)
$(call publishfn,rust_icu_ulistformatter)
$(call publishfn,rust_icu_upluralrules)
$(call publishfn,rust_icu_uformattable)
$(call publishfn,rust_icu_unum)
$(call publishfn,rust_icu_ubrk)
$(call publishfn,rust_icu_utrans)
$(call publishfn,rust_icu_unumberformatter)
$(call publishfn,rust_icu_unorm2)
$(call publishfn,rust_icu_uchar)
$(call publishfn,rust_icu_ucnv)
$(call publishfn,rust_icu_ucsdet)
touch $@
publish-ecma402_traits.stamp:
$(call publishfn,ecma402_traits)
touch $@
publish-rust_icu_ecma402.stamp: publish-rust_icu.stamp publish-ecma402_traits.stamp
$(call publishfn,rust_icu_ecma402)
touch $@
publish.stamp: publish-rust_icu.stamp publish-rust_icu_ecma402.stamp
$(call publishfn,rust_icu)
touch $@
publish: publish.stamp
.PHONY: publish
# A helper to up-rev the cargo crate versions.
# NOTE: The cargo crate version number is completely independent of the Docker
# build environment version number.
UPREV_OLD_VERSION ?= 5.0.0
UPREV_NEW_VERSION ?= 5.1.0
define uprevfn
( \
cd $(1) && \
sed -i -e s/${UPREV_OLD_VERSION}/$(UPREV_NEW_VERSION)/g Cargo.toml \
)
endef
uprev:
$(call uprevfn,rust_icu)
$(call uprevfn,rust_icu_common)
$(call uprevfn,rust_icu_intl)
$(call uprevfn,rust_icu_sys)
$(call uprevfn,rust_icu_ucal)
$(call uprevfn,rust_icu_ucol)
$(call uprevfn,rust_icu_ucsdet)
$(call uprevfn,rust_icu_udat)
$(call uprevfn,rust_icu_udata)
$(call uprevfn,rust_icu_uenum)
$(call uprevfn,rust_icu_ulistformatter)
$(call uprevfn,rust_icu_uloc)
$(call uprevfn,rust_icu_umsg)
$(call uprevfn,rust_icu_upluralrules)
$(call uprevfn,rust_icu_ustring)
$(call uprevfn,rust_icu_utext)
$(call uprevfn,rust_icu_uformattable)
$(call uprevfn,rust_icu_unum)
$(call uprevfn,rust_icu_unumberformatter)
$(call uprevfn,rust_icu_ubrk)
$(call uprevfn,rust_icu_utrans)
$(call uprevfn,rust_icu_ecma402)
$(call uprevfn,ecma402_traits)
$(call uprevfn,rust_icu_unorm2)
$(call uprevfn,rust_icu_uchar)
$(call uprevfn,rust_icu_ucnv)
.PHONY: uprev
cov:
./build/showprogress.sh