diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..2f29c0d --- /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 --features arcwelder --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 --features arcwelder --release 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) + } }