Fix binary installation for cross compilation

This commit is contained in:
Elias Projahn 2021-02-19 09:49:06 +01:00
parent 3bdc08e408
commit c2c811e321
2 changed files with 17 additions and 6 deletions

View file

@ -8,17 +8,21 @@ export OUTPUT="$3"
export BUILDTYPE="$4" export BUILDTYPE="$4"
export APP_BIN="$5" export APP_BIN="$5"
if [ -z ${CARGO_BUILD_TARGET+defined} ]; then
CARGO_OUTPUT_PATH="${CARGO_TARGET_DIR}"
else
CARGO_OUTPUT_PATH="${CARGO_TARGET_DIR}/${CARGO_BUILD_TARGET}"
fi
if [ $BUILDTYPE = "release" ] if [ $BUILDTYPE = "release" ]; then
then
echo "RELEASE MODE" echo "RELEASE MODE"
cargo build --manifest-path \ cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml --release && \ "$MESON_SOURCE_ROOT"/Cargo.toml --release && \
cp "$CARGO_TARGET_DIR"/release/"$APP_BIN" "$OUTPUT" cp "$CARGO_OUTPUT_PATH"/release/"$APP_BIN" "$OUTPUT"
else else
echo "DEBUG MODE" echo "DEBUG MODE"
cargo build --manifest-path \ cargo build --manifest-path \
"$MESON_SOURCE_ROOT"/Cargo.toml --verbose && \ "$MESON_SOURCE_ROOT"/Cargo.toml --verbose && \
cp "$CARGO_TARGET_DIR"/debug/"$APP_BIN" "$OUTPUT" cp "$CARGO_OUTPUT_PATH"/debug/"$APP_BIN" "$OUTPUT"
fi fi

View file

@ -37,6 +37,13 @@ sources = files(
'resources.rs', 'resources.rs',
) )
system = host_machine.system()
if system == 'windows'
output = meson.project_name() + '.exe'
else
output = meson.project_name()
endif
cargo_script = find_program(join_paths(meson.source_root(), 'build-aux/cargo.sh')) cargo_script = find_program(join_paths(meson.source_root(), 'build-aux/cargo.sh'))
cargo_release = custom_target( cargo_release = custom_target(
'cargo-build', 'cargo-build',
@ -44,7 +51,7 @@ cargo_release = custom_target(
input: sources, input: sources,
build_always_stale: true, build_always_stale: true,
depends: resources, depends: resources,
output: meson.project_name(), output: output,
console: true, console: true,
install: true, install: true,
install_dir: get_option('bindir'), install_dir: get_option('bindir'),
@ -54,6 +61,6 @@ cargo_release = custom_target(
meson.source_root(), meson.source_root(),
'@OUTPUT@', '@OUTPUT@',
get_option('buildtype'), get_option('buildtype'),
meson.project_name(), output,
] ]
) )