Browse Source

Merge pull request #66 from ian-h-chamberlain/feature/ci-lint-and-fmt

Initial attempt at CI with GitHub Actions
pull/70/head
Meziu 2 years ago committed by GitHub
parent
commit
cdc9c04522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      .github/workflows/ci.yml
  2. 24
      ctru-rs/Cargo.toml
  3. 2
      ctru-rs/examples/network-sockets.rs
  4. 9
      ctru-rs/src/services/reference.rs
  5. 13
      ctru-sys/src/bin/docstring-to-rustdoc.rs

64
.github/workflows/ci.yml

@ -0,0 +1,64 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
env:
# https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
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:
- 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: ${{ matrix.toolchain }}
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 7b70b6b26c4740b9a10ab85b832ee73c41142bbb
- name: Check formatting
run: cargo fmt --all --verbose -- --check
- name: Cargo check
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.

24
ctru-rs/Cargo.toml

@ -36,5 +36,29 @@ default = ["romfs", "big-stack"]
romfs = [] romfs = []
big-stack = [] big-stack = []
# Temporary feature to disable some examples by default,
# until thread support is upstreamed
std-threads = []
[package.metadata.cargo-3ds] [package.metadata.cargo-3ds]
romfs_dir = "examples/romfs" 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"]

2
ctru-rs/examples/network-sockets.rs

@ -43,7 +43,7 @@ fn main() {
} else { } else {
println!("Unable to read stream: {}", e) 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\n<html><body>Hello world</body></html>\r\n"; let response = b"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n<html><body>Hello world</body></html>\r\n";

9
ctru-rs/src/services/reference.rs

@ -16,7 +16,9 @@ impl ServiceReference {
S: FnOnce() -> crate::Result<()>, S: FnOnce() -> crate::Result<()>,
E: Fn() + Send + Sync + 'static, 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 { if *value == 0 {
start()?; start()?;
@ -35,7 +37,10 @@ impl ServiceReference {
impl Drop for ServiceReference { impl Drop for ServiceReference {
fn drop(&mut self) { 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; *value -= 1;
if *value == 0 { if *value == 0 {
(self.close)(); (self.close)();

13
ctru-sys/src/bin/docstring-to-rustdoc.rs

@ -19,8 +19,8 @@
//! The followings are _partially_ transformed to Rustdoc format: //! The followings are _partially_ transformed to Rustdoc format:
//! * `@param` //! * `@param`
use std::{env, fs, io};
use std::path::Path; use std::path::Path;
use std::{env, fs, io};
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
@ -32,9 +32,8 @@ fn main() -> io::Result<()> {
.lines() .lines()
.map(|v| { .map(|v| {
// Only modify lines with the following structure: `` #[doc ... ] `` // 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 v.replace("@brief", "")
.replace("@brief", "")
// Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...`` // Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...``
// Will improve in the future // Will improve in the future
.replace("@param", "* ") .replace("@param", "* ")
@ -54,9 +53,7 @@ fn main() -> io::Result<()> {
String::from(v) String::from(v)
} }
}) })
.map(|v| { .map(|v| v + "\n")
v + "\n"
})
.collect::<String>(); .collect::<String>();
let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old"; 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)?; fs::remove_file(&old_bindings_path)?;
Ok(()) Ok(())
} }

Loading…
Cancel
Save