diff --git a/build-aux/cargo.py b/build-aux/cargo.py new file mode 100755 index 0000000..1b8130b --- /dev/null +++ b/build-aux/cargo.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import sys +import subprocess +import os +import shutil + +env = os.environ + +MESON_BUILD_ROOT=sys.argv[1] +MESON_SOURCE_ROOT=sys.argv[2] +CARGO_TARGET_DIR = os.path.join (MESON_BUILD_ROOT, "target") +env["CARGO_TARGET_DIR"] = CARGO_TARGET_DIR +CARGO_HOME = os.path.join (CARGO_TARGET_DIR, "cargo-home") +env["CARGO_HOME"] = CARGO_HOME +OUTPUT=sys.argv[3] +BUILDTYPE=sys.argv[4] +APP_BIN=sys.argv[5] + + +if BUILDTYPE == "release": + print("RELEASE MODE") + CMD = ['cargo', 'build', '--manifest-path', os.path.join(MESON_SOURCE_ROOT, 'Cargo.toml'), '--release'] + subprocess.run(CMD, env=env) + shutil.copyfile(os.path.join(CARGO_TARGET_DIR, "release", APP_BIN), OUTPUT) +else: + print("DEBUG MODE") + CMD = ['cargo', 'build', '--manifest-path', os.path.join(MESON_SOURCE_ROOT, 'Cargo.toml')] + subprocess.run(CMD, env=env) + shutil.copyfile(os.path.join(CARGO_TARGET_DIR, "debug", APP_BIN), OUTPUT) + + diff --git a/build-aux/cargo.sh b/build-aux/cargo.sh deleted file mode 100644 index caec9ac..0000000 --- a/build-aux/cargo.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -export MESON_BUILD_ROOT="$1" -export MESON_SOURCE_ROOT="$2" -export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target -export CARGO_HOME="$CARGO_TARGET_DIR"/cargo-home -export OUTPUT="$3" -export BUILDTYPE="$4" -export APP_BIN="$5" - - -if [ $BUILDTYPE = "release" ] -then - echo "RELEASE MODE" - cargo build --manifest-path \ - "$MESON_SOURCE_ROOT"/Cargo.toml --release && \ - cp "$CARGO_TARGET_DIR"/release/"$APP_BIN" "$OUTPUT" -else - echo "DEBUG MODE" - cargo build --manifest-path \ - "$MESON_SOURCE_ROOT"/Cargo.toml && \ - cp "$CARGO_TARGET_DIR"/debug/"$APP_BIN" "$OUTPUT" -fi - diff --git a/meson.build b/meson.build index 9aa725f..cbba514 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ python_mod = import('python') python3 = python_mod.find_installation() current_date = run_command(python3, '-c', 'import datetime; print(datetime.datetime.now().strftime("%Y-%m-%d"), end ="")').stdout() i18n = import('i18n') +host_system = host_machine.system() dependency('glib-2.0', version: '>= 2.66') dependency('gio-2.0', version: '>= 2.66') @@ -69,5 +70,6 @@ meson.add_dist_script( meson.source_root(), join_paths(meson.build_root(), 'meson-dist', meson.project_name() + '-' + version) ) - -meson.add_install_script('build-aux/meson/postinstall.py') +if host_system == 'linux' + meson.add_install_script('build-aux/meson/postinstall.py') +endif diff --git a/src/meson.build b/src/meson.build index 434261e..6bf39d6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -39,12 +39,18 @@ rust_sources = files( sources = [cargo_sources, rust_sources] -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.py')) + +app_name = meson.project_name() +if host_system == 'windows' + app_name += '.exe' +endif + cargo_release = custom_target( 'cargo-build', build_by_default: true, input: sources, - output: meson.project_name(), + output: app_name, console: true, install: true, install_dir: get_option('bindir'), @@ -54,6 +60,6 @@ cargo_release = custom_target( meson.source_root(), '@OUTPUT@', get_option('buildtype'), - meson.project_name(), + app_name, ] )