diff --git a/cargo_build.py b/cargo_build.py new file mode 100644 index 00000000..d78ceb9e --- /dev/null +++ b/cargo_build.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +"""This script manages Cargo builds +while keeping the artifact directory within the build tree +instead of the source tree. +""" + +from pathlib import Path +import shlex +import subprocess +import sys + +source_dir = Path(__file__).absolute().parent + +args = sys.argv[1:] +binary_dir = "debug" + +if '--release' in args: + binary_dir = "release" + +# The file produced by Cargo will have a special name +try: + i = args.index('--rename') +except ValueError: + filename = None +else: + args.pop(i) + filename = args.pop(i) + +# The target destination of the produced file is a positional argument +out_path = [arg for arg in args if not arg.startswith('--')] +if out_path: + out_path = out_path[0] + i = args.index(out_path) + args.pop(i) + +subprocess.run(['sh', "{}/cargo.sh".format(shlex.quote(source_dir.as_posix())), 'build'] + + args, + check=True) + +if out_path: + out_path = Path(out_path).absolute() + out_basename = out_path.name + filename = filename or out_basename + subprocess.run(['cp', '-a', + './{}/{}'.format(shlex.quote(binary_dir), shlex.quote(filename)), + out_path], + check=True) + diff --git a/cargo_build.sh b/cargo_build.sh deleted file mode 100755 index 840bc1c6..00000000 --- a/cargo_build.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -# This script manages Cargo builds -# while keeping the artifact directory within the build tree -# instead of the source tree - -set -e - -SCRIPT_PATH="$(realpath "$0")" -SOURCE_DIR="$(dirname "$SCRIPT_PATH")" - -RELEASE="" -BINARY_DIR="debug" -if [ "${1}" = "--release" ]; then - shift - BINARY_DIR="release" - RELEASE="--release" -fi - -if [ "${1}" = "--rename" ]; then - shift - FILENAME="${1}" - shift -fi -OUT_PATH="$(realpath "${1}")" -shift -OUT_BASENAME="$(basename "${OUT_PATH}")" -FILENAME="${FILENAME:-"${OUT_BASENAME}"}" - -sh "$SOURCE_DIR"/cargo.sh build $RELEASE "$@" - -if [ -n "${OUT_PATH}" ]; then - cp -a ./"${BINARY_DIR}"/"${FILENAME}" "${OUT_PATH}" -fi diff --git a/debian/control b/debian/control index ff713e71..f57b943a 100644 --- a/debian/control +++ b/debian/control @@ -26,6 +26,7 @@ Build-Depends: librust-xkbcommon-0.4+wayland-dev (>= 0.4), libwayland-dev (>= 1.16), lsb-release, + python3, rustc, wayland-protocols (>= 1.14), Standards-Version: 4.1.3 diff --git a/debian/rules b/debian/rules index 1eddb6f9..0238bd0d 100755 --- a/debian/rules +++ b/debian/rules @@ -8,6 +8,22 @@ ifeq ($(DEB_HOST_ARCH),mips64el) export RUSTFLAGS = -Ctarget-feature=+xgot endif +# the below avoids an FTBFS on mips64el with a GOT > 64kb +DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH) +ifeq ($(DEB_HOST_ARCH),mips64el) + xgot = -Ctarget-feature=+xgot +else + xgot = +endif + +# Don't use paths that may change between builds. +# No need to care about $HOME +# because Cargo will not place any source in ~/.cargo. +# The build directory is a subdirectory of the source directory, +# so it doesn't need to be explicitly taken care of. +export RUSTFLAGS = --remap-path-prefix=$(CURDIR)=/remap-pwd $(xgot) + + distrel := $(shell lsb_release --codename --short) ifneq (,$(filter $(distrel),buster amber)) legacy = true diff --git a/meson.build b/meson.build index a1a073a4..c0eac362 100644 --- a/meson.build +++ b/meson.build @@ -100,7 +100,7 @@ cargo_toml = custom_target( dep_cargo = find_program('cargo') cargo_script = find_program('cargo.sh') -cargo_build = find_program('cargo_build.sh') +cargo_build = find_program('cargo_build.py') subdir('data') subdir('protocols') diff --git a/src/data.rs b/src/data.rs index ab0c4d5a..41123b24 100644 --- a/src/data.rs +++ b/src/data.rs @@ -746,13 +746,21 @@ mod tests { use ::logging::ProblemPanic; - const THIS_FILE: &str = file!(); - fn path_from_root(file: &'static str) -> PathBuf { - PathBuf::from(THIS_FILE) - .parent().unwrap() - .parent().unwrap() - .join(file) + let source_dir = env::var("SOURCE_DIR") + .map(PathBuf::from) + .unwrap_or_else(|e| { + if let env::VarError::NotPresent = e { + let this_file = file!(); + PathBuf::from(this_file) + .parent().unwrap() + .parent().unwrap() + .into() + } else { + panic!("{:?}", e); + } + }); + source_dir.join(file) } #[test] diff --git a/src/meson.build b/src/meson.build index f5bd27ae..d85be960 100644 --- a/src/meson.build +++ b/src/meson.build @@ -80,6 +80,7 @@ test( 'rstest', cargo_script, args: ['test'] + cargo_build_flags, + env: ['SOURCE_DIR=' + meson.source_root()], # this is a whole Carg-based test suite, let it run for a while timeout: 900, depends: [build_rstests, cargo_toml], diff --git a/tests/meson.build b/tests/meson.build index e78a714d..103c631d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -77,13 +77,23 @@ foreach layout : [ if layout == 'emoji' extra += ['allow_missing_return'] endif - + + # Older Cargo seens to be sensitive to something + # about the RUST_FLAGS env var, and rebuilds all tests when it's set, + # increasing test time by 2 orders of magnitude. + # Let it have its way. + if get_option('legacy') == true + timeout = 300 + else + timeout = 30 + endif test( 'test_layout_' + layout, cargo_script, args: ['run'] + cargo_build_flags + ['--example', 'test_layout', '--', layout] + extra, + timeout: timeout, workdir: meson.build_root(), ) endforeach