espanso/Makefile.toml
2021-07-11 22:26:40 +02:00

179 lines
4.2 KiB
TOML

[config]
default_to_workspace = false
[env]
DEBUG = true
RELEASE = false
NO_X11 = false
NO_MODULO = false
EXEC_PATH = "target/debug/espanso"
# TODO: flag to enable/disable modulo support
[env.release]
DEBUG = false
RELEASE = true
EXEC_PATH = "target/release/espanso"
# Build variants
# This one was written in Rust instead of bash because it has to run on Windows as well
[tasks.build-binary]
script_runner = "@rust"
script = '''
//! ```cargo
//! [dependencies]
//! envmnt = "*"
//! ```
use std::process::Command;
#[derive(Debug, PartialEq)]
enum Profile {
Debug,
Release,
}
fn main() {
let profile = if envmnt::get_or_panic("RELEASE") == "true" {
Profile::Release
} else {
Profile::Debug
};
println!("Using profile: {:?}", profile);
let wayland = envmnt::get_or("NO_X11", "false") == "true";
if wayland {
println!("Using Wayland feature");
}
let avoid_modulo = envmnt::get_or("NO_MODULO", "false") == "true";
if avoid_modulo {
println!("Skipping modulo feature");
}
let mut args = Vec::new();
args.push("build");
if profile == Profile::Release {
args.push("--release");
}
let mut features = Vec::new();
if wayland {
features.push("wayland");
}
if !avoid_modulo {
features.push("modulo");
}
let features_flag = features.join(" ");
args.push("-p");
args.push("espanso");
args.push("--no-default-features");
args.push("--features");
args.push(&features_flag);
println!("Calling with args: {:?}", args);
let mut cmd = Command::new("cargo");
cmd.args(&args);
// Remove cargo/rust-specific env variables, as otherwise they mess up the
// nested cargo build call.
let all_vars = envmnt::vars();
for (key, _) in all_vars {
if key.starts_with("CARGO") || key.starts_with("RUST") {
//println!("Removing {}", key);
cmd.env_remove(key);
}
}
let mut handle = cmd.spawn().expect("cargo build failed");
handle.wait();
}
'''
[tasks.run-binary]
command = "${EXEC_PATH}"
args = ["${@}"]
dependencies = ["build-binary"]
[tasks.create-bundle]
script = '''
TARGET_DIR=target/mac/Espanso.app
rm -Rf $TARGET_DIR
VERSION=$(cat espanso/Cargo.toml | grep version | head -1 | awk -F '"' '{ print $2 }')
mkdir -p $TARGET_DIR/Contents
mkdir -p $TARGET_DIR/Contents/MacOS
mkdir -p $TARGET_DIR/Contents/Resources
sed -e "s/VERSION/$VERSION/" espanso/src/res/macos/Info.plist > $TARGET_DIR/Contents/Info.plist
/bin/echo "APPL????" > $TARGET_DIR/Contents/PkgInfo
cp -f espanso/src/res/macos/icon.icns $TARGET_DIR/Contents/Resources/icon.icns
cp -f $EXEC_PATH $TARGET_DIR/Contents/MacOS/espanso
'''
dependencies=["build-binary"]
[tasks.run-bundle]
command="target/mac/Espanso.app/Contents/MacOS/espanso"
args=["${@}"]
dependencies=["create-bundle"]
[tasks.create-app-image]
script = '''
#!/usr/bin/env bash
set -e
TOOL_DIR=$(pwd)/target/linux/linuxdeploy
TARGET_DIR=$(pwd)/target/linux/AppImage
BUILD_DIR=$TARGET_DIR/build
OUTPUT_DIR=$TARGET_DIR/out
BASE_DIR=$(pwd)
mkdir -p $TOOL_DIR
if ls $TOOL_DIR/*.AppImage 1> /dev/null 2>&1; then
echo "Skipping download of linuxdeploy"
else
echo "Downloading linuxdeploy tool"
wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage -P "$TOOL_DIR"
chmod +x $TOOL_DIR/linuxdeploy*.AppImage
fi
rm -Rf "$TARGET_DIR"
mkdir -p $OUTPUT_DIR
mkdir -p $BUILD_DIR
echo Building AppImage into $OUTPUT_DIR
pushd $OUTPUT_DIR
$TOOL_DIR/linuxdeploy*.AppImage --appimage-extract-and-run -e "$BASE_DIR/$EXEC_PATH" -d "$BASE_DIR/espanso/src/res/linux/espanso.desktop" -i "$BASE_DIR/espanso/src/res/linux/icon.png" --appdir $BUILD_DIR --output appimage
chmod +x ./Espanso*.AppImage
popd
'''
dependencies=["build-binary"]
[tasks.run-app-image]
args=["${@}"]
script='''
#!/usr/bin/env bash
set -e
echo Launching AppImage with args: "$@"
./target/linux/AppImage/out/Espanso-*.AppImage "$@"
'''
dependencies=["create-app-image"]
# Test runs
[tasks.test]
command = "cargo"
args = ["test", "--workspace", "--exclude", "espanso-modulo", "--exclude", "espanso-ipc", "--no-default-features"]
[tasks.test-output]
command = "cargo"
args = ["test", "--workspace", "--exclude", "espanso-modulo", "--exclude", "espanso-ipc", "--no-default-features", "--", "--nocapture"]