diff --git a/cargo.sh b/cargo.sh index ae3a3c08..434340b4 100755 --- a/cargo.sh +++ b/cargo.sh @@ -11,21 +11,7 @@ SOURCE_DIR="$(dirname "$SCRIPT_PATH")" CARGO_TARGET_DIR="$(pwd)" export CARGO_TARGET_DIR -if [ "${1}" = "--rename" ]; then - shift - FILENAME="${1}" - shift - OUT_PATH="$(realpath "${1}")" -elif [ "${1}" = "--output" ]; then - shift - OUT_PATH="$(realpath "${1}")" - FILENAME="$(basename "${OUT_PATH}")" -fi -shift cd "$SOURCE_DIR" cargo "$@" -if [ -n "${OUT_PATH}" ]; then - cp -a "${CARGO_TARGET_DIR}"/debug/"${FILENAME}" "${OUT_PATH}" -fi diff --git a/cargo_build.sh b/cargo_build.sh new file mode 100755 index 00000000..840bc1c6 --- /dev/null +++ b/cargo_build.sh @@ -0,0 +1,34 @@ +#!/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/meson.build b/meson.build index f748973f..a5d6a856 100644 --- a/meson.build +++ b/meson.build @@ -33,6 +33,11 @@ endif if get_option('buildtype') != 'plain' add_project_arguments('-fstack-protector-strong', language: 'c') endif +if get_option('buildtype') == 'release' + cargo_build_flags = ['--release'] # for artifacts +else + cargo_build_flags = [] +endif prefix = get_option('prefix') datadir = join_paths(prefix, get_option('datadir')) @@ -54,8 +59,9 @@ summary = [ ] message('\n'.join(summary)) -cargo = find_program('cargo') +dep_cargo = find_program('cargo') cargo_script = find_program('cargo.sh') +cargo_build = find_program('cargo_build.sh') subdir('data') subdir('protocols') diff --git a/src/meson.build b/src/meson.build index 36f817bb..0f071d01 100644 --- a/src/meson.build +++ b/src/meson.build @@ -58,7 +58,7 @@ rslibs = custom_target( output: ['librs.a'], install: false, console: true, - command: [cargo_script, '--output', '@OUTPUT@', 'build', '--lib'] + command: [cargo_build] + cargo_build_flags + ['@OUTPUT@', '--lib'] ) build_rstests = custom_target( @@ -72,14 +72,14 @@ build_rstests = custom_target( output: ['src'], install: false, console: true, - command: [cargo_script, '', 'test', '--no-run'], + command: [cargo_script, 'test', '--no-run'], depends: rslibs, # no point building tests if the code itself fails ) test( 'rstest', cargo_script, - args: ['', 'test'], + args: ['test'], # this is a whole Carg-based test suite, let it run for a while timeout: 900, depends: build_rstests, @@ -131,7 +131,8 @@ test_layout = custom_target('squeekboard-test-layout', build_always_stale: true, output: ['squeekboard-test-layout'], console: true, - command: [cargo_script, '--rename', 'test_layout', '@OUTPUT@', 'build', '--bin', 'test_layout'], + command: [cargo_build] + cargo_build_flags + + ['--rename', 'test_layout', '@OUTPUT@', '--bin', 'test_layout'], install: true, install_dir: bindir, ) diff --git a/tests/meson.build b/tests/meson.build index bd89b1a9..3c7b6c39 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -62,7 +62,7 @@ foreach layout : [ test( 'test_layout_' + layout, cargo_script, - args: ['', 'run', '--example', 'test_layout', layout] + args: ['run', '--example', 'test_layout', layout] ) endforeach