From 7fcfc618ea1facdd65b4dfcf585fc809fe22602d Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Tue, 27 May 2025 23:07:55 -0400 Subject: [PATCH 1/4] adding cmake build for arwcelderlib. --- .gitignore | 2 ++ Cargo.toml | 11 +++++++++++ arcwelderlib-sys/Cargo.toml | 8 ++++++++ arcwelderlib-sys/build.rs | 32 ++++++++++++++++++++++++++++++++ arcwelderlib-sys/src/lib.rs | 15 +++++++++++++++ src/main.rs | 21 ++++++++++++++++++++- 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 arcwelderlib-sys/Cargo.toml create mode 100644 arcwelderlib-sys/build.rs create mode 100644 arcwelderlib-sys/src/lib.rs diff --git a/.gitignore b/.gitignore index d3c4db3..2ea19a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +/arcwelderlib-sys/vendor/ArcWelderLib /target Cargo.lock *.gcode + diff --git a/Cargo.toml b/Cargo.toml index 87f4887..1c642d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,14 @@ clap = { version = "4.5.16", features = ["derive"] } serde = { version = "1.0.213", features = ["derive"] } serde_json = "1.0.132" stl_io = "0.8.2" + +[dependencies.arcwelderlib-sys] +optional = true +path = "arcwelderlib-sys" + +[features] +default = [] +arcwelder = ["arcwelderlib-sys"] + +[workspace] +members = ["arcwelderlib-sys"] diff --git a/arcwelderlib-sys/Cargo.toml b/arcwelderlib-sys/Cargo.toml new file mode 100644 index 0000000..4a5f4df --- /dev/null +++ b/arcwelderlib-sys/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "arcwelderlib-sys" +version = "0.1.0" +edition = "2024" + +[build-dependencies] +cmake = "0.1.54" +git2 = "0.20.2" diff --git a/arcwelderlib-sys/build.rs b/arcwelderlib-sys/build.rs new file mode 100644 index 0000000..4ffca47 --- /dev/null +++ b/arcwelderlib-sys/build.rs @@ -0,0 +1,32 @@ +use git2::Repository; +use std::env; +use std::fs; +use std::path::PathBuf; + +fn main() { + let arcwelder_src = PathBuf::from("vendor/ArcWelderLib"); + + if !arcwelder_src.exists() { + println!("Cloning ArcWelderLib..."); + Repository::clone("https://github.com/fieldOfView/ArcWelderLib.git", &arcwelder_src) + .expect("Failed to clone ArcWelderLib"); + } + + // This assumes ArcWelderConsole is the name of the CMake target + let dst = cmake::Config::new(&arcwelder_src) + .build_target("ArcWelderConsole") + .build(); + + // Typical output location is build/ArcWelderConsole + let exe_path = dst.join("build") + .join("ArcWelderConsole") + .join("ArcWelder"); + + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let target_path = out_dir.join("ArcWelderConsole"); + + fs::copy(&exe_path, &target_path).expect("Failed to copy ArcWelder executable"); + + println!("cargo:rerun-if-changed=vendor/ArcWelderLib"); + println!("cargo:rustc-env=ARCWELDER_PATH={}", target_path.display()); +} diff --git a/arcwelderlib-sys/src/lib.rs b/arcwelderlib-sys/src/lib.rs new file mode 100644 index 0000000..7aa92ea --- /dev/null +++ b/arcwelderlib-sys/src/lib.rs @@ -0,0 +1,15 @@ +use std::path::PathBuf; + +/// Returns the path to the built ArcWelder executable +fn arcwelder_exe_path() -> PathBuf { + PathBuf::from(env!("ARCWELDER_PATH")) +} + +/// publicly callable command. +pub fn arcwelder(input_file: &str, output_file: &str) -> () { + let arcwelder = arcwelder_exe_path(); + let status = std::process::Command::new(arcwelder) + .args([input_file, output_file]) + .status() + .expect("Failed to execute ArcWelder"); +} diff --git a/src/main.rs b/src/main.rs index 6f5c134..b40fedf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "arcwelder")] +use arcwelderlib_sys::arcwelder; + use clap::Parser; use slicey::{ geometry::STLMesh, @@ -18,7 +21,10 @@ struct CLIArgs { stl_files: Vec, /// Path to settings file #[arg(long)] - settings_file: String + settings_file: String, + /// Whether or not to use arcwelder. Requires cargo build --features arcwelder + #[arg(long)] + arcwelder: bool } fn main() { @@ -31,4 +37,17 @@ fn main() { .collect(); let slicer = Slicer::new(settings, stl_meshes); let _ = slicer.slice(&args.gcode_file); + + // arcwelder stuff + let arcwelder_enabled = cfg!(feature = "arcwelder"); + if arcwelder_enabled { + println!("ArcWelder feature is enabled."); + } else { + println!("ArcWelder feature is NOT enabled."); + } + + #[cfg(feature = "arcwelder")] + if args.arcwelder { + arcwelder(&args.gcode_file, &args.gcode_file) + } } From 35d608079c53c42e4c154a57bd237c51a9c71480 Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Tue, 27 May 2025 23:09:50 -0400 Subject: [PATCH 2/4] adding CI. --- .github/workflows/CI.yml | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..e9608bd --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,62 @@ +name: Rust +on: + pull_request: + branches: main + release: + types: published +env: + CARGO_TERM_COLOR: always +jobs: + bench: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + # package: + # runs-on: ubuntu-latest + # steps: + # - name: checkout + # uses: actions/checkout@v4 + # - name: cleanup + # run: rm -fr book/ sandbox/ tests/ + # - name: package + # run: cargo package + # - name: login + # if: github.event_name == 'release' + # run: cargo login ${{ secrets.CRATES_IO_TOKEN }} + # - name: publish + # if: github.event_name == 'release' + # run: cargo publish + test: + if: github.event_name != 'release' + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + toolchain: + - beta + - stable + runs-on: ${{ matrix.os }} + steps: + - name: checkout + uses: actions/checkout@v4 + - uses: actions-rs/toolchain@v1 + with: + # components: clippy, rustfmt + default: true + toolchain: ${{ matrix.toolchain }} + - name: build + run: cargo build --release + # - name: clippy + # run: cargo clippy -- -D warnings + # - name: clippy + # run: cargo clippy --tests + # - name: doc + # run: cargo rustdoc --release -- --html-in-header docs/katex.html + # - name: fmt + # run: cargo fmt --all -- --check + - name: test + run: cargo test --release From 135ee05a5a79101af4870065eef9819a221b3cdb Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Tue, 27 May 2025 23:11:54 -0400 Subject: [PATCH 3/4] tweaking CI to use all features. --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e9608bd..84a6000 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -49,7 +49,7 @@ jobs: default: true toolchain: ${{ matrix.toolchain }} - name: build - run: cargo build --release + run: cargo build --features arcwelder--release # - name: clippy # run: cargo clippy -- -D warnings # - name: clippy @@ -59,4 +59,4 @@ jobs: # - name: fmt # run: cargo fmt --all -- --check - name: test - run: cargo test --release + run: cargo test --features arcwelder --release From 41cc2afc8d2d45cc8b6af0b5a37d2f88c7d11bde Mon Sep 17 00:00:00 2001 From: "Craig M. Hamel" Date: Tue, 27 May 2025 23:12:50 -0400 Subject: [PATCH 4/4] tweaking CI to use all features. --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 84a6000..2f29c0d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -49,7 +49,7 @@ jobs: default: true toolchain: ${{ matrix.toolchain }} - name: build - run: cargo build --features arcwelder--release + run: cargo build --features arcwelder --release # - name: clippy # run: cargo clippy -- -D warnings # - name: clippy