Skip to content

Commit

Permalink
Build with stable rust 1.75
Browse files Browse the repository at this point in the history
This updates to latest git embassy deps (soon to be published on
crates.io).

The two nightly rust features are no longer required. Async Fn in Traits
has been merged.

Type Alias Impl Trait isn't in stable yet, so uses of singleton!() need
to be replaced with more cumbersome StaticCell. Eventually that can be
reverted.

There are also some small API changes to embassy and embedded-io crates
that needed fixing.
  • Loading branch information
mkj committed Dec 30, 2023
1 parent 01ad34d commit 6fb3108
Show file tree
Hide file tree
Showing 27 changed files with 598 additions and 565 deletions.
879 changes: 473 additions & 406 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sunset-sshwire-derive = { version = "0.1", path = "sshwire-derive" }
snafu = { version = "0.7", default-features = false, features = ["rust_1_61"] }
# TODO: check that log macro calls disappear in no_std builds
log = { version = "0.4" }
heapless = "0.7.10"
heapless = "0.8"

# allows avoiding utf8 for SSH identifier names
ascii = { version = "1.0", default-features = false }
Expand Down Expand Up @@ -88,22 +88,22 @@ x25519-dalek = { git = "https://github.com/mkj/curve25519-dalek", branch = "suns
# ed25519-dalek = { path = "/home/matt/3rd/rs/crypto/curve25519-dalek/ed25519-dalek" }
# x25519-dalek = { path = "/home/matt/3rd/rs/crypto/curve25519-dalek/x25519-dalek" }

embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
# embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-rp = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-usb = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
# embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-usb-driver = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
# embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-rp = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-usb = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
# embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-usb-driver = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
# for cyw43
embassy-net = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-net-driver-channel = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-net-driver = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-net-tuntap = { git = "https://github.com/embassy-rs/embassy", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }

cyw43 = { git = "https://github.com/embassy-rs/embassy/", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
cyw43-pio = { git = "https://github.com/embassy-rs/embassy/", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-net-wiznet = { git = "https://github.com/embassy-rs/embassy/", rev = "78a7ee7ec48a6ed26d770165e777beb06e92777c" }
embassy-net = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-net-driver-channel = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-net-driver = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-net-tuntap = { git = "https://github.com/embassy-rs/embassy", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }

cyw43 = { git = "https://github.com/embassy-rs/embassy/", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
cyw43-pio = { git = "https://github.com/embassy-rs/embassy/", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }
embassy-net-wiznet = { git = "https://github.com/embassy-rs/embassy/", rev = "90e96d281f87efdbea3a1418f5354f14386a42e8" }

# embassy-net = { path = "/home/matt/3rd/rs/embassy/embassy-net" }
# embassy-net-driver = { path = "/home/matt/3rd/rs/embassy/embassy-net-driver" }
Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ Desirable:

## Rust versions

At present `sunset` requires nightly Rust, in order to use async functions in
the `Behaviour` traits. It is intended to switch to stable Rust once that
feature stabilises.

`sunset-embassy` requires a nightly Rust version, as required by Embassy. See the
[embassy/rust-toolchain.toml](rust-toolchain.toml) for a known-good version.
Once [async functions in traits](https://github.com/rust-lang/rust/issues/91611)
becomes stable, Embassy should support stable Rust too.
At present Sunset will build with latest stable (1.75 at time of writing).

## Safety

Expand Down
6 changes: 3 additions & 3 deletions async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ argh = "0.1"

ssh-key = { version = "0.5", default-features = false, features = [ "std"] }

embassy-sync = { version = "0.3.0" }
embassy-futures = { version = "0.1.0" }
embassy-sync = { version = "0.5" }
embassy-futures = { version = "0.1" }

embedded-io-async = "0.6"

Expand All @@ -28,7 +28,7 @@ futures = "0.3"
libc = "0.2"
nix = "0.26"

heapless = "0.7.10"
heapless = "0.8"

# TODO
pretty-hex = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion async/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-01"
channel = "stable"
components = [ "rustfmt" ]
2 changes: 0 additions & 2 deletions async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// avoid mysterious missing awaits
#![deny(unused_must_use)]

#![feature(async_fn_in_trait)]

mod pty;
mod cmdline_client;
mod knownhosts;
Expand Down
4 changes: 2 additions & 2 deletions embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ categories = ["network-programming", "embedded", "no-std"]
license = "0BSD"

[dependencies]
embassy-sync = { version = "0.3.0" }
embassy-futures = { version = "0.1.0" }
embassy-sync = { version = "0.5" }
embassy-futures = { version = "0.1" }
embedded-io-async = "0.6"
atomic-polyfill = "1.0"
pin-utils = { version = "0.1" }
Expand Down
12 changes: 6 additions & 6 deletions embassy/demos/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ sunset-embassy = { path = "../../" }
sunset = { path = "../../.." }
sunset-sshwire-derive = { version = "0.1", path = "../../../sshwire-derive" }

embassy-sync = { version = "0.3.0" }
embassy-net = { version = "0.2.0", features = ["tcp", "dhcpv4", "medium-ethernet", "nightly"] }
embassy-net-driver = { version = "0.2.0" }
embassy-futures = { version = "0.1.0" }
embassy-sync = { version = "0.5" }
embassy-net = { version = "0.2", features = ["tcp", "dhcpv4", "medium-ethernet"] }
embassy-net-driver = { version = "0.2" }
embassy-futures = { version = "0.1" }
embassy-time = { version = "0.1" }

heapless = "0.7.15"
heapless = "0.8"
# using local fork
# menu = "0.3"
embedded-io-async = "0.6"
Expand All @@ -34,5 +34,5 @@ sunset = { path = "../../..", features = ["std"] }
tokio = { version = "1.25", features = ["full"] }

[features]
defmt = ["dep:defmt", "embedded-io-async/defmt-03"]
defmt = ["dep:defmt", "embedded-io-async/defmt-03", "embassy-net/defmt"]
log = ["embassy-net/log"]
8 changes: 4 additions & 4 deletions embassy/demos/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl SSHConfig {
pub fn new() -> Result<Self> {
let hostkey = SignKey::generate(KeyType::Ed25519, None)?;

let wifi_net = option_env!("WIFI_NET").unwrap_or("guest").into();
let wifi_pw = option_env!("WIFI_PW").map(|p| p.into());
let wifi_net: String::<32> = option_env!("WIFI_NET").unwrap_or("guest").try_into().trap()?;
let wifi_pw: Option<String::<63>> = option_env!("WIFI_PW").map(|s| s.try_into()).transpose().trap()?;
let mac = random_mac()?;
Ok(SSHConfig {
hostkey,
Expand Down Expand Up @@ -363,9 +363,9 @@ mod tests {
Some(Ed25519PubKey { key: Blob([29u8; 32]) }),
Some(Ed25519PubKey { key: Blob([39u8; 32]) }),
],
wifi_net: core::str::from_utf8([b'a'; 32].as_slice()).unwrap().into(),
wifi_net: core::str::from_utf8([b'a'; 32].as_slice()).unwrap().try_into().unwrap(),
wifi_pw: Some(
core::str::from_utf8([b'f'; 63].as_slice()).unwrap().into(),
core::str::from_utf8([b'f'; 63].as_slice()).unwrap().try_into().unwrap(),
),
mac: [6, 2, 3, 4, 5, 6],
ip4_static: Some(embassy_net::StaticConfigV4 {
Expand Down
5 changes: 2 additions & 3 deletions embassy/demos/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg_attr(not(any(feature = "std", test)), no_std)]

#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
// #![allow(incomplete_features)]
// avoid warning about Send for the time being
#[allow(async_fn_in_trait)]

mod server;

Expand Down
19 changes: 0 additions & 19 deletions embassy/demos/common/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ use sunset_embassy::{SSHServer, SunsetMutex};

use crate::SSHConfig;

// #[macro_export]
// macro_rules! singleton {
// ($val:expr) => {{
// type T = impl Sized;
// static STATIC_CELL: StaticCell<T> = StaticCell::new();
// STATIC_CELL.init($val)
// }};
// }
#[macro_export]
macro_rules! singleton {
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}


// common entry point
pub async fn listener<D: Driver, S: DemoServer>(stack: &'static Stack<D>,
config: &SunsetMutex<SSHConfig>,
Expand Down
6 changes: 4 additions & 2 deletions embassy/demos/common/src/takepipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ impl Read for TakeRead<'_> {
if *c != self.counter {
return Err(sunset::Error::ChannelEOF);
}
Ok(o.read(buf).await)
// OK unwrap, pipe.read() is infallible
Ok(o.read(buf).await.unwrap())
};

let r = select(
Expand Down Expand Up @@ -204,7 +205,8 @@ impl Write for TakeWrite<'_> {
if *c != self.counter {
return Err(sunset::Error::ChannelEOF);
}
Ok(o.write(buf).await)
// OK unwrap, pipe.write is infallible
Ok(o.write(buf).await.unwrap())
};

let r = select(
Expand Down
32 changes: 12 additions & 20 deletions embassy/demos/picow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ cyw43-pio = { version = "0.1.0", optional = true }

embassy-net-wiznet = { version = "0.1.0", optional = true }

embassy-executor = { version = "0.3", features = ["defmt", "integrated-timers", "executor-thread", "arch-cortex-m", "nightly"] }
embassy-time = { version = "0.1", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "nightly"] }
embassy-rp = { version = "0.1.0", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver"] }
embassy-executor = { version = "0.4", features = ["defmt", "integrated-timers", "executor-thread", "arch-cortex-m"] }
embassy-time = { version = "0.2", features = ["defmt", "defmt-timestamp-uptime"] }
embassy-rp = { version = "0.1", features = ["defmt", "unstable-pac", "time-driver"] }
# embassy-net/nightly is required for asynch::Read/Write on TcpReader/TcpWriter
embassy-net = { version = "0.2.0", features = ["tcp", "dhcpv4", "medium-ethernet", "nightly"] }
embassy-net-driver = { version = "0.2.0" }
embassy-usb-driver = { version = "0.1.0" }
embassy-sync = { version = "0.3.0" }
embassy-futures = { version = "0.1.0" }
embassy-usb = { version = "0.1.0" }
embassy-net = { version = "0.2", features = ["tcp", "dhcpv4", "medium-ethernet"] }
embassy-net-driver = { version = "0.2" }
embassy-usb-driver = { version = "0.1" }
embassy-sync = { version = "0.5" }
embassy-futures = { version = "0.1" }
embassy-usb = { version = "0.1" }
atomic-polyfill = "0.1.5"
static_cell = { version = "1.0", features = [ "nightly" ] }

Expand All @@ -46,28 +46,20 @@ embedded-hal-async = { version = "1.0.0-alpha.10" }
embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"], optional = true }
embedded-io-async = "0.6"
embedded-storage-async = { version = "0.4.0" }
heapless = "0.7.15"

getrandom = { version = "0.2", default-features = false, features = ["custom"]}
pin-utils = "0.1"

# using local fork
# menu = "0.3"
heapless = "0.8"

caprand = { git = "https://github.com/mkj/caprand" }
getrandom = { version = "0.2", features = ["custom"] }

critical-section = "1.1"
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
sha2 = { version = "0.10", default-features = false }

# for defmt feature
smoltcp = { version = "0.10", default-features = false }

usbd-hid = "0.6"

[features]
default = ["cyw43", "defmt", "sunset-demo-embassy-common/defmt" ]
defmt = ["dep:defmt", "sunset/defmt", "sunset-embassy/defmt", "smoltcp/defmt"]
defmt = ["dep:defmt", "sunset/defmt", "sunset-embassy/defmt"]

# for pico w board
cyw43 = ["dep:cyw43", "dep:cyw43-pio"]
Expand Down
2 changes: 1 addition & 1 deletion embassy/demos/picow/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-01"
channel = "stable"
components = [ "rustfmt" ]
32 changes: 17 additions & 15 deletions embassy/demos/picow/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
// #![allow(incomplete_features)]

#[allow(unused_imports)]
#[cfg(not(feature = "defmt"))]
Expand Down Expand Up @@ -30,7 +27,6 @@ use embassy_sync::signal::Signal;
use sunset::*;
use sunset_embassy::{SSHServer, SunsetMutex};

use crate::demo_common::singleton;
pub(crate) use sunset_demo_embassy_common as demo_common;

mod flashconfig;
Expand Down Expand Up @@ -75,19 +71,25 @@ async fn main(spawner: Spawner) {
} else {
flashconfig::load_or_create(&mut flash).await.unwrap()
};
let flash = &*singleton!(SunsetMutex::new(flash));
let config = &*singleton!(SunsetMutex::new(config));
static FLASH: StaticCell<SunsetMutex<flashconfig::Fl>> = StaticCell::new();
let flash = FLASH.init(SunsetMutex::new(flash));
static CONFIG: StaticCell<SunsetMutex<SSHConfig>> = StaticCell::new();
let config = CONFIG.init(SunsetMutex::new(config));

// A shared pipe to a local USB-serial (CDC)
static USBS: StaticCell<takepipe::TakePipeStorage> = StaticCell::new();
static USBP: StaticCell<takepipe::TakePipe> = StaticCell::new();
let usb_pipe = {
let p = singleton!(takepipe::TakePipeStorage::new());
singleton!(p.build())
let p = USBS.init(Default::default());
USBP.init_with(|| p.build())
};

// A shared pipe to a local uart
static SERS: StaticCell<takepipe::TakePipeStorage> = StaticCell::new();
static SERP: StaticCell<takepipe::TakePipe> = StaticCell::new();
let serial1_pipe = {
let s = singleton!(takepipe::TakePipeStorage::new());
singleton!(s.build())
let p = SERS.init(Default::default());
SERP.init_with(|| p.build())
};
spawner
.spawn(serial::task(
Expand All @@ -101,10 +103,12 @@ async fn main(spawner: Spawner) {
.unwrap();

// Watchdog currently only used for triggering reset manually
let watchdog = singleton!(SunsetMutex::new(
static WD: StaticCell<SunsetMutex<embassy_rp::watchdog::Watchdog>> = StaticCell::new();
let watchdog = WD.init(SunsetMutex::new(
embassy_rp::watchdog::Watchdog::new(p.WATCHDOG)
));

static STATE: StaticCell<GlobalState> = StaticCell::new();
let state;

// Spawn network tasks to handle incoming connections with demo_common::session()
Expand All @@ -120,8 +124,7 @@ async fn main(spawner: Spawner) {
let net_mac = match stack.hardware_address() {
HardwareAddress::Ethernet(EthernetAddress(eth)) => eth,
};
let g = GlobalState { usb_pipe, serial1_pipe, config, flash, watchdog, net_mac };
state = singleton!(g);
state = STATE.init_with(|| GlobalState { usb_pipe, serial1_pipe, config, flash, watchdog, net_mac });
for _ in 0..NUM_LISTENERS {
spawner.spawn(cyw43_listener(&stack, config, state)).unwrap();
}
Expand All @@ -139,8 +142,7 @@ async fn main(spawner: Spawner) {
let net_mac = match stack.hardware_address() {
HardwareAddress::Ethernet(EthernetAddress(eth)) => eth,
};
let g = GlobalState { usb_pipe, serial1_pipe, config, flash, watchdog, net_mac };
state = singleton!(g);
state = STATE.init_with(|| GlobalState { usb_pipe, serial1_pipe, config, flash, watchdog, net_mac });
for _ in 0..NUM_LISTENERS {
spawner.spawn(w5500_listener(&stack, config, state)).unwrap();
}
Expand Down
8 changes: 5 additions & 3 deletions embassy/demos/picow/src/picowmenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,10 @@ fn do_wifi_wpa2(_item: &Item<MenuCtx>, args: &[&str], context: &mut MenuCtx) {
let _ = writeln!(out, "Too long pw");
return;
}
c.wifi_net = net.into();
c.wifi_pw = Some(pw.into())
// OK unwrap, checked length
c.wifi_net = net.try_into().unwrap();
// OK unwrap, checked length
c.wifi_pw = Some(pw.try_into().unwrap())
});
wifi_entry(context);
}
Expand Down Expand Up @@ -795,5 +797,5 @@ pub(crate) async fn request_pw<E>(
}

let pw = core::str::from_utf8(&pw).map_err(|_| ())?;
return Ok(pw.into());
pw.try_into().map_err(|_| ())
}
6 changes: 4 additions & 2 deletions embassy/demos/picow/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ pub(crate) async fn task(
pin_rts: PIN_3,
pipe: &'static TakePipe<'static>,
) -> ! {
let tx_buf = singleton!([0u8; 16]).as_mut_slice();
let rx_buf = singleton!([0u8; 300]).as_mut_slice();
static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
let tx_buf = TX_BUF.init(Default::default()).as_mut_slice();
static RX_BUF: StaticCell<[u8; 300]> = StaticCell::new();
let rx_buf = RX_BUF.init_with(|| [0u8; 300]).as_mut_slice();
let uart = BufferedUart::new_with_rtscts(
uart,
Irqs,
Expand Down
Loading

0 comments on commit 6fb3108

Please sign in to comment.