From aa210204a7e5eaa7dc180fd19cd1e0a53f78db4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Tue, 25 Mar 2025 06:34:52 +0900 Subject: [PATCH] chore(xtask): add ffi install task This task is for installing all the requirements for ffi tasks. (That is: `diplomat-tool`.) --- Cargo.lock | 2 +- ffi/Cargo.toml | 2 +- xtask/src/bin_version.rs | 1 + xtask/src/cli.rs | 3 +++ xtask/src/ffi.rs | 24 +++++++++++++++++++++--- xtask/src/main.rs | 3 ++- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09743f03..32f59806 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1508,7 +1508,7 @@ dependencies = [ [[package]] name = "ffi" -version = "0.1.0" +version = "0.0.0" dependencies = [ "diplomat", "diplomat-runtime", diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index 3193461e..5a7b3932 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ffi" -version = "0.1.0" +version = "0.0.0" edition = "2021" publish = false diff --git a/xtask/src/bin_version.rs b/xtask/src/bin_version.rs index d2d9cad0..8b31108a 100644 --- a/xtask/src/bin_version.rs +++ b/xtask/src/bin_version.rs @@ -8,5 +8,6 @@ pub const CARGO_LLVM_COV: CargoPackage = CargoPackage::new("cargo-llvm-cov", "0. pub const GRCOV: CargoPackage = CargoPackage::new("grcov", "0.8.20"); pub const WASM_PACK: CargoPackage = CargoPackage::new("wasm-pack", "0.13.1"); pub const TYPOS_CLI: CargoPackage = CargoPackage::new("typos-cli", "1.29.5").with_binary_name("typos"); +pub const DIPLOMAT_TOOL: CargoPackage = CargoPackage::new("diplomat-tool", "0.7.1"); pub const WABT_VERSION: &str = "1.0.36"; diff --git a/xtask/src/cli.rs b/xtask/src/cli.rs index fc8a0f85..79a1ef1d 100644 --- a/xtask/src/cli.rs +++ b/xtask/src/cli.rs @@ -36,6 +36,7 @@ TASKS: web check Ensure Web Client is building without error web install Install dependencies required to build and run Web Client web run Run SvelteKit-based standalone Web Client + ffi install Install all requirements for ffi tasks ffi build [--release] Build DLL for FFI (default is debug) ffi bindings [--skip-dotnet-build] Generate C# bindings for FFI, optionally skipping the .NET build @@ -88,6 +89,7 @@ pub enum Action { WebCheck, WebInstall, WebRun, + FfiInstall, FfiBuildDll { release: bool, }, @@ -162,6 +164,7 @@ pub fn parse_args() -> anyhow::Result { None => Action::ShowHelp, }, Some("ffi") => match args.subcommand()?.as_deref() { + Some("install") => Action::FfiInstall, Some("build") => Action::FfiBuildDll { release: args.contains("--release"), }, diff --git a/xtask/src/ffi.rs b/xtask/src/ffi.rs index fd370c22..4ed3dff2 100644 --- a/xtask/src/ffi.rs +++ b/xtask/src/ffi.rs @@ -3,6 +3,8 @@ use std::path::{Path, PathBuf}; use anyhow::Context as _; +use crate::prelude::*; + #[cfg(target_os = "windows")] const OUTPUT_LIB_NAME: &str = "ironrdp.dll"; #[cfg(target_os = "linux")] @@ -24,7 +26,17 @@ const DOTNET_NATIVE_LIB_PATH: &str = "dependencies/runtimes/linux-x64/native/"; #[cfg(target_os = "macos")] const DOTNET_NATIVE_LIB_PATH: &str = "dependencies/runtimes/osx-x64/native/"; -pub(crate) fn build_dynamic_lib(sh: &xshell::Shell, release: bool) -> anyhow::Result<()> { +pub(crate) fn install(sh: &Shell) -> anyhow::Result<()> { + let _s = Section::new("FFI-INSTALL"); + + cargo_install(sh, &DIPLOMAT_TOOL)?; + + Ok(()) +} + +pub(crate) fn build_dynamic_lib(sh: &Shell, release: bool) -> anyhow::Result<()> { + let _s = Section::new("BUILD-DYNAMIC-LIBRARY"); + println!("Build IronRDP DLL"); let mut args = vec!["build", "--package", "ffi"]; @@ -64,7 +76,13 @@ pub(crate) fn build_dynamic_lib(sh: &xshell::Shell, release: bool) -> anyhow::Re Ok(()) } -pub(crate) fn build_bindings(sh: &xshell::Shell, skip_dotnet_build: bool) -> anyhow::Result<()> { +pub(crate) fn build_bindings(sh: &Shell, skip_dotnet_build: bool) -> anyhow::Result<()> { + let _s = Section::new("BUILD-BINDINGS"); + + if !is_installed(sh, "diplomat-tool") { + anyhow::bail!("`diplomat-tool` binary is missing. Please run `cargo xtask ffi install`."); + } + let dotnet_generated_path = "./dotnet/Devolutions.IronRdp/Generated/"; let diplomat_config = "./dotnet-interop-conf.toml"; @@ -90,7 +108,7 @@ pub(crate) fn build_bindings(sh: &xshell::Shell, skip_dotnet_build: bool) -> any sh.change_dir("./dotnet/Devolutions.IronRdp/"); - sh.cmd("dotnet").arg("build").run()?; + cmd!(sh, "dotnet build").run()?; Ok(()) } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b4a01137..2d834d27 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -112,7 +112,8 @@ fn main() -> anyhow::Result<()> { Action::WebCheck => web::check(&sh)?, Action::WebInstall => web::install(&sh)?, Action::WebRun => web::run(&sh)?, - Action::FfiBuildDll { release: debug } => ffi::build_dynamic_lib(&sh, debug)?, + Action::FfiInstall => ffi::install(&sh)?, + Action::FfiBuildDll { release } => ffi::build_dynamic_lib(&sh, release)?, Action::FfiBuildBindings { skip_dotnet_build } => ffi::build_bindings(&sh, skip_dotnet_build)?, }