From 158e6a5924be034fe0f66003d6148074b68a1920 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:12:40 -0400 Subject: [PATCH 01/11] Set up reusable workflow and add doctests --- .github/workflows/ci.yml | 50 +++++++++++++------------------------ .github/workflows/setup.yml | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/setup.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 102c704..fb4d218 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,6 @@ on: - master workflow_dispatch: -env: - # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html - CARGO_UNSTABLE_SPARSE_REGISTRY: "true" - jobs: lint: strategy: @@ -25,38 +21,10 @@ jobs: # But if latest nightly fails, allow the workflow to continue continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest - container: devkitpro/devkitarm steps: - # https://github.com/nektos/act/issues/917#issuecomment-1074421318 - - if: ${{ env.ACT }} - name: Hack container for local development - run: | - curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - - sudo apt-get install -y nodejs - - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Setup default Rust toolchain - uses: actions-rs/toolchain@v1 + - uses: ./.github/workflows/setup.yml with: - components: clippy, rustfmt, rust-src - profile: minimal toolchain: ${{ matrix.toolchain }} - default: true - - - name: Install build tools for host - run: sudo apt-get update && sudo apt-get install -y build-essential - - - name: Install cargo-3ds - uses: actions-rs/cargo@v1 - with: - command: install - # TODO: this should probably just be a released version from crates.io - # once cargo-3ds gets published somewhere... - args: >- - --git https://github.com/rust3ds/cargo-3ds - --rev 7b70b6b26c4740b9a10ab85b832ee73c41142bbb - name: Check formatting run: cargo fmt --all --verbose -- --check @@ -68,5 +36,21 @@ jobs: # feature, but https://github.com/actions/runner/issues/2341 means we # can't have both that *and* colored output. + doctests: + strategy: + matrix: + toolchain: + - nightly-2023-01-13 + - nightly + continue-on-error: ${{ matrix.toolchain == 'nightly' }} + runs-on: ubuntu-latest + steps: + - uses: ./.github/workflows/setup.yml + with: + toolchain: ${{ matrix.toolchain }} + + - name: Build doc tests + run: cargo 3ds test --doc --verbose + # TODO: it would be nice to actually build 3dsx for examples/tests, etc. # and run it somehow, but exactly how remains to be seen. diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml new file mode 100644 index 0000000..bfdc8de --- /dev/null +++ b/.github/workflows/setup.yml @@ -0,0 +1,48 @@ +name: Setup + +on: + workflow_call: + inputs: + toolchain: + required: true + type: string + +env: + # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + +jobs: + setup: + runs-on: ubuntu-latest + container: devkitpro/devkitarm + steps: + # https://github.com/nektos/act/issues/917#issuecomment-1074421318 + - if: ${{ env.ACT }} + name: Hack container for local development + run: | + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - + sudo apt-get install -y nodejs + + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Setup default Rust toolchain + # Use this helper + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy, rustfmt, rust-src + toolchain: ${{ matrix.toolchain }} + + - name: Install build tools for host + run: sudo apt-get update && sudo apt-get install -y build-essential + + - name: Install cargo-3ds + uses: actions-rs/cargo@v1 + with: + command: install + # TODO: this should probably just be a released version from crates.io + # once cargo-3ds gets published somewhere... + # also switch to hash once feature/doctests gets merged + args: >- + --git https://github.com/rust3ds/cargo-3ds + --rev feature/doctests From 6c6c09439953b2ed89e2047d45bd9330e51ec285 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:13:14 -0400 Subject: [PATCH 02/11] Fix build errors in FS examples --- ctru-rs/src/services/fs.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 45f9efb..058eb14 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -123,6 +123,9 @@ pub struct Archive { /// Create a new file and write bytes to it: /// /// ```no_run +/// # use std::error::Error; +/// # fn main() -> Result<(), Box> { +/// # /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// @@ -131,11 +134,17 @@ pub struct Archive { /// /// let mut file = File::create(&sdmc, "/foo.txt")?; /// file.write_all(b"Hello, world!")?; +/// # +/// # Ok(()) +/// # } /// ``` /// /// Read the contents of a file into a `String`:: /// /// ```no_run +/// # use std::error::Error; +/// # fn main() -> Result<(), Box> { +/// # /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// @@ -146,12 +155,18 @@ pub struct Archive { /// let mut contents = String::new(); /// file.read_to_string(&mut contents)?; /// assert_eq!(contents, "Hello, world!"); +/// # +/// # Ok(()) +/// # } /// ``` /// /// It can be more efficient to read the contents of a file with a buffered /// `Read`er. This can be accomplished with `BufReader`: /// /// ```no_run +/// # use std::error::Error; +/// # fn main() -> Result<(), Box> { +/// # /// use std::io::BufReader; /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; @@ -164,6 +179,9 @@ pub struct Archive { /// let mut contents = String::new(); /// buf_reader.read_to_string(&mut contents)?; /// assert_eq!(contents, "Hello, world!"); +/// # +/// # Ok(()) +/// # } /// ``` pub struct File { handle: u32, From 131a53582698c50c221a4226ffa6164e3c8c3d2e Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:13:43 -0400 Subject: [PATCH 03/11] Add basic CODEOWNERS file --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..0163641 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @rust3ds/active From cabd3acf1a49a1ba59df6b964fc7381c9d0b0d1a Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:22:20 -0400 Subject: [PATCH 04/11] Try using a composite action instead of workflow --- .github/actions/setup/action.yml | 45 ++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 10 +++++-- .github/workflows/setup.yml | 48 -------------------------------- 3 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 .github/actions/setup/action.yml delete mode 100644 .github/workflows/setup.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..2f33006 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,45 @@ +name: Setup +description: Set up CI environment for Rust + 3DS development + +inputs: + toolchain: + description: The Rust toolchain to use for the steps + required: true + default: nightly + +runs: + using: composite + steps: + # https://github.com/nektos/act/issues/917#issuecomment-1074421318 + - if: ${{ env.ACT }} + shell: bash + name: Hack container for local development + run: | + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - + sudo apt-get install -y nodejs + + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Setup default Rust toolchain + # Use this helper action so we get matcher support + # https://github.com/actions-rust-lang/setup-rust-toolchain/pull/15 + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy, rustfmt, rust-src + toolchain: ${{ matrix.toolchain }} + + - name: Install build tools for host + shell: bash + run: sudo apt-get update && sudo apt-get install -y build-essential + + - name: Install cargo-3ds + uses: actions-rs/cargo@v1 + with: + command: install + # TODO: this should probably just be a released version from crates.io + # once cargo-3ds gets published somewhere... + # also switch to hash once feature/doctests gets merged + args: >- + --git https://github.com/rust3ds/cargo-3ds + --rev feature/doctests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb4d218..7b44782 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,10 @@ on: - master workflow_dispatch: +env: + # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + jobs: lint: strategy: @@ -21,8 +25,9 @@ jobs: # But if latest nightly fails, allow the workflow to continue continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest + container: devkitpro/devkitarm steps: - - uses: ./.github/workflows/setup.yml + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} @@ -44,8 +49,9 @@ jobs: - nightly continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest + container: devkitpro/devkitarm steps: - - uses: ./.github/workflows/setup.yml + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml deleted file mode 100644 index bfdc8de..0000000 --- a/.github/workflows/setup.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Setup - -on: - workflow_call: - inputs: - toolchain: - required: true - type: string - -env: - # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html - CARGO_UNSTABLE_SPARSE_REGISTRY: "true" - -jobs: - setup: - runs-on: ubuntu-latest - container: devkitpro/devkitarm - steps: - # https://github.com/nektos/act/issues/917#issuecomment-1074421318 - - if: ${{ env.ACT }} - name: Hack container for local development - run: | - curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - - sudo apt-get install -y nodejs - - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Setup default Rust toolchain - # Use this helper - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - components: clippy, rustfmt, rust-src - toolchain: ${{ matrix.toolchain }} - - - name: Install build tools for host - run: sudo apt-get update && sudo apt-get install -y build-essential - - - name: Install cargo-3ds - uses: actions-rs/cargo@v1 - with: - command: install - # TODO: this should probably just be a released version from crates.io - # once cargo-3ds gets published somewhere... - # also switch to hash once feature/doctests gets merged - args: >- - --git https://github.com/rust3ds/cargo-3ds - --rev feature/doctests From 38d89bd170f0264e1b24502db411b5e46c1df8e6 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:25:07 -0400 Subject: [PATCH 05/11] Checkout branch before trying to use its code --- .github/actions/setup/action.yml | 5 +---- .github/workflows/ci.yml | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 2f33006..728dd02 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -18,16 +18,13 @@ runs: curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs - - name: Checkout branch - uses: actions/checkout@v2 - - name: Setup default Rust toolchain # Use this helper action so we get matcher support # https://github.com/actions-rust-lang/setup-rust-toolchain/pull/15 uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: clippy, rustfmt, rust-src - toolchain: ${{ matrix.toolchain }} + toolchain: ${{ inputs.toolchain }} - name: Install build tools for host shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b44782..b0bfc23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: runs-on: ubuntu-latest container: devkitpro/devkitarm steps: + - name: Checkout branch + uses: actions/checkout@v2 + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} @@ -51,6 +54,9 @@ jobs: runs-on: ubuntu-latest container: devkitpro/devkitarm steps: + - name: Checkout branch + uses: actions/checkout@v2 + - uses: ./.github/actions/setup with: toolchain: ${{ matrix.toolchain }} From 271dba9fd8959770e497928d8cc089e5cfb0879c Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:27:17 -0400 Subject: [PATCH 06/11] Fix hash for installing cargo-3ds --- .github/actions/setup/action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 728dd02..1833988 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -36,7 +36,8 @@ runs: command: install # TODO: this should probably just be a released version from crates.io # once cargo-3ds gets published somewhere... - # also switch to hash once feature/doctests gets merged + # + # also switch to master hash once feature/doctests gets merged args: >- --git https://github.com/rust3ds/cargo-3ds - --rev feature/doctests + --rev 5a06e64307499ffe681453e7d88d7ee986054eb7 From 336887aa180c8553e9a13b7f0fdb23c267291b1c Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 13:52:54 -0400 Subject: [PATCH 07/11] Clear -Dwarnings flag from toolchain --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0bfc23..8ff1525 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ on: env: # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + # actions-rust-lang/setup-rust-toolchain sets some default RUSTFLAGS + RUSTFLAGS: "" jobs: lint: @@ -22,6 +24,7 @@ jobs: - nightly-2023-01-13 # Check for breakage on latest nightly - nightly + # But if latest nightly fails, allow the workflow to continue continue-on-error: ${{ matrix.toolchain == 'nightly' }} runs-on: ubuntu-latest From 0f2add4c6d98d7b9353ef7d503b3afaadadf3994 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 14:01:02 -0400 Subject: [PATCH 08/11] Try to fix PATH for devkitarm tools --- .github/actions/setup/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 1833988..30da46e 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -41,3 +41,8 @@ runs: args: >- --git https://github.com/rust3ds/cargo-3ds --rev 5a06e64307499ffe681453e7d88d7ee986054eb7 + + - name: Set PATH to include devkitARM + shell: bash + # For some reason devkitARM/bin is not part of the default PATH in the container + run: echo "${DEVKITARM}/bin" >> $GITHUB_PATH From c40cf5a94e13f202188a5cd708dc201194aa342f Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 3 Apr 2023 14:14:56 -0400 Subject: [PATCH 09/11] Deduplicate warnings from lint vs build jobs --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ff1525..20a22ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,12 @@ jobs: with: toolchain: ${{ matrix.toolchain }} + - name: Hide duplicate warnings from lint job + if: ${{ matrix.toolchain == 'nightly' }} + run: | + echo "::remove-matcher owner=clippy::" + echo "::remove-matcher owner=rustfmt::" + - name: Check formatting run: cargo fmt --all --verbose -- --check @@ -64,6 +70,9 @@ jobs: with: toolchain: ${{ matrix.toolchain }} + - name: Hide duplicated warnings from lint job + run: echo "::remove-matcher owner=clippy::" + - name: Build doc tests run: cargo 3ds test --doc --verbose From 3a8b05054f1363b89d292c73d6a2e4585851203d Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 14 Apr 2023 14:50:45 -0400 Subject: [PATCH 10/11] Update cargo-3ds hash to latest --- .github/actions/setup/action.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 30da46e..a86d6f6 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -36,11 +36,9 @@ runs: command: install # TODO: this should probably just be a released version from crates.io # once cargo-3ds gets published somewhere... - # - # also switch to master hash once feature/doctests gets merged args: >- --git https://github.com/rust3ds/cargo-3ds - --rev 5a06e64307499ffe681453e7d88d7ee986054eb7 + --rev 78a652fdfb01e2614a792d1a56b10c980ee1dae9 - name: Set PATH to include devkitARM shell: bash From 7d70add8f317caea68e9ff3a64f17a3c150f3ef1 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Fri, 14 Apr 2023 15:08:37 -0400 Subject: [PATCH 11/11] Fix mutability issues after merge of master --- ctru-rs/src/services/fs.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 962e048..e3f45b0 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -103,7 +103,7 @@ pub struct Fs(()); /// ```no_run /// use ctru::services::fs::Fs; /// -/// let fs = Fs::init().unwrap(); +/// let mut fs = Fs::init().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap(); /// ``` pub struct Archive { @@ -129,10 +129,10 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::init()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// -/// let mut file = File::create(&sdmc, "/foo.txt")?; +/// let mut file = File::create(&mut sdmc, "/foo.txt")?; /// file.write_all(b"Hello, world!")?; /// # /// # Ok(()) @@ -148,8 +148,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::init()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let mut file = File::open(&sdmc, "/foo.txt")?; /// let mut contents = String::new(); @@ -171,8 +171,8 @@ pub struct Archive { /// use std::io::prelude::*; /// use ctru::services::fs::{Fs, File}; /// -/// let fs = Fs::init()?; -/// let sdmc = fs.sdmc()?; +/// let mut fs = Fs::init()?; +/// let mut sdmc = fs.sdmc()?; /// /// let file = File::open(&sdmc, "/foo.txt")?; /// let mut buf_reader = BufReader::new(file); @@ -227,8 +227,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let fs = Fs::init().unwrap(); -/// let sdmc_archive = fs.sdmc().unwrap(); +/// let mut fs = Fs::init().unwrap(); +/// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .archive(&sdmc_archive) @@ -242,8 +242,8 @@ pub struct Metadata { /// ```no_run /// use ctru::services::fs::{Fs, OpenOptions}; /// -/// let fs = Fs::init().unwrap(); -/// let sdmc_archive = fs.sdmc().unwrap(); +/// let mut fs = Fs::init().unwrap(); +/// let mut sdmc_archive = fs.sdmc().unwrap(); /// let file = OpenOptions::new() /// .read(true) /// .write(true) @@ -369,8 +369,8 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let fs = Fs::init().unwrap(); - /// let sdmc_archive = fs.sdmc().unwrap(); + /// let mut fs = Fs::init().unwrap(); + /// let mut sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn open>(arch: &Archive, path: P) -> IoResult { @@ -398,9 +398,9 @@ impl File { /// ```no_run /// use ctru::services::fs::{Fs, File}; /// - /// let fs = Fs::init().unwrap(); - /// let sdmc_archive = fs.sdmc().unwrap(); - /// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap(); + /// let mut fs = Fs::init().unwrap(); + /// let mut sdmc_archive = fs.sdmc().unwrap(); + /// let mut f = File::create(&mut sdmc_archive, "/foo.txt").unwrap(); /// ``` pub fn create>(arch: &mut Archive, path: P) -> IoResult { OpenOptions::new()