Skip to content

Commit 01d823b

Browse files
committed
install: Verify that installed compiler runs
Another sanity check. Can be disabled in `install.sh` via `--disable-verify` and `configure` with `--disable-verify-install`.
1 parent 42e1003 commit 01d823b

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-
384384
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
385385
opt rpath 1 "build rpaths into rustc itself"
386386
opt nightly 0 "build nightly packages"
387+
opt verify-install 1 "verify installed binaries work"
387388
valopt prefix "/usr/local" "set installation prefix"
388389
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
389390
valopt llvm-root "" "set LLVM root"

mk/install.mk

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88
# option. This file may not be copied, modified, or distributed
99
# except according to those terms.
1010

11+
ifdef CFG_DISABLE_VERIFY_INSTALL
12+
MAYBE_DISABLE_VERIFY=--disable-verify
13+
else
14+
MAYBE_DISABLE_VERIFY=
15+
endif
1116

1217
install: dist-install-dir-$(CFG_BUILD)
13-
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)"
18+
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)" "$(MAYBE_DISABLE_VERIFY)"
1419
# Remove tmp files while we can because they may have been created under sudo
1520
$(Q)rm -R tmp/dist/$(PKG_NAME)-$(CFG_BUILD)
1621

1722
uninstall: dist-install-dir-$(CFG_BUILD)
1823
$(Q)sh tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(CFG_PREFIX)" --libdir="$(CFG_LIBDIR)" --mandir="$(CFG_MANDIR)"
24+
# Remove tmp files while we can because they may have been created under sudo
25+
$(Q)rm -R tmp/dist/$(PKG_NAME)-$(CFG_BUILD)
1926

2027

2128
######################################################################

src/etc/install.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ BOOL_OPTIONS=""
212212
VAL_OPTIONS=""
213213

214214
flag uninstall "only uninstall from the installation prefix"
215+
opt verify 1 "verify that the installed binaries run correctly"
215216
valopt prefix "/usr/local" "set installation prefix"
216217
# NB This isn't quite the same definition as in `configure`.
217218
# just using 'lib' instead of CFG_LIBDIR_RELATIVE
@@ -230,19 +231,36 @@ validate_opt
230231

231232
# OK, let's get installing ...
232233

234+
# Sanity check: can we run the binaries?
235+
if [ -z "${CFG_DISABLE_VERIFY}" ]
236+
then
237+
# Don't do this if uninstalling. Failure here won't help in any way.
238+
if [ -z "${CFG_UNINSTALL}" ]
239+
then
240+
msg "verifying platform can run binaries"
241+
"${CFG_SRC_DIR}/bin/rustc" --version > /dev/null
242+
if [ $? -ne 0 ]
243+
then
244+
err "can't execute rustc binary on this platform"
245+
fi
246+
fi
247+
fi
248+
233249
# Sanity check: can we can write to the destination?
250+
msg "verifying destination is writable"
234251
umask 022 && mkdir -p "${CFG_LIBDIR}"
235-
need_ok "can't write to destination. consider 'sudo'."
236-
touch "${CFG_LIBDIR}/rust-install-probe" 2> /dev/null
252+
need_ok "can't write to destination. consider \`sudo\`."
253+
touch "${CFG_LIBDIR}/rust-install-probe" > /dev/null
237254
if [ $? -ne 0 ]
238255
then
239-
err "can't write to destination. consider 'sudo'."
256+
err "can't write to destination. consider \`sudo\`."
240257
fi
241258
rm "${CFG_LIBDIR}/rust-install-probe"
242259
need_ok "failed to remove install probe"
243260

244261
# Sanity check: don't install to the directory containing the installer.
245262
# That would surely cause chaos.
263+
msg "verifying destination is not the same as source"
246264
INSTALLER_DIR="$(cd $(dirname $0) && pwd)"
247265
PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)"
248266
if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
@@ -273,6 +291,10 @@ then
273291
fi
274292
done < "${INSTALLED_MANIFEST}"
275293

294+
# TODO: Remove the manifest.
295+
# If we fail to remove rustlib below, then the installed manifest will
296+
# still be full; the installed manifest needs to be empty before install.
297+
276298
# Remove 'rustlib' directory
277299
rm -r "${CFG_LIBDIR}/rustlib"
278300
if [ $? -ne 0 ]
@@ -346,6 +368,20 @@ while read p; do
346368
# The manifest lists all files to install
347369
done < "${CFG_SRC_DIR}/lib/rustlib/manifest.in"
348370

371+
# Sanity check: can we run the installed binaries?
372+
if [ -z "${CFG_DISABLE_VERIFY}" ]
373+
then
374+
msg "verifying installed binaries are executable"
375+
"${CFG_PREFIX}/bin/rustc" --version > /dev/null
376+
if [ $? -ne 0 ]
377+
then
378+
err "can't execute installed rustc binary. installation may be broken. " \
379+
"if this is expected then rerun install.sh with \`--disable-verify\` " \
380+
"or \`make install\` with \`--disable-verify-install\`"
381+
fi
382+
fi
383+
384+
349385
echo
350386
echo " Rust is ready to roll."
351387
echo

0 commit comments

Comments
 (0)