Files
regorus/xtask/src/tasks/bindings/all.rs
T
Anand Krishnamoorthi e68e852ee3 feat(xtask): consolidate CI workflows onto xtask helpers (#542)
- split the xtask crate into structured modules for
  - bindings
  - ci
  - dev
  - util
  - no-std
- Adding commands for
  - ci-release/ci-debug
  - MUSL/no-std
  - per- binding language smoke tests
  - developer tasks (fmt, clippy, pre-commit, pre-push)
- refresh Cargo manifests/locks, binding readmes, and shared FFI helpers so every binding reuses the same preparation steps
- refactor GitHub Actions (release/debug, extensions, CodeQL, clippy, bindings) to call the new xtask commands
- Use rust-cache in ci workflows (microsoft qdk also does this)
- extend README with a contributor workflow section describing how xtask mirrors CI expectations
- update pre-commit and pre-push hooks to use the xtask dev commands

WORKAROUND:
When dotnet is run from an xtask, codeql tracer intercepts it an routes to a nonexistent binary.
Therefore in codeql workflow, xtask is not used for c# and instead dotnet is directly invoked.
Tracked by #545

closes #475

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2026-01-27 07:42:21 +05:30

143 lines
3.9 KiB
Rust

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use anyhow::Result;
use clap::Args;
use super::c::{TestCCommand, TestCNoStdCommand};
use super::cpp::TestCppCommand;
use super::csharp::{build_nuget_package, BuildNugetConfig, TestCsharpCommand};
use super::ffi;
use super::java::{BuildJavaCommand, TestJavaCommand};
use super::python::{BuildPythonCommand, TestPythonCommand};
use super::wasm::{BuildWasmCommand, TestWasmCommand};
use crate::tasks::util::workspace_root;
/// Builds every published binding with opinionated defaults.
#[derive(Args, Default)]
pub struct BuildAllBindingsCommand {
/// Optimise artefacts where supported (defaults to debug builds).
#[arg(long)]
pub release: bool,
}
impl BuildAllBindingsCommand {
pub fn run(&self) -> Result<()> {
let workspace = workspace_root();
let release = self.release;
let targets = ffi::resolve_targets(Vec::new())?;
ffi::build_targets(&workspace, &targets, release)?;
let ffi_dir = workspace.join("bindings/ffi/target");
let nuget_result = build_nuget_package(&BuildNugetConfig {
targets: Vec::new(),
release,
clean: false,
artifacts_dir: Some(ffi_dir.clone()),
enforce_artifacts: false,
})?;
if nuget_result.packages.is_empty() {
println!("NuGet packaging completed but no archives were produced.");
} else {
for package in &nuget_result.packages {
println!("NuGet package ready at {}", package.display());
}
}
BuildJavaCommand { skip_tests: true }.run()?;
BuildPythonCommand {
release,
target: None,
target_dir: None,
frozen: false,
}
.run()?;
BuildWasmCommand {
release,
target: "nodejs".to_string(),
out_dir: None,
}
.run()?;
println!("Completed building all bindings.");
Ok(())
}
}
/// Executes the smoke tests for all bindings in sequence.
#[derive(Args, Default)]
pub struct TestAllBindingsCommand {
/// Optimise artefacts where supported (defaults to debug builds).
#[arg(long)]
pub release: bool,
/// Python executable leveraged by the binding tests.
#[arg(long, value_name = "EXE", default_value = "python3")]
pub python: String,
/// Node.js executable leveraged by the WASM test.
#[arg(long, value_name = "EXE", default_value = "node")]
pub node: String,
}
impl TestAllBindingsCommand {
pub fn run(&self) -> Result<()> {
TestCCommand {
release: self.release,
frozen: false,
skip_ffi: false,
}
.run()?;
TestCppCommand {
release: self.release,
frozen: false,
skip_ffi: true,
}
.run()?;
TestCNoStdCommand {
release: self.release,
frozen: false,
skip_ffi: true,
}
.run()?;
TestJavaCommand {
release: self.release,
frozen: false,
}
.run()?;
TestPythonCommand {
release: self.release,
target: None,
python: self.python.clone(),
}
.run()?;
TestWasmCommand {
release: self.release,
target: "nodejs".to_string(),
out_dir: None,
node: self.node.clone(),
frozen: false,
skip_build: false,
}
.run()?;
TestCsharpCommand {
targets: Vec::new(),
release: self.release,
clean: false,
artifacts_dir: None,
enforce_artifacts: false,
force_nuget: false,
nuget_dir: None,
}
.run()?;
println!("Completed testing all bindings.");
Ok(())
}
}