Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable usage with non-nightly rust #7

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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