forked from google/rust_icu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
185 lines (170 loc) · 6.16 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
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.4.2
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 ?= 69
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
# 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-%:
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=${LOGNAME_HOME}/.cargo:/usr/local/cargo \
--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 \
./rust_icu/rust_icu_sys/bindgen/run_bindgen.sh"
# 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 \
static-bindgen-67 \
static-bindgen-68 \
static-bindgen-69
.PHONY: static-bindgen
# 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:
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
# This is not the best method, since it will error out if a crate has already
# been published.
publish:
$(call publishfn,rust_icu_sys)
$(call publishfn,rust_icu_common)
$(call publishfn,rust_icu_uenum)
$(call publishfn,rust_icu_ustring)
$(call publishfn,rust_icu_utext)
$(call publishfn,rust_icu_uloc)
$(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)
$(call publishfn,rust_icu_unumberformatter)
$(call publishfn,rust_icu_ecma402)
.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 ?= 1.0.0
UPREV_NEW_VERSION ?= 1.0.1
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_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)
.PHONY: uprev
cov:
./build/showprogress.sh