From c8dbd185c0135a5eed718906d1fb7d7a8ede8e8f Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Sun, 4 May 2025 09:41:51 +0200 Subject: [PATCH] Allow compiling `uucore` with `wasm32-unknown-unknown` (#7840) and fix the build --- .github/workflows/CICD.yml | 18 ++++++++++++------ src/uu/dd/Cargo.toml | 7 ++++++- src/uucore/src/lib/lib.rs | 1 + src/uucore/src/lib/mods.rs | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index e35abb637..80b2fa240 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -513,7 +513,7 @@ jobs: fail-fast: false matrix: job: - # - { os , target , cargo-options , features , use-cross , toolchain, skip-tests, workspace-tests } + # - { os , target , cargo-options , default-features, features , use-cross , toolchain, skip-tests, workspace-tests, skip-package, skip-publish } - { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf , features: feat_os_unix_gnueabihf , use-cross: use-cross , skip-tests: true } - { os: ubuntu-24.04-arm , target: aarch64-unknown-linux-gnu , features: feat_os_unix_gnueabihf } - { os: ubuntu-latest , target: aarch64-unknown-linux-musl , features: feat_os_unix , use-cross: use-cross , skip-tests: true } @@ -524,13 +524,14 @@ jobs: - { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: "feat_os_unix,uudoc" , use-cross: no, workspace-tests: true } - { os: ubuntu-latest , target: x86_64-unknown-linux-musl , features: feat_os_unix , use-cross: use-cross } - { os: ubuntu-latest , target: x86_64-unknown-redox , features: feat_os_unix_redox , use-cross: redoxer , skip-tests: true } + - { os: ubuntu-latest , target: wasm32-unknown-unknown , default-features: false, features: uucore/format, skip-tests: true, skip-package: true, skip-publish: true } - { os: macos-latest , target: aarch64-apple-darwin , features: feat_os_macos, workspace-tests: true } # M1 CPU - { os: macos-13 , target: x86_64-apple-darwin , features: feat_os_macos, workspace-tests: true } - { os: windows-latest , target: i686-pc-windows-msvc , features: feat_os_windows } # TODO: Re-enable after rust-onig release: https://github.com/rust-onig/rust-onig/issues/193 # - { os: windows-latest , target: x86_64-pc-windows-gnu , features: feat_os_windows } - { os: windows-latest , target: x86_64-pc-windows-msvc , features: feat_os_windows } - - { os: windows-latest , target: aarch64-pc-windows-msvc , features: feat_os_windows, use-cross: use-cross , skip-tests: true } + - { os: windows-latest , target: aarch64-pc-windows-msvc , features: feat_os_windows, use-cross: use-cross , skip-tests: true } steps: - uses: actions/checkout@v4 with: @@ -620,6 +621,10 @@ jobs: CARGO_FEATURES_OPTION='' ; if [ -n "${{ matrix.job.features }}" ]; then CARGO_FEATURES_OPTION='--features=${{ matrix.job.features }}' ; fi outputs CARGO_FEATURES_OPTION + # * CARGO_DEFAULT_FEATURES_OPTION + CARGO_DEFAULT_FEATURES_OPTION='' ; + if [ "${{ matrix.job.default-features }}" == "false" ]; then CARGO_DEFAULT_FEATURES_OPTION='--no-default-features' ; fi + outputs CARGO_DEFAULT_FEATURES_OPTION # * CARGO_CMD CARGO_CMD='cross' CARGO_CMD_OPTIONS='+${{ env.RUST_MIN_SRV }}' @@ -753,20 +758,20 @@ jobs: # dependencies echo "## dependency list" cargo fetch --locked --quiet - cargo tree --locked --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} --no-dedupe -e=no-dev --prefix=none | grep -vE "$PWD" | sort --unique + cargo tree --locked --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} ${{ steps.vars.outputs.CARGO_DEFAULT_FEATURES_OPTION }} --no-dedupe -e=no-dev --prefix=none | grep -vE "$PWD" | sort --unique - name: Build shell: bash run: | ## Build ${{ steps.vars.outputs.CARGO_CMD }} ${{ steps.vars.outputs.CARGO_CMD_OPTIONS }} build --release \ - --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} + --target=${{ matrix.job.target }} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} ${{ steps.vars.outputs.CARGO_DEFAULT_FEATURES_OPTION }} - name: Test if: matrix.job.skip-tests != true shell: bash run: | ## Test ${{ steps.vars.outputs.CARGO_CMD }} ${{ steps.vars.outputs.CARGO_CMD_OPTIONS }} test --target=${{ matrix.job.target }} \ - ${{ steps.vars.outputs.CARGO_TEST_OPTIONS}} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} + ${{ steps.vars.outputs.CARGO_TEST_OPTIONS}} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} ${{ steps.vars.outputs.CARGO_DEFAULT_FEATURES_OPTION }} env: RUST_BACKTRACE: "1" - name: Test individual utilities @@ -784,6 +789,7 @@ jobs: name: ${{ env.PROJECT_NAME }}-${{ matrix.job.target }}${{ steps.vars.outputs.ARTIFACTS_SUFFIX }} path: target/${{ matrix.job.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }} - name: Package + if: matrix.job.skip-package != true shell: bash run: | ## Package artifact(s) @@ -819,7 +825,7 @@ jobs: fi - name: Publish uses: softprops/action-gh-release@v2 - if: steps.vars.outputs.DEPLOY + if: steps.vars.outputs.DEPLOY && matrix.job.skip-publish != true with: draft: true files: | diff --git a/src/uu/dd/Cargo.toml b/src/uu/dd/Cargo.toml index 38a216b03..04f051799 100644 --- a/src/uu/dd/Cargo.toml +++ b/src/uu/dd/Cargo.toml @@ -21,7 +21,12 @@ path = "src/dd.rs" clap = { workspace = true } gcd = { workspace = true } libc = { workspace = true } -uucore = { workspace = true, features = ["format", "parser", "quoting-style"] } +uucore = { workspace = true, features = [ + "format", + "parser", + "quoting-style", + "fs", +] } thiserror = { workspace = true } [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index ee0fd8525..dbf3924aa 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -24,6 +24,7 @@ pub use uucore_procs::*; // * cross-platform modules pub use crate::mods::display; pub use crate::mods::error; +#[cfg(feature = "fs")] pub use crate::mods::io; pub use crate::mods::line_ending; pub use crate::mods::os; diff --git a/src/uucore/src/lib/mods.rs b/src/uucore/src/lib/mods.rs index 29508e31a..a5570e8e2 100644 --- a/src/uucore/src/lib/mods.rs +++ b/src/uucore/src/lib/mods.rs @@ -6,6 +6,7 @@ pub mod display; pub mod error; +#[cfg(feature = "fs")] pub mod io; pub mod line_ending; pub mod os;