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
13 changes: 11 additions & 2 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Build svg2gcode-cli

on: [push, pull_request]
on:
push:
branches: [main]
pull_request:

env:
CARGO_TERM_COLOR: always
Expand All @@ -9,8 +12,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Fmt
run: cargo fmt --check -p svg2gcode-cli
- name: Clippy
run: cargo clippy -p svg2gcode-cli -- -D warnings
- name: Build
run: cargo build -p svg2gcode-cli
22 changes: 19 additions & 3 deletions .github/workflows/lib.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Build, test, and publish coverage for svg2gcode

on: [push, pull_request]
on:
push:
branches: [main]
pull_request:

env:
CARGO_TERM_COLOR: always
Expand All @@ -9,15 +12,26 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libcairo2-dev
- name: Fmt
run: cargo fmt --check -p svg2gcode
- name: Clippy
run: cargo clippy -p svg2gcode -- -D warnings
- name: Build
run: cargo build -p svg2gcode
- name: Test
run: cargo test -p svg2gcode
coverage:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: Swatinem/rust-cache@v2
Expand All @@ -27,6 +41,8 @@ jobs:
with:
toolchain: nightly
components: llvm-tools-preview
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libcairo2-dev
- run: cargo install grcov
- run: cargo build -p svg2gcode
env:
Expand Down
79 changes: 61 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,69 @@ on:
types: [created]

jobs:
release:
name: release ${{ matrix.targets.name }}
runs-on: ubuntu-latest
build:
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
targets:
[
{ name: Windows, triple: x86_64-pc-windows-gnu, version: stable },
{ name: Linux, triple: x86_64-unknown-linux-musl, version: stable },
# Fix for https://github.com/rust-build/rust-build.action/issues/88
{ name: macOS, triple: x86_64-apple-darwin, version: '1.73.0' }
]
# https://docs.github.com/en/actions/reference/runners/github-hosted-runners#standard-github-hosted-runners-for-public-repositories
include:
- name: Linux x64
runner: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact: svg2gcode-linux-x86_64
- name: Linux arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
artifact: svg2gcode-linux-aarch64
- name: macOS x64
runner: macos-15-intel
target: x86_64-apple-darwin
artifact: svg2gcode-macos-x86_64
- name: macOS arm64
runner: macos-latest
target: aarch64-apple-darwin
artifact: svg2gcode-macos-aarch64
- name: Windows x64
runner: windows-latest
target: x86_64-pc-windows-msvc
artifact: svg2gcode-windows-x86_64.exe
- name: Windows arm64
runner: windows-11-arm
target: aarch64-pc-windows-msvc
artifact: svg2gcode-windows-aarch64.exe
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install musl tools
if: contains(matrix.target, 'musl')
run: sudo apt-get install -y musl-tools
- name: Build
run: cargo build --release --target ${{ matrix.target }} -p svg2gcode-cli
- name: Copy cli build
run: cp target/${{ matrix.target }}/release/svg2gcode${{ runner.os == 'Windows' && '.exe' || '' }} ${{ matrix.artifact }}
- uses: actions/upload-artifact@v6
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}

release:
name: Upload release assets
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Compile and release
uses: rust-build/rust-build.action@v1.4.5
- uses: actions/download-artifact@v7
with:
path: artifacts
merge-multiple: true
- name: Upload to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUSTTARGET: ${{ matrix.targets.triple }}
TOOLCHAIN_VERSION: ${{ matrix.targets.version }}
EXTRA_FILES: "README.md LICENSE"
SRC_DIR: "cli/"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release upload ${{ github.event.release.tag_name }} artifacts/*
4 changes: 2 additions & 2 deletions .github/workflows/web-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
submodules: 'true'
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -29,7 +29,7 @@ jobs:
trunk build --release --public-url svg2gcode

- name: Publish to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
name: Check svg2gcode-web
on: [push, pull_request]
on:
push:
branches: [main]
pull_request:
env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo check -p svg2gcode-web
with:
targets: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Fmt
run: cargo fmt --check -p svg2gcode-web
- name: Clippy
run: cargo clippy -p svg2gcode-web --target wasm32-unknown-unknown -- -D warnings
- name: Check
run: cargo check -p svg2gcode-web --target wasm32-unknown-unknown
3 changes: 1 addition & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ svg2gcode = { path = "../lib", version = "0.3.2", features = ["serde"] }
env_logger = "0.11"
log.workspace = true
g-code.workspace = true
# Latest version of clap supporting Rust 1.73, needed for the macOS release in CI
clap = { version = "^4.0,<=4.4.18", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
codespan-reporting = "0.11"
roxmltree.workspace = true
serde_json.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct Opt {
/// Workaround for parsers that don't accept comments on the same line
newline_before_comment: Option<bool>,
#[arg(long)]
/// When printing a node name , print a extra attribute
/// When printing a node name , print a extra attribute
///
/// Useful to print the label of layer on SVG generated by Inkscape
extra_attribute_name: Option<String>,
Expand Down Expand Up @@ -165,7 +165,7 @@ fn main() -> io::Result<()> {
settings.postprocess.newline_before_comment = newline_before_comment;
}

settings.conversion.extra_attribute_name = opt.extra_attribute_name ;
settings.conversion.extra_attribute_name = opt.extra_attribute_name;

if let Version::Unknown(ref unknown) = settings.version {
error!(
Expand Down
1 change: 1 addition & 0 deletions lib/src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl<S: Scalar> Transformed<S> for SvgArc<S> {
///
/// The code is Rust-ified with only one or two changes, but I plan to understand the math here and
/// merge changes upstream to lyon-geom.
#[allow(non_snake_case)]
fn transformed(&self, transform: &Transform<S>) -> Self {
let from = transform.transform_point(self.from);
let to = transform.transform_point(self.to);
Expand Down
24 changes: 12 additions & 12 deletions lib/src/converter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Default for ConversionConfig {
feedrate: 300.0,
dpi: 96.0,
origin: zero_origin(),
extra_attribute_name : None,
extra_attribute_name: None,
}
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'a, T: Turtle> ConversionVisitor<'a, T> {
comment += name;
comment += " > ";
});
comment += &node_name(node,&self._config.extra_attribute_name);
comment += &node_name(node, &self._config.extra_attribute_name);

self.terrarium.turtle.comment(comment);
}
Expand Down Expand Up @@ -174,20 +174,20 @@ pub fn svg2program<'a, 'input: 'a>(
conversion_visitor.terrarium.turtle.inner.program
}

fn node_name(node: &Node , attr_to_print : &Option<String> ) -> String {
fn node_name(node: &Node, attr_to_print: &Option<String>) -> String {
let mut name = node.tag_name().name().to_string();
if let Some(id) = node.attribute("id") {
name += "#";
name += id;
if let Some(extra_attr_to_print) = attr_to_print {
for a_attr in node.attributes() {
if a_attr.name() == extra_attr_to_print {
name += " ( ";
name += a_attr.value() ;
name += " ) ";
}
}
}
if let Some(extra_attr_to_print) = attr_to_print {
for a_attr in node.attributes() {
if a_attr.name() == extra_attr_to_print {
name += " ( ";
name += a_attr.value();
name += " ) ";
}
}
}
}
name
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/converter/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn should_render_node(node: Node) -> bool {
node.is_element()
&& !node
.attribute("style")
.map_or(false, |style| style.contains("display:none"))
.is_some_and( |style| style.contains("display:none"))
// - Defs are not rendered
// - Markers are not directly rendered
// - Symbols are not directly rendered
Expand Down Expand Up @@ -370,7 +370,8 @@ impl<'a, T: Turtle> XmlVisitor for ConversionVisitor<'a, T> {
}
}

self.name_stack.push(node_name(&node,&self._config.extra_attribute_name));
self.name_stack
.push(node_name(&node, &self._config.extra_attribute_name));
}

fn visit_exit(&mut self, node: Node) {
Expand Down
4 changes: 2 additions & 2 deletions web/src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn settings_form() -> Html {
|| form_state
.origin
.iter()
.all(|opt| opt.as_ref().map_or(false, |r| r.is_err()))
.all(|opt| opt.as_ref().is_some_and(|r| r.is_err()))
|| form_state
.tool_on_sequence
.as_ref()
Expand Down Expand Up @@ -343,7 +343,7 @@ pub fn import_export_modal() -> Html {
button={html_nested!(
<Button
style={ButtonStyle::Primary}
disabled={import_state.as_ref().map_or(true, |r| r.is_err()) || import_reading.is_some()}
disabled={import_state.as_ref().is_none_or(|r| r.is_err()) || import_reading.is_some()}
title="Save"
onclick={import_save_onclick}
input_group=true
Expand Down
4 changes: 2 additions & 2 deletions web/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum FormStateConversionError {
GCode(String),
}

impl<'a> TryInto<Settings> for &'a FormState {
impl TryInto<Settings> for &FormState {
type Error = FormStateConversionError;

fn try_into(self) -> Result<Settings, Self::Error> {
Expand All @@ -52,7 +52,7 @@ impl<'a> TryInto<Settings> for &'a FormState {
self.origin[0].clone().transpose()?,
self.origin[1].clone().transpose()?,
],
extra_attribute_name: None,
extra_attribute_name: None,
},
machine: MachineConfig {
supported_functionality: SupportedFunctionality {
Expand Down
Loading