Skip to content

Commit

Permalink
move code to the 2018 edition
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
japaric committed Sep 5, 2018
1 parent eba03d8 commit cbec54e
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 21 deletions.
5 changes: 4 additions & 1 deletion ci/exceptions/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cargo-features = ["edition"]

[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]

[dependencies]
rt = { path = "../rt" }
5 changes: 2 additions & 3 deletions ci/exceptions/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#![no_main]
#![no_std]

#[macro_use]
extern crate rt;

use core::intrinsics;

use rt::entry;

entry!(main);

fn main() -> ! {
Expand Down
5 changes: 2 additions & 3 deletions ci/exceptions/app2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#![no_main]
#![no_std]

#[macro_use]
extern crate rt;

use core::intrinsics;

use rt::entry;

entry!(main);

fn main() -> ! {
Expand Down
2 changes: 1 addition & 1 deletion ci/exceptions/rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub unsafe extern "C" fn Reset() -> ! {
pub static RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset;

#[panic_handler]
fn panic(_panic: &PanicInfo) -> ! {
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}

Expand Down
3 changes: 3 additions & 0 deletions ci/main/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
cargo-features = ["edition"]

[package]
edition = '2018'
name = "app"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]
Expand Down
3 changes: 1 addition & 2 deletions ci/main/app2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![no_std]
#![no_main]

#[macro_use]
extern crate rt;
use rt::entry;

entry!(main);

Expand Down
3 changes: 1 addition & 2 deletions ci/main/app3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![no_std]
#![no_main]

#[macro_use]
extern crate rt;
use rt::entry;

entry!(main);

Expand Down
5 changes: 4 additions & 1 deletion ci/main/app4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cargo-features = ["edition"]

[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]

[dependencies]
rt = { path = "../rt2" }
5 changes: 2 additions & 3 deletions ci/main/app4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#![no_main]
#![no_std]

#[macro_use]
extern crate rt;

use core::ptr;

use rt::entry;

entry!(main);

static mut DATA: i32 = 1;
Expand Down
5 changes: 4 additions & 1 deletion ci/main/rt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cargo-features = ["edition"]

[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "rt"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]

[dependencies]
2 changes: 1 addition & 1 deletion ci/main/rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub unsafe extern "C" fn Reset() -> ! {
pub static RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset;

#[panic_handler]
fn panic(_panic: &PanicInfo) -> ! {
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}

Expand Down
2 changes: 1 addition & 1 deletion ci/main/rt2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub unsafe extern "C" fn Reset() -> ! {
pub static RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset;

#[panic_handler]
fn panic(_panic: &PanicInfo) -> ! {
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}

Expand Down
2 changes: 1 addition & 1 deletion ci/memory-layout/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ pub unsafe extern "C" fn Reset() -> ! {
pub static RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset;

#[panic_handler]
fn panic(_panic: &PanicInfo) -> ! {
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
16 changes: 16 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ main() {
diff app.o.nm \
<(cargo nm -- target/thumbv7m-none-eabi/debug/deps/app-*.o | grep '[0-9]* [^n] ')

edition_check

popd

# # memory-layout
Expand All @@ -38,6 +40,8 @@ main() {

qemu_check target/thumbv7m-none-eabi/debug/app

edition_check

popd

# # main
Expand All @@ -47,20 +51,25 @@ main() {
pushd app
diff app.objdump \
<(cargo objdump --bin app -- -d -no-show-raw-insn)
# disabled because of rust-lang/rust#53964
# edition_check
popd

# check that it builds
pushd app2
cargo build
edition_check
popd

pushd app3
cargo build
edition_check
popd

pushd app4
cargo build
qemu_check target/thumbv7m-none-eabi/debug/app
edition_check
popd

popd
Expand All @@ -72,16 +81,23 @@ main() {
pushd app
diff app.vector_table.objdump \
<(cargo objdump --bin app --release -- -s -j .vector_table)
edition_check
popd

# check that it builds
pushd app2
cargo build
edition_check
popd

popd
}

# checks that 2018 idioms are being used
edition_check() {
RUSTFLAGS="-D rust_2018_compatibility -D rust_2018_idioms" cargo check
}

# checks that QEMU doesn't crash and that it produces no error messages
qemu_check() {
qemu-system-arm \
Expand Down
3 changes: 3 additions & 0 deletions ci/smallest-no-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cargo-features = ["edition"]

[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"

Expand Down
2 changes: 1 addition & 1 deletion ci/smallest-no-std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
use core::panic::PanicInfo;

#[panic_handler]
fn panic(_panic: &PanicInfo) -> ! {
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
17 changes: 17 additions & 0 deletions src/preface.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ nor is access to a Cortex-M microcontroller needed -- all the examples included
QEMU. You will, however, need to install the following tools to run and inspect the examples in this
book:

- All the code in this book uses the 2018 edition. If you are not familiar with
the 2018 features and idioms check [the edition guide]. Please also note that
until the 2018 edition is officially released you'll have to *manually modify
the Cargo.toml of new projects* to make use the 2018 edition. The required
changes are shown below:

[the edition guide]: https://rust-lang-nursery.github.io/edition-guide/

``` diff
+cargo-features = ["edition"]
+
[package]
+edition = "2018"
name = "hello"
version = "0.1.0"
```

- A nightly toolchain from 2018-08-28 or newer.

- [`cargo-binutils`](https://github.com/japaric/cargo-binutils). v0.1.2 or newer.
Expand Down

0 comments on commit cbec54e

Please sign in to comment.