Skip to content

Commit

Permalink
enable usage with non-nightly rust
Browse files Browse the repository at this point in the history
default is "nightly"

to compile with stable rust:
uart_16550 = { version = "0.2.4", default-features = false, features = [ "stable" ] }
  • Loading branch information
haraldh committed Feb 25, 2020
1 parent 5454dd2 commit e54008c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ jobs:
- name: "Run cargo test"
run: cargo test

- name: "Run cargo build for stable"
run: cargo build --no-default-features --features stable
if: runner.os != 'Windows'

- name: "Run cargo test for stable"
run: cargo test --no-default-features --features stable
if: runner.os != 'Windows'

- name: "Run cargo doc"
run: cargo doc

Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ edition = "2018"

[dependencies]
bitflags = "1.1.0"
x86_64 = "0.9"
x86_64 = { version = "0.9.3", default-features = false }

[features]
default = [ "nightly" ]
stable = [ "x86_64/stable" ]
nightly = [ "x86_64/nightly" ]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ serial_port.send(42);
## License

Licensed under the MIT license ([LICENSE](LICENSE) or <http://opensource.org/licenses/MIT>).

## Crate Feature Flags

* `nightly`: This is the default.
* `stable`: Use this to build with non-nightly rust. Needs `default-features = false`.

## Building with stable rust

This needs to have the [compile-time requirements](https://github.com/alexcrichton/cc-rs#compile-time-requirements) of the `cc` crate installed on your system.
It was currently only tested on Linux and MacOS.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl SerialPort {
///
/// This function is unsafe because the caller must ensure that the given base address
/// really points to a serial port device.
#[cfg(feature = "nightly")]
pub const unsafe fn new(base: u16) -> SerialPort {
SerialPort {
data: Port::new(base),
Expand All @@ -68,6 +69,22 @@ impl SerialPort {
}
}

/// Creates a new serial port interface on the given I/O port.
///
/// This function is unsafe because the caller must ensure that the given base address
/// really points to a serial port device.
#[cfg(not(feature = "nightly"))]
pub unsafe fn new(base: u16) -> SerialPort {
SerialPort {
data: Port::new(base),
int_en: Port::new(base + 1),
fifo_ctrl: Port::new(base + 2),
line_ctrl: Port::new(base + 3),
modem_ctrl: Port::new(base + 4),
line_sts: Port::new(base + 5),
}
}

/// Initializes the serial port.
///
/// The default configuration of [38400/8-N-1](https://en.wikipedia.org/wiki/8-N-1) is used.
Expand Down

0 comments on commit e54008c

Please sign in to comment.