From fd2be5bc962b60613edd6a87d39031807c07bb92 Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Fri, 20 Sep 2024 16:16:42 +0800 Subject: [PATCH] chore: fix ci and use codspeed (#28) --- .github/workflows/CI.yml | 19 +- .github/workflows/codspeed.yml | 34 +++ Cargo.lock | 317 +++++++++++++++++++- __tests__/__snapshots__/config.spec.ts.md | 8 +- __tests__/__snapshots__/config.spec.ts.snap | Bin 1366 -> 1366 bytes binding.js | 66 +--- crates/core/Cargo.toml | 5 + crates/core/benches/bench.rs | 21 ++ crates/core/benches/rspack-logo.svg | 1 + 9 files changed, 381 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/codspeed.yml create mode 100644 crates/core/benches/bench.rs create mode 100644 crates/core/benches/rspack-logo.svg diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a42d953..56433b0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,7 +3,7 @@ env: DEBUG: napi:* APP_NAME: svgr-rs MACOSX_DEPLOYMENT_TARGET: '10.13' -'on': +on: push: branches: - main @@ -26,7 +26,6 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly-2023-06-27 target: x86_64-unknown-linux-gnu - name: Run Cargo Check @@ -62,7 +61,6 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly-2023-06-27 target: x86_64-unknown-linux-gnu - name: Run cargo test run: cargo test -p svgr-rs @@ -71,10 +69,10 @@ jobs: fail-fast: false matrix: settings: - - host: macos-latest + - host: macos-13 target: x86_64-apple-darwin build: | - yarn build + yarn build --target x86_64-apple-darwin strip -x *.node - host: windows-latest build: yarn build @@ -82,10 +80,9 @@ jobs: - host: ubuntu-latest target: x86_64-unknown-linux-gnu docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian - build: |- - set -e && - rustup default nightly-2023-06-27 && - yarn build --target x86_64-unknown-linux-gnu && + build: | + set -e + yarn build --target x86_64-unknown-linux-gnu strip *.node - host: macos-latest target: aarch64-apple-darwin @@ -94,7 +91,9 @@ jobs: strip -x *.node - host: windows-latest target: aarch64-pc-windows-msvc - build: yarn build --target aarch64-pc-windows-msvc + build: | + rustup target add aarch64-pc-windows-msvc + yarn build --target aarch64-pc-windows-msvc name: stable - ${{ matrix.settings.target }} - node@18 needs: - cargo-test diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..73a4c64 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,34 @@ +name: codspeed-benchmarks + +on: + # Run on pushes to the main branch + push: + branches: + - "main" + # Run on pull requests + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +jobs: + benchmarks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup rust toolchain, cache and cargo-codspeed binary + uses: moonrepo/setup-rust@v0 + with: + channel: stable + cache-target: release + bins: cargo-codspeed + + - name: Build the benchmark target(s) + run: cargo codspeed build + + - name: Run benchmarks + uses: CodSpeedHQ/action@v3 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: cargo codspeed run --package svgr-rs diff --git a/Cargo.lock b/Cargo.lock index e3ec1ca..59ce0fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "ansi_term" version = "0.12.1" @@ -279,7 +285,7 @@ dependencies = [ "chrono", "either", "indexmap", - "itertools", + "itertools 0.13.0", "nom", "once_cell", "serde", @@ -334,6 +340,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.1.7" @@ -355,7 +367,34 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", ] [[package]] @@ -398,12 +437,44 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "codspeed" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "450a0e9df9df1c154156f4344f99d8f6f6e69d0fc4de96ef6e2e68b2ec3bce97" +dependencies = [ + "colored", + "libc", + "serde_json", +] + +[[package]] +name = "codspeed-criterion-compat" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb1a6cb9c20e177fde58cdef97c1c7c9264eb1424fe45c4fccedc2fb078a569" +dependencies = [ + "codspeed", + "colored", + "criterion", +] + [[package]] name = "colorchoice" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "convert_case" version = "0.6.0" @@ -443,6 +514,42 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools 0.10.5", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools 0.10.5", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -468,6 +575,12 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -616,6 +729,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] + [[package]] name = "hashbrown" version = "0.13.2" @@ -656,6 +779,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + [[package]] name = "hstr" version = "0.2.10" @@ -732,6 +861,17 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_ci" version = "1.2.0" @@ -744,6 +884,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.13.0" @@ -796,7 +945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1077,6 +1226,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "outref" version = "0.1.0" @@ -1121,7 +1276,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1225,6 +1380,34 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -1475,6 +1658,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad97d4ce1560a5e27cec89519dc8300d1aa6035b099821261c651486a19e44d5" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -1743,6 +1935,7 @@ name = "svgr-rs" version = "0.1.3" dependencies = [ "clap", + "codspeed-criterion-compat", "linked-hash-map", "linked_hash_set", "napi", @@ -3060,6 +3253,16 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -3266,6 +3469,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3326,6 +3539,16 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -3363,7 +3586,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", ] [[package]] @@ -3372,7 +3604,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -3381,7 +3613,22 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -3390,28 +3637,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -3424,24 +3689,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/__tests__/__snapshots__/config.spec.ts.md b/__tests__/__snapshots__/config.spec.ts.md index 306acaa..70a7295 100644 --- a/__tests__/__snapshots__/config.spec.ts.md +++ b/__tests__/__snapshots__/config.spec.ts.md @@ -152,7 +152,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `import * as React from "react";␊ - const SvgComponent = ({ title , titleId , ...props })=>{title ? {title} : null};␊ + const SvgComponent = ({ title, titleId, ...props })=>{title ? {title} : null};␊ export default SvgComponent;␊ ` @@ -161,7 +161,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `import * as React from "react";␊ - const SvgComponent = ({ desc , descId , ...props })=>{desc ? {desc} : null};␊ + const SvgComponent = ({ desc, descId, ...props })=>{desc ? {desc} : null};␊ export default SvgComponent;␊ ` @@ -226,7 +226,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `import * as React from "react";␊ - const SvgComponent = ({ title , titleId , ...props })=>{title ? {title} : null};␊ export default SvgComponent;␊ @@ -237,7 +237,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 `import * as React from "react";␊ - const SvgComponent = ({ desc , descId , ...props })=>{desc ? {desc} : null};␊ export default SvgComponent;␊ diff --git a/__tests__/__snapshots__/config.spec.ts.snap b/__tests__/__snapshots__/config.spec.ts.snap index ce9c3e622dec4d740703ff9df8c9999d7bf8cada..41378dd06ada2a770e01395a9c813cffa8a5c162 100644 GIT binary patch literal 1366 zcmV-c1*!T$RzV)I*uW14QjQZ3&$yJHz!oB?m&=__r_|XhQD&8^l}e?|+ZLd< zLptBkt_BrULA4sH)c{4MQYmR7ZZ<4rI1g2m1J+DkK%Kz>m(2y(LgxV=O_Zh@rci52I?kuIf*l{>?v3Zi@wQ#b$@ma7C2gL5^u;L$y~a4_2D=g)$J@6hYE|ki(?U0x8pvFBz@^fd_0Z>REd`v zsPc1+>RHFAUP{OKWE6*wh0`YE1Jy4IkM2|+z4D{BRX`Csz``z|eH5RqRZQC~N`a>W zJj#6@yq_DwgIN&nHyh=n*%5v<8DU|{xbw4uQ@lZ(c?8GRLb){!$<(Xo720BIp7whC}A=p#w zh9qH_^rj9i7wae4=$8Um{EP!HTPh@fUn_RmAahzN_q25tySyit;vVtnc-p@zw11p^sw-bR&m{Mfovx-zJeDG9iB?l)va;q7W01AD z^@wpVc?jw-coP&LIU1LPt&UxnFqsM%X*)FJgZlq#?HF8Y(GqW4$FK)+=CJ%yv5b?I z8J6EX`<~d5DhB3gn2ARWU_b`Rf$bx?&li{yzj2yT^wE_n?i8H zR@4jLJq&%}coGv11@*9S^h{K{3aabtS19Hh@yb)g*ImrHqZfnJ)aN*fjF3GT;DReh zITxMdNpv21>F5*zry-iw+fXzxvwRo%J7V<5+g27U7|(N2I_qR z${lHrbp*J@sT&FcNnsr4xON<{sGy2n-ELR6A5>n#S@h-kKwRrD=7t=SMa?)2`wE6y Y&MUhMLs;}mZejZW2Qy1PGqNfG0NiSg$N&HU literal 1366 zcmV-c1*!T$RzVeufq|ER|g5JKvW8;Avl;bmV)lQezVD6NZ@)o!=au2i+l zu2%Fiu_y6Rzu_4t=~_lY95`|3x=4r{C&Z1f!8hQ0@Qm#w9pb#TaW_#LCH2@d`1y%hgZ#FYoJ(e<09O1WGv zL1m0ujJCgWI~p#dGOAYLi&0oC7Go39?oJamm}P0$0pmDM9|jiHFl|xCH4F?b_1zP= z@JV@Vy}G&Cz3`YhR41N>`F8>FY4`H;_+i5e+}R_-M23c+Y_6g8yYjoaCez(hT-x0! zHQ@)(xx2kWJF!v*ZIHlHCD~r-qWF~PI`srct|u5sheB*Hn>t*c;97%NoJJW~wiPUe zSzx(x+J82vJ=BBFa3GsALi~q{_;=4Kes0}i(Ky^3!vRBV@&(Q!kwbLq`|~xK4+hCF zkPz2|A7u87rwWe;GaN0}sNH7}pIo_k_5Ls#m5nSGhYE}Pvttp0y)KG4edS1eIE)0Y zfM;HA$Ecj`7?ms8F+Li^;Sj-Eba&9$B8fx z`^sr&WW04&u-gOP(y!I`l^cV;GSWN#RJ`N2NxkF3u=9EQlnr}srckqny)_6M45i^b z!~|x+bzFd74TrH9#d?IJEH^L}H+V6h?-q#$O+j_7*OvLDJW))~K<87>B09Y%g#V0K z0gV~PtpSXXbCQkjxq|M|e4@(&m9%N@NmZvK6~@gP(#;l?RobYzXN3n@#Thar4j%*m zR;c`OPAVaaO`$?^+&3WART4!xMn#{IRg2WAWl^Jks)ea}B|0V-(U)i^Nid^dF3pT~ zO7U?Q)sPcdRJmC|9)=t(h~5Nhsy;oE&8mUkWb93;NvF)?(tD# zPYWeE09_sym3hWnahuxiaNa*FyuY7(x+`xx%|!Q#?XV_FJdq-4u~uVdv$A9#qnEY7 zwW;wSt^|W>?@lnAjkm|;fU6UTc)m<|K5a2K;Jxzyvv!Ovx9Jw)QIGL9jLcb{@lx@O zlZ6?YUqAa)>`)a0Wb2yC0RI>)2v?Ayuc6k_fMzAkB*5ZHX;d8<$gkddZMV1!F;9C=h{4JL;;Y-X<~zfn*= z?xHkPj9It8W;*Q-b8iJ%L*4(@OBPYYFsPA1v+zsPp}5gq(Dg~g%bH;z_7xDd Y+*fxO#xU#E+{_642lwlPoVqFi00Ww+X#fBK diff --git a/binding.js b/binding.js index b504692..9ad69b6 100644 --- a/binding.js +++ b/binding.js @@ -17,7 +17,7 @@ function isMusl() { // For Node 10 if (!process.report || typeof process.report.getReport !== 'function') { try { - const lddPath = require('child_process').execSync('which ldd').toString().trim() + const lddPath = require('child_process').execSync('which ldd').toString().trim(); return readFileSync(lddPath, 'utf8').includes('musl') } catch (e) { return true @@ -224,72 +224,14 @@ switch (platform) { } break case 'arm': - if (isMusl()) { - localFileExisted = existsSync( - join(__dirname, 'svgr-rs.linux-arm-musleabihf.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./svgr-rs.linux-arm-musleabihf.node') - } else { - nativeBinding = require('@svgr-rs/core-linux-arm-musleabihf') - } - } catch (e) { - loadError = e - } - } else { - localFileExisted = existsSync( - join(__dirname, 'svgr-rs.linux-arm-gnueabihf.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./svgr-rs.linux-arm-gnueabihf.node') - } else { - nativeBinding = require('@svgr-rs/core-linux-arm-gnueabihf') - } - } catch (e) { - loadError = e - } - } - break - case 'riscv64': - if (isMusl()) { - localFileExisted = existsSync( - join(__dirname, 'svgr-rs.linux-riscv64-musl.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./svgr-rs.linux-riscv64-musl.node') - } else { - nativeBinding = require('@svgr-rs/core-linux-riscv64-musl') - } - } catch (e) { - loadError = e - } - } else { - localFileExisted = existsSync( - join(__dirname, 'svgr-rs.linux-riscv64-gnu.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./svgr-rs.linux-riscv64-gnu.node') - } else { - nativeBinding = require('@svgr-rs/core-linux-riscv64-gnu') - } - } catch (e) { - loadError = e - } - } - break - case 's390x': localFileExisted = existsSync( - join(__dirname, 'svgr-rs.linux-s390x-gnu.node') + join(__dirname, 'svgr-rs.linux-arm-gnueabihf.node') ) try { if (localFileExisted) { - nativeBinding = require('./svgr-rs.linux-s390x-gnu.node') + nativeBinding = require('./svgr-rs.linux-arm-gnueabihf.node') } else { - nativeBinding = require('@svgr-rs/core-linux-s390x-gnu') + nativeBinding = require('@svgr-rs/core-linux-arm-gnueabihf') } } catch (e) { loadError = e diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 0272839..a9fae84 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -35,4 +35,9 @@ linked-hash-map = { version = "0.5.6", features = ["serde_impl"] } linked_hash_set = "0.1.4" [dev-dependencies] +codspeed-criterion-compat = "2.7.2" testing = "0.32.5" + +[[bench]] +name = "bench" +harness = false diff --git a/crates/core/benches/bench.rs b/crates/core/benches/bench.rs new file mode 100644 index 0000000..7102405 --- /dev/null +++ b/crates/core/benches/bench.rs @@ -0,0 +1,21 @@ +use std::fs; + +use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; +use svgr_rs::transform; + +pub fn criterion_benchmark(c: &mut Criterion) { + let path = "benches/rspack-logo.svg"; + let rspack_logo = fs::read_to_string(path).unwrap(); + c.bench_function("Rspack logo", |b| { + b.iter(|| { + transform( + rspack_logo.to_string(), + Default::default(), + Default::default(), + ) + }) + }); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/crates/core/benches/rspack-logo.svg b/crates/core/benches/rspack-logo.svg new file mode 100644 index 0000000..545f982 --- /dev/null +++ b/crates/core/benches/rspack-logo.svg @@ -0,0 +1 @@ + \ No newline at end of file