From 2bfa0a85ac16eff06eef80b4fc1ea5193f49c6e0 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sun, 17 Jul 2022 11:09:42 -0400 Subject: [PATCH 1/8] Initial attempt at CI with GitHub Actions --- .github/workflows/ci.yml | 64 ++++++++++++++++++++++++ ctru-rs/examples/network-sockets.rs | 2 +- ctru-rs/src/services/reference.rs | 9 +++- ctru-sys/src/bin/docstring-to-rustdoc.rs | 11 ++-- 4 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b8e4db3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +env: + # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + +jobs: + lint: + runs-on: ubuntu-latest + container: devkitpro/devkitarm + steps: + - if: ${{ env.ACT }} + name: Hack container for local development + run: | + curl -fsSL https://deb.nodesource.com/setup_18.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 + with: + components: clippy, rustfmt, rust-src + profile: minimal + toolchain: nightly + default: true + + - name: Install build tools for host + run: 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 913645665391ea715bc96910bda35f98a4536a6e + + - name: Check formatting + run: cargo fmt --all --verbose -- --check + + # For some reason, `cargo clippy` doesn't seem to work properly with + # -Zbuild-std (and thus with `cargo 3ds`). Maybe would be helped by + # https://github.com/rust3ds/cargo-3ds/pull/21 ? + - name: Cargo check + run: cargo 3ds check --color=always --workspace --verbose --all-targets + env: + RUSTFLAGS: + --deny=warnings + + # TODO: it would be nice to actually build 3dsx for examples/tests, etc. + # and run it somehow, but exactly how remains to be seen. Also, we probably + # need the std::thread PR to land before a lot of the examples are runnable. diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index ac8953d..6526d41 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -43,7 +43,7 @@ fn main() { } else { println!("Unable to read stream: {}", e) } - }, + } } let response = b"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nHello world\r\n"; diff --git a/ctru-rs/src/services/reference.rs b/ctru-rs/src/services/reference.rs index 7fac227..41319a7 100644 --- a/ctru-rs/src/services/reference.rs +++ b/ctru-rs/src/services/reference.rs @@ -16,7 +16,9 @@ impl ServiceReference { S: FnOnce() -> crate::Result<()>, E: Fn() + Send + Sync + 'static, { - let mut value = counter.lock().expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning + let mut value = counter + .lock() + .expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning if *value == 0 { start()?; @@ -35,7 +37,10 @@ impl ServiceReference { impl Drop for ServiceReference { fn drop(&mut self) { - let mut value = self.counter.lock().expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning + let mut value = self + .counter + .lock() + .expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning *value -= 1; if *value == 0 { (self.close)(); diff --git a/ctru-sys/src/bin/docstring-to-rustdoc.rs b/ctru-sys/src/bin/docstring-to-rustdoc.rs index b7c7cb9..a843a1b 100644 --- a/ctru-sys/src/bin/docstring-to-rustdoc.rs +++ b/ctru-sys/src/bin/docstring-to-rustdoc.rs @@ -19,8 +19,8 @@ //! The followings are _partially_ transformed to Rustdoc format: //! * `@param` -use std::{env, fs, io}; use std::path::Path; +use std::{env, fs, io}; fn main() -> io::Result<()> { let args: Vec = env::args().collect(); @@ -33,8 +33,7 @@ fn main() -> io::Result<()> { .map(|v| { // Only modify lines with the following structure: `` #[doc ... ] `` if v.trim_start().starts_with("#[doc") && v.trim_end().ends_with("]") { - v - .replace("@brief", "") + v.replace("@brief", "") // Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...`` // Will improve in the future .replace("@param", "* ") @@ -54,9 +53,7 @@ fn main() -> io::Result<()> { String::from(v) } }) - .map(|v| { - v + "\n" - }) + .map(|v| v + "\n") .collect::(); let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old"; @@ -67,4 +64,4 @@ fn main() -> io::Result<()> { fs::remove_file(&old_bindings_path)?; Ok(()) -} \ No newline at end of file +} From c9c76eae18f4ad33840b0f42c7149c4bdeac7728 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sun, 17 Jul 2022 11:17:05 -0400 Subject: [PATCH 2/8] Remove node hack that was for local testing --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8e4db3..b219400 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,12 +17,6 @@ jobs: runs-on: ubuntu-latest container: devkitpro/devkitarm steps: - - if: ${{ env.ACT }} - name: Hack container for local development - run: | - curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - - sudo apt-get install -y nodejs - - name: Checkout branch uses: actions/checkout@v2 From 3511b6540f71dcd239d8ee5efd3ddc40583ae481 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sat, 6 Aug 2022 22:59:21 -0400 Subject: [PATCH 3/8] Fix lint error and allow failure on latest nightly --- .github/workflows/ci.yml | 21 +++++++++++++-------- ctru-rs/Cargo.toml | 24 ++++++++++++++++++++++++ ctru-sys/src/bin/docstring-to-rustdoc.rs | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b219400..5b59fce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,15 @@ env: jobs: lint: + strategy: + matrix: + toolchain: + # Run against a "known good" nightly + - nightly-2022-07-18 + # 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 container: devkitpro/devkitarm steps: @@ -25,7 +34,7 @@ jobs: with: components: clippy, rustfmt, rust-src profile: minimal - toolchain: nightly + toolchain: ${{ matrix.toolchain }} default: true - name: Install build tools for host @@ -39,20 +48,16 @@ jobs: # once cargo-3ds gets published somewhere... args: >- --git https://github.com/rust3ds/cargo-3ds - --rev 913645665391ea715bc96910bda35f98a4536a6e + --rev 7b70b6b26c4740b9a10ab85b832ee73c41142bbb - name: Check formatting run: cargo fmt --all --verbose -- --check - # For some reason, `cargo clippy` doesn't seem to work properly with - # -Zbuild-std (and thus with `cargo 3ds`). Maybe would be helped by - # https://github.com/rust3ds/cargo-3ds/pull/21 ? - name: Cargo check - run: cargo 3ds check --color=always --workspace --verbose --all-targets + run: cargo 3ds clippy --color=always --workspace --verbose --all-targets env: RUSTFLAGS: --deny=warnings # TODO: it would be nice to actually build 3dsx for examples/tests, etc. - # and run it somehow, but exactly how remains to be seen. Also, we probably - # need the std::thread PR to land before a lot of the examples are runnable. + # and run it somehow, but exactly how remains to be seen. diff --git a/ctru-rs/Cargo.toml b/ctru-rs/Cargo.toml index 1016198..3c90be8 100644 --- a/ctru-rs/Cargo.toml +++ b/ctru-rs/Cargo.toml @@ -36,5 +36,29 @@ default = ["romfs", "big-stack"] romfs = [] big-stack = [] +# Temporary feature to disable some examples by default, +# until thread support is upstreamed +std-threads = [] + [package.metadata.cargo-3ds] romfs_dir = "examples/romfs" + +[[example]] +name = "thread-basic" +required-features = ["std-threads"] + +[[example]] +name = "thread-info" +required-features = ["std-threads"] + +[[example]] +name = "thread-locals" +required-features = ["std-threads"] + +[[example]] +name = "futures-basic" +required-features = ["std-threads"] + +[[example]] +name = "futures-tokio" +required-features = ["std-threads"] diff --git a/ctru-sys/src/bin/docstring-to-rustdoc.rs b/ctru-sys/src/bin/docstring-to-rustdoc.rs index a843a1b..21b1185 100644 --- a/ctru-sys/src/bin/docstring-to-rustdoc.rs +++ b/ctru-sys/src/bin/docstring-to-rustdoc.rs @@ -32,7 +32,7 @@ fn main() -> io::Result<()> { .lines() .map(|v| { // Only modify lines with the following structure: `` #[doc ... ] `` - if v.trim_start().starts_with("#[doc") && v.trim_end().ends_with("]") { + if v.trim_start().starts_with("#[doc") && v.trim_end().ends_with(']') { v.replace("@brief", "") // Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...`` // Will improve in the future From 9a6346728d3b6f18e18af5a7297ae097ad7d35be Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Thu, 11 Aug 2022 09:51:40 -0400 Subject: [PATCH 4/8] Allow manual dispatch of CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b59fce..344a534 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - master + workflow_dispatch: env: # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html From 400fd1776c1d09e5810541a149c3acf5d209d7ed Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 19 Aug 2022 11:55:18 +0200 Subject: [PATCH 5/8] Test PR for Github Actions --- ctru-rs/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 5a4aaa9..0048306 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -4,6 +4,8 @@ #![feature(custom_test_frameworks)] #![test_runner(test_runner::run)] +// Test PR + extern "C" fn services_deinit() { unsafe { ctru_sys::psExit(); From fb38d8202f1d9ef3b33caa031470a84679f6a30b Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 19 Aug 2022 11:59:39 +0200 Subject: [PATCH 6/8] Fix formatting --- ctru-rs/examples/network-sockets.rs | 2 +- ctru-rs/examples/system-configuration.rs | 17 +++++++++++++---- ctru-rs/src/lib.rs | 2 -- ctru-rs/src/services/reference.rs | 9 +++++++-- ctru-sys/src/bin/docstring-to-rustdoc.rs | 11 ++++------- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index ac8953d..6526d41 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -43,7 +43,7 @@ fn main() { } else { println!("Unable to read stream: {}", e) } - }, + } } let response = b"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nHello world\r\n"; diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index 47e70c6..6f51c23 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -1,8 +1,8 @@ use ctru::console::Console; use ctru::gfx::Gfx; use ctru::services::apt::Apt; -use ctru::services::hid::{Hid, KeyPad}; use ctru::services::cfgu::Cfgu; +use ctru::services::hid::{Hid, KeyPad}; fn main() { ctru::init(); @@ -12,9 +12,18 @@ fn main() { let cfgu = Cfgu::init().expect("Couldn't obtain CFGU controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); - println!("\x1b[0;0H{}", format!("Region: {:?}", cfgu.get_region().unwrap())); - println!("\x1b[10;0H{}", format!("Language: {:?}", cfgu.get_language().unwrap())); - println!("\x1b[20;0H{}", format!("Model: {:?}", cfgu.get_model().unwrap())); + println!( + "\x1b[0;0H{}", + format!("Region: {:?}", cfgu.get_region().unwrap()) + ); + println!( + "\x1b[10;0H{}", + format!("Language: {:?}", cfgu.get_language().unwrap()) + ); + println!( + "\x1b[20;0H{}", + format!("Model: {:?}", cfgu.get_model().unwrap()) + ); // Main loop while apt.main_loop() { diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 0048306..5a4aaa9 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -4,8 +4,6 @@ #![feature(custom_test_frameworks)] #![test_runner(test_runner::run)] -// Test PR - extern "C" fn services_deinit() { unsafe { ctru_sys::psExit(); diff --git a/ctru-rs/src/services/reference.rs b/ctru-rs/src/services/reference.rs index 7fac227..41319a7 100644 --- a/ctru-rs/src/services/reference.rs +++ b/ctru-rs/src/services/reference.rs @@ -16,7 +16,9 @@ impl ServiceReference { S: FnOnce() -> crate::Result<()>, E: Fn() + Send + Sync + 'static, { - let mut value = counter.lock().expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning + let mut value = counter + .lock() + .expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning if *value == 0 { start()?; @@ -35,7 +37,10 @@ impl ServiceReference { impl Drop for ServiceReference { fn drop(&mut self) { - let mut value = self.counter.lock().expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning + let mut value = self + .counter + .lock() + .expect("Mutex Counter for ServiceReference is poisoned"); // todo: handle poisoning *value -= 1; if *value == 0 { (self.close)(); diff --git a/ctru-sys/src/bin/docstring-to-rustdoc.rs b/ctru-sys/src/bin/docstring-to-rustdoc.rs index b7c7cb9..a843a1b 100644 --- a/ctru-sys/src/bin/docstring-to-rustdoc.rs +++ b/ctru-sys/src/bin/docstring-to-rustdoc.rs @@ -19,8 +19,8 @@ //! The followings are _partially_ transformed to Rustdoc format: //! * `@param` -use std::{env, fs, io}; use std::path::Path; +use std::{env, fs, io}; fn main() -> io::Result<()> { let args: Vec = env::args().collect(); @@ -33,8 +33,7 @@ fn main() -> io::Result<()> { .map(|v| { // Only modify lines with the following structure: `` #[doc ... ] `` if v.trim_start().starts_with("#[doc") && v.trim_end().ends_with("]") { - v - .replace("@brief", "") + v.replace("@brief", "") // Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...`` // Will improve in the future .replace("@param", "* ") @@ -54,9 +53,7 @@ fn main() -> io::Result<()> { String::from(v) } }) - .map(|v| { - v + "\n" - }) + .map(|v| v + "\n") .collect::(); let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old"; @@ -67,4 +64,4 @@ fn main() -> io::Result<()> { fs::remove_file(&old_bindings_path)?; Ok(()) -} \ No newline at end of file +} From d8e36cf68db299c74b4921cb2cc78554cc4b0d41 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 19 Aug 2022 12:05:15 +0200 Subject: [PATCH 7/8] Fix println! statements --- ctru-rs/examples/system-configuration.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index 6f51c23..a5ae05c 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -13,16 +13,16 @@ fn main() { let _console = Console::init(gfx.top_screen.borrow_mut()); println!( - "\x1b[0;0H{}", - format!("Region: {:?}", cfgu.get_region().unwrap()) + "\x1b[0;0HRegion: {:?}", + cfgu.get_region().unwrap() ); println!( - "\x1b[10;0H{}", - format!("Language: {:?}", cfgu.get_language().unwrap()) + "\x1b[10;0HLanguage: {:?}", + cfgu.get_language().unwrap() ); println!( - "\x1b[20;0H{}", - format!("Model: {:?}", cfgu.get_model().unwrap()) + "\x1b[20;0HModel: {:?}", + cfgu.get_model().unwrap() ); // Main loop From 35d7c7832f3a2716a660a445f0c444d24225c508 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 19 Aug 2022 12:09:41 +0200 Subject: [PATCH 8/8] Formatting println! --- ctru-rs/examples/system-configuration.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index a5ae05c..5b04a0e 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -12,18 +12,9 @@ fn main() { let cfgu = Cfgu::init().expect("Couldn't obtain CFGU controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); - println!( - "\x1b[0;0HRegion: {:?}", - cfgu.get_region().unwrap() - ); - println!( - "\x1b[10;0HLanguage: {:?}", - cfgu.get_language().unwrap() - ); - println!( - "\x1b[20;0HModel: {:?}", - cfgu.get_model().unwrap() - ); + println!("\x1b[0;0HRegion: {:?}", cfgu.get_region().unwrap()); + println!("\x1b[10;0HLanguage: {:?}", cfgu.get_language().unwrap()); + println!("\x1b[20;0HModel: {:?}", cfgu.get_model().unwrap()); // Main loop while apt.main_loop() {