Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
rustup override set nightly
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Restore helper manifest
run: cp crates/openjd-sessions/src/helper/Cargo.bundled.toml crates/openjd-sessions/src/helper/Cargo.toml
- name: Run helper cargo fmt
run: cargo fmt --manifest-path crates/openjd-sessions/src/helper/Cargo.toml --all -- --check

Expand All @@ -44,6 +46,8 @@ jobs:
- uses: actions/checkout@v6
- name: Install cargo-deny
run: cargo install cargo-deny --locked
- name: Restore helper manifest
run: cp crates/openjd-sessions/src/helper/Cargo.bundled.toml crates/openjd-sessions/src/helper/Cargo.toml
# Licenses, bans, and sources apply to every crate we compile,
# including dev-dependencies, so scan the full graph.
- name: Run cargo deny check licenses, bans, sources (workspace)
Expand Down Expand Up @@ -138,6 +142,9 @@ jobs:
# openjd-for-js is a wasm32 crate that has its own dedicated workflow
# (openjd-for-js.yml); compiling it natively here wastes ~45-60s
# recompiling wasm-bindgen, js-sys, web-sys, and serde-wasm-bindgen.
- name: Restore helper manifest
shell: bash
run: cp crates/openjd-sessions/src/helper/Cargo.bundled.toml crates/openjd-sessions/src/helper/Cargo.toml
- name: Build workspace (lib, bin, tests)
run: cargo test --release --workspace --exclude openjd-for-js --all-targets --no-run
- name: Run cargo clippy
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package*.json
!crates/openjd-for-js/package.json
!crates/openjd-for-js/package-lock.json
crates/openjd-sessions/src/helper/target/
crates/openjd-sessions/src/helper/Cargo.toml

# Build artifacts
crates/openjd-for-js/node_modules/
Expand Down
8 changes: 8 additions & 0 deletions crates/openjd-sessions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ repository.workspace = true
homepage.workspace = true
readme = "README.md"
description = "Open Job Description sessions — local job execution runtime"
include = [
"/src/**",
"/tests/**",
"/build.rs",
"/README.md",
"/LICENSE-*",
"/NOTICE",
]
keywords = ["openjd", "openjobdescription", "session", "subprocess", "runtime"]
categories = ["command-line-utilities", "os"]
build = "build.rs"
Expand Down
54 changes: 40 additions & 14 deletions crates/openjd-sessions/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

use std::path::PathBuf;
use std::path::{Path, PathBuf};

fn copy_dir_recursive(src: &Path, dst: &Path) {
std::fs::create_dir_all(dst).unwrap();
for entry in std::fs::read_dir(src).unwrap() {
let entry = entry.unwrap();
let ty = entry.file_type().unwrap();
let dest_path = dst.join(entry.file_name());
if ty.is_dir() {
if entry.file_name() == "target" {
continue;
}
copy_dir_recursive(&entry.path(), &dest_path);
} else {
std::fs::copy(entry.path(), &dest_path).unwrap();
}
}
}

fn main() {
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
Expand All @@ -12,10 +29,11 @@ fn main() {
let helper_dir = manifest_dir.join("src/helper");
let helper_out = out_dir.join("openjd_helper");

// Rerun only when helper sources change. Watching the whole `src/helper/`
// directory would include `src/helper/target/` which this script writes
// into, causing spurious re-runs on every cargo invocation (and
// recompilation of openjd-sessions + openjd-cli every time).
// Rerun only when helper sources change.
println!(
"cargo:rerun-if-changed={}",
helper_dir.join("Cargo.bundled.toml").display()
);
println!(
"cargo:rerun-if-changed={}",
helper_dir.join("Cargo.toml").display()
Expand All @@ -33,12 +51,28 @@ fn main() {
let is_windows = target.contains("windows") || cfg!(windows);

if is_unix || is_windows {
// Copy the helper source tree into OUT_DIR so we never write into the
// source tree. The manifest is stored as `Cargo.bundled.toml` so that
// cargo doesn't treat src/helper/ as a separate crate during packaging
// (its check matches the literal filename `Cargo.toml`), while keeping
// the `.toml` extension so editor TOML tooling still works.
// If `Cargo.toml` exists (local dev before rename), use it as-is.
let build_src = out_dir.join("helper_src");
copy_dir_recursive(&helper_dir, &build_src);

let manifest_in_build = build_src.join("Cargo.toml");
if !manifest_in_build.exists() {
let bundled = build_src.join("Cargo.bundled.toml");
std::fs::rename(&bundled, &manifest_in_build)
.expect("Failed to rename Cargo.bundled.toml to Cargo.toml");
}

let status = std::process::Command::new("cargo")
.args([
"build",
"--release",
"--manifest-path",
&helper_dir.join("Cargo.toml").to_string_lossy(),
&manifest_in_build.to_string_lossy(),
"--target-dir",
&out_dir.join("helper_build").to_string_lossy(),
"--target",
Expand All @@ -60,20 +94,12 @@ fn main() {
.join(binary_name);
std::fs::copy(&built, &helper_out).expect("Failed to copy helper binary");

// Expose the built helper binary path to integration tests via
// env!("OPENJD_HELPER_BINARY_PATH"). This keeps the helper binary
// inside OUT_DIR where it belongs, instead of copying it back into
// the source tree (which would dirty the cargo fingerprint on every
// run).
println!(
"cargo:rustc-env=OPENJD_HELPER_BINARY_PATH={}",
built.display()
);
} else {
// Unsupported platform: write empty placeholder so include_bytes! doesn't fail
std::fs::write(&helper_out, b"").expect("Failed to write placeholder");
// Still set the env var so env!() compiles; tests that need the helper
// will skip on unsupported platforms.
println!(
"cargo:rustc-env=OPENJD_HELPER_BINARY_PATH={}",
helper_out.display()
Expand Down
Comment thread
epmog marked this conversation as resolved.
File renamed without changes.
Loading