Skip to content

Commit

Permalink
Merge branch 'master' into fix/build-doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-h-chamberlain authored and Meziu committed Apr 17, 2023
2 parents 474cb2e + 94a453e commit c18ed6f
Show file tree
Hide file tree
Showing 52 changed files with 451 additions and 443 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @rust3ds/active
46 changes: 46 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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: 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: ${{ inputs.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...
args: >-
--git https://github.com/rust3ds/cargo-3ds
--rev 78a652fdfb01e2614a792d1a56b10c980ee1dae9
- 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
56 changes: 32 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,41 +24,24 @@ 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
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/actions/setup
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: 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
Expand All @@ -68,5 +53,28 @@ 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
container: devkitpro/devkitarm
steps:
- name: Checkout branch
uses: actions/checkout@v2

- uses: ./.github/actions/setup
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

# TODO: it would be nice to actually build 3dsx for examples/tests, etc.
# and run it somehow, but exactly how remains to be seen.
4 changes: 0 additions & 4 deletions AUTHORS.md

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (C) Rust 3DS Project authors, 2015-2016

As with the original ctrulib, this library is licensed under zlib. This
applies to every file in the tree, unless otherwise noted.

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
33 changes: 5 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,10 @@ This repository is organized as follows:
(displayed when built with `-vv`) will be issued if the build script detects
a mismatch or is unable to check the installed `libctru` version.

## License
## Original version

Copyright (C) Rust 3DS Project authors, 2015-2016

See AUTHORS.md.

As with the original ctrulib, this library is licensed under zlib. This
applies to every file in the tree, unless otherwise noted.

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.

Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See [LICENSE-APACHE](https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE), [LICENSE-MIT](https://github.com/rust-lang/rust/blob/master/LICENSE-MIT), and [COPYRIGHT](https://github.com/rust-lang/rust/blob/master/COPYRIGHT) for details.
This project is based on the efforts the original authors:
* [Eidolon](https://github.com/HybridEidolon)
* [FenrirWolf](https://github.com/FenrirWolf)

The old version is archived [here](https://github.com/rust3ds/ctru-rs-old).
4 changes: 2 additions & 2 deletions ctru-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
authors = ["Ronald Kinard <[email protected]>"]
authors = [ "Rust3DS Org", "Ronald Kinard <[email protected]>" ]
description = "A safe wrapper around smealum's ctrulib."
license = "Zlib"
name = "ctru-rs"
Expand All @@ -15,7 +15,7 @@ name = "ctru"
cfg-if = "1.0"
ctru-sys = { path = "../ctru-sys", version = "21.2" }
const-zero = "0.1.0"
linker-fix-3ds = { git = "https://github.com/rust3ds/rust-linker-fix-3ds.git" }
shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" }
pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" }
libc = "0.2.121"
bitflags = "1.0.0"
Expand Down
16 changes: 6 additions & 10 deletions ctru-rs/examples/audio-filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ fn fill_buffer(audio_data: &mut [u8], frequency: f32) {
fn main() {
ctru::use_panic_handler();

let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.top_screen.borrow_mut());

let mut note: usize = 4;

Expand Down Expand Up @@ -68,12 +68,12 @@ fn main() {
let mut wave_info1 = Wave::new(audio_data1, AudioFormat::PCM16Stereo, false);
let mut wave_info2 = Wave::new(audio_data2, AudioFormat::PCM16Stereo, false);

let mut ndsp = Ndsp::init().expect("Couldn't obtain NDSP controller");
let mut ndsp = Ndsp::new().expect("Couldn't obtain NDSP controller");

// This line isn't needed since the default NDSP configuration already sets the output mode to `Stereo`
ndsp.set_output_mode(OutputMode::Stereo);

let channel_zero = ndsp.channel(0).unwrap();
let mut channel_zero = ndsp.channel(0).unwrap();
channel_zero.set_interpolation(InterpolationType::Linear);
channel_zero.set_sample_rate(SAMPLE_RATE as f32);
channel_zero.set_format(AudioFormat::PCM16Stereo);
Expand Down Expand Up @@ -154,10 +154,6 @@ fn main() {
altern = !altern;
}

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();

//Wait for VBlank
gfx.wait_for_vblank();
}
Expand Down
11 changes: 4 additions & 7 deletions ctru-rs/examples/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use ctru::prelude::*;
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let console = Console::init(gfx.top_screen.borrow_mut());
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
let console = Console::new(gfx.top_screen.borrow_mut());

println!("Hi there! Try pressing a button");
println!("\x1b[29;16HPress Start to exit");
Expand Down Expand Up @@ -63,9 +63,6 @@ fn main() {
// Save our current key presses for the next frame
old_keys = keys;

// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
32 changes: 14 additions & 18 deletions ctru-rs/examples/camera-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ const WAIT_TIMEOUT: Duration = Duration::from_millis(300);
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().expect("Failed to initialize Apt service.");
let hid = Hid::init().expect("Failed to initialize Hid service.");
let gfx = Gfx::init().expect("Failed to initialize GFX service.");
let apt = Apt::new().expect("Failed to initialize Apt service.");
let mut hid = Hid::new().expect("Failed to initialize Hid service.");
let gfx = Gfx::new().expect("Failed to initialize GFX service.");

gfx.top_screen.borrow_mut().set_double_buffering(true);
gfx.top_screen
.borrow_mut()
.set_framebuffer_format(FramebufferFormat::Rgb565);
gfx.bottom_screen.borrow_mut().set_double_buffering(false);
let _console = Console::init(gfx.bottom_screen.borrow_mut());
let mut top_screen = gfx.top_screen.borrow_mut();
top_screen.set_double_buffering(true);
top_screen.set_framebuffer_format(FramebufferFormat::Rgb565);

let _console = Console::new(gfx.bottom_screen.borrow_mut());

let mut keys_down;

println!("Initializing camera");

let mut cam = Cam::init().expect("Failed to initialize CAM service.");
let mut cam = Cam::new().expect("Failed to initialize CAM service.");

{
let camera = &mut cam.outer_right_cam;
Expand Down Expand Up @@ -86,15 +85,12 @@ fn main() {
cam.play_shutter_sound(ShutterSound::Normal)
.expect("Failed to play shutter sound");

rotate_image_to_screen(
&buf,
gfx.top_screen.borrow_mut().raw_framebuffer().ptr,
WIDTH,
HEIGHT,
);
rotate_image_to_screen(&buf, top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT);

// We will only flush the "camera" screen, since the other screen is handled by `Console`
top_screen.flush_buffer();
top_screen.swap_buffers();

gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank();
}
}
Expand Down
18 changes: 8 additions & 10 deletions ctru-rs/examples/file-explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ use std::path::{Path, PathBuf};
fn main() {
ctru::use_panic_handler();

let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap();
let gfx = Gfx::init().unwrap();
let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();

#[cfg(all(feature = "romfs", romfs_exists))]
let _romfs = ctru::services::romfs::RomFS::init().unwrap();
let _romfs = ctru::services::romfs::RomFS::new().unwrap();

FileExplorer::init(&apt, &hid, &gfx).run();
FileExplorer::new(&apt, &mut hid, &gfx).run();
}

struct FileExplorer<'a> {
apt: &'a Apt,
hid: &'a Hid,
hid: &'a mut Hid,
gfx: &'a Gfx,
console: Console<'a>,
path: PathBuf,
Expand All @@ -32,10 +32,10 @@ struct FileExplorer<'a> {
}

impl<'a> FileExplorer<'a> {
fn init(apt: &'a Apt, hid: &'a Hid, gfx: &'a Gfx) -> Self {
fn new(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self {
let mut top_screen = gfx.top_screen.borrow_mut();
top_screen.set_wide_mode(true);
let console = Console::init(top_screen);
let console = Console::new(top_screen);

FileExplorer {
apt,
Expand Down Expand Up @@ -68,8 +68,6 @@ impl<'a> FileExplorer<'a> {
self.get_input_and_run(Self::set_exact_path);
}

self.gfx.flush_buffers();
self.gfx.swap_buffers();
self.gfx.wait_for_vblank();
}
}
Expand Down
Loading

0 comments on commit c18ed6f

Please sign in to comment.