Skip to content

Commit db46c4b

Browse files
committed
Simplify features and detect based on OS
Now we can build on Windows just with `cargo build`! Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 58960fa commit db46c4b

File tree

16 files changed

+198
-238
lines changed

16 files changed

+198
-238
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: cargo install cross
2727

2828
- name: Build FreeBSD tool
29-
run: cross build --target=x86_64-unknown-freebsd --no-default-features --features cross_freebsd
29+
run: cross build --target=x86_64-unknown-freebsd --no-default-features -p framework_lib
3030

3131
- name: Upload FreeBSD App
3232
uses: actions/upload-artifact@v4
@@ -93,15 +93,15 @@ jobs:
9393

9494
# Build debug library first to fail fast
9595
- name: Build library (Windows)
96-
run: cargo build -p framework_lib --no-default-features --features "windows"
96+
run: cargo build -p framework_lib
9797

9898
- name: Build Windows tool
9999
run: |
100-
cargo build -p framework_tool --no-default-features --features "windows"
101-
cargo build -p framework_tool --no-default-features --features "windows" --release
100+
cargo build -p framework_tool
101+
cargo build -p framework_tool --release
102102
103103
- name: Check if Windows tool can start
104-
run: cargo run --no-default-features --features "windows" -- --help --release
104+
run: cargo run -- --help --release
105105

106106
# Upload release build so that vcruntime is statically linked
107107
- name: Upload Windows App

README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,10 @@ Building on Windows or in general with fewer features:
130130

131131
```ps1
132132
# Build the library and tool
133-
cargo build --no-default-features --features "windows"
133+
cargo build
134134
135135
# Running the tool
136-
cargo run --no-default-features --features "windows"
137-
```
138-
139-
Cross compile from Linux to FreeBSD:
140-
141-
```sh
142-
# One time, install cross tool
143-
cargo install cross
144-
145-
# Make sure docker is started as well
146-
sudo systemctl start docker
147-
148-
# Build
149-
cross build --target=x86_64-unknown-freebsd --no-default-features --features unix
136+
cargo run
150137
```
151138

152139
## Running
@@ -375,8 +362,8 @@ Keyboard backlight: 0%
375362
sudo pkg install hidapi
376363
377364
# Build the library and tool
378-
cargo build --no-default-features --features freebsd
365+
cargo build
379366
380367
# Running the tool
381-
cargo run --no-default-features --features freebsd
368+
cargo run
382369
```

framework_lib/Cargo.toml

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,61 @@ rust-version = "1.74"
88
build = "build.rs"
99

1010
[features]
11-
default = ["linux"]
12-
# Linux/FreeBSD
13-
unix = ["std", "raw_pio", "smbios", "dep:nix", "dep:libc"]
14-
linux = ["unix", "linux_pio", "cros_ec_driver", "hidapi", "rusb"]
15-
freebsd = ["unix", "freebsd_pio", "hidapi", "rusb"]
16-
# hidapi and rusb don't seem to build in the cross container at the moment
17-
cross_freebsd = ["unix", "freebsd_pio"]
18-
# Windows does not have the cros_ec driver nor raw port I/O access to userspace
19-
windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio", "hidapi", "rusb", "dep:wmi"]
20-
smbios = ["dep:smbios-lib"]
21-
std = ["dep:clap", "dep:clap-num", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std"]
11+
default = ["std"]
12+
std = ["hidapi", "rusb"]
2213
rusb = ["dep:rusb"]
2314
hidapi = ["dep:hidapi"]
2415
uefi = [
25-
"dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services",
16+
"lazy_static/spin_no_std",
2617
# Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!`
2718
# Seems to be a Ruset/LLVM bug when SSE is enabled.
2819
# See: https://github.com/rust-lang/rust/issues/61721
2920
"sha2/force-soft"
3021
]
3122

32-
# EC communication via Port I/O on FreeBSD
33-
freebsd_pio = ["redox_hwio/std"]
34-
# EC communication via Port I/O on Linux
35-
linux_pio = ["dep:libc", "redox_hwio/std"]
36-
# EC communication via raw Port I/O (e.g. UEFI or other ring 0 code)
37-
raw_pio = []
38-
# EC communication via cros_ec driver on Linux
39-
cros_ec_driver = []
40-
41-
# Chromium EC driver by DHowett
42-
win_driver = []
43-
4423
[build-dependencies]
4524
built = { version = "0.5", features = ["chrono", "git2"] }
4625

4726
[dependencies]
4827
lazy_static = "1.4.0"
4928
sha2 = { version = "0.10.8", default-features = false, features = [ "force-soft" ] }
5029
regex = { version = "1.11.1", default-features = false }
51-
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
52-
libc = { version = "0.2.155", optional = true }
53-
clap = { version = "4.5", features = ["derive", "cargo"], optional = true }
54-
clap-num = { version = "1.2.0", optional = true }
55-
clap-verbosity-flag = { version = "2.2.1", optional = true }
56-
nix = { version = "0.29.0", features = ["ioctl", "user"], optional = true }
5730
num = { version = "0.4", default-features = false }
5831
num-derive = { version = "0.4", default-features = false }
5932
num-traits = { version = "0.2", default-features = false }
60-
env_logger = { version = "0.11", optional = true }
6133
log = { version = "0.4", default-features = true }
62-
uefi = { version = "0.20", features = ["alloc"], optional = true }
63-
uefi-services = { version = "0.17", optional = true }
64-
plain = { version = "0.2.3", optional = true }
65-
spin = { version = "0.9.8", optional = false }
66-
hidapi = { version = "2.6.3", optional = true, features = [ "windows-native" ] }
67-
rusb = { version = "0.9.4", optional = true }
34+
spin = { version = "0.9.8" }
6835
no-std-compat = { version = "0.4.1", features = [ "alloc" ] }
6936
guid_macros = { path = "../guid_macros" }
70-
wmi = { version = "0.15.0", optional = true }
37+
hidapi = { version = "2.6.3", features = [ "windows-native" ], optional = true }
38+
rusb = { version = "0.9.4", optional = true }
39+
40+
[target.'cfg(target_os = "uefi")'.dependencies]
41+
uefi = { version = "0.20", features = ["alloc"] }
42+
uefi-services = "0.17"
43+
plain = "0.2.3"
44+
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
45+
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std", default-features = false }
46+
47+
[target.'cfg(windows)'.dependencies]
48+
wmi = "0.15.0"
49+
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std" }
50+
env_logger = "0.11"
51+
clap = { version = "4.5", features = ["derive", "cargo"] }
52+
clap-num = { version = "1.2.0" }
53+
clap-verbosity-flag = { version = "2.2.1" }
7154

72-
[dependencies.smbios-lib]
73-
git = "https://github.com/FrameworkComputer/smbios-lib.git"
74-
branch = "no-std"
75-
optional = true
76-
default-features = false
77-
# Local development
78-
#path = "../../smbios-lib"
79-
# After my changes are upstreamed
80-
#version = "0.9.0"
55+
[target.'cfg(unix)'.dependencies]
56+
libc = "0.2.155"
57+
nix = { version = "0.29.0", features = ["ioctl", "user"] }
58+
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd" }
59+
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std" }
60+
env_logger = "0.11"
61+
clap = { version = "4.5", features = ["derive", "cargo"] }
62+
clap-num = { version = "1.2.0" }
63+
clap-verbosity-flag = { version = "2.2.1" }
8164

82-
[dependencies.windows]
83-
optional = true
65+
[target.'cfg(windows)'.dependencies.windows]
8466
version = "0.59.0"
8567
features = [
8668
"Win32_Foundation",

framework_lib/src/chromium_ec/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ pub trait EcRequestRaw<R> {
173173
{
174174
let response = self.send_command_vec_extra(ec, extra_data)?;
175175
// TODO: The Windows driver seems to return 20 more bytes than expected
176-
#[cfg(feature = "win_driver")]
176+
#[cfg(windows)]
177177
let expected = response.len() != std::mem::size_of::<R>() + 20;
178-
#[cfg(not(feature = "win_driver"))]
178+
#[cfg(not(windows))]
179179
let expected = response.len() != std::mem::size_of::<R>();
180180
if expected {
181181
return Err(EcError::DeviceError(format!(

framework_lib/src/chromium_ec/mod.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ use num_derive::FromPrimitive;
2121

2222
pub mod command;
2323
pub mod commands;
24-
#[cfg(feature = "cros_ec_driver")]
24+
#[cfg(target_os = "linux")]
2525
mod cros_ec;
2626
pub mod i2c_passthrough;
2727
pub mod input_deck;
28+
#[cfg(not(windows))]
2829
mod portio;
30+
#[cfg(not(windows))]
2931
mod portio_mec;
30-
#[cfg(feature = "win_driver")]
32+
#[allow(dead_code)]
33+
mod protocol;
34+
#[cfg(windows)]
3135
mod windows;
3236

3337
use alloc::format;
@@ -224,15 +228,15 @@ impl Default for CrosEc {
224228
fn available_drivers() -> Vec<CrosEcDriverType> {
225229
let mut drivers = vec![];
226230

227-
#[cfg(feature = "win_driver")]
231+
#[cfg(windows)]
228232
drivers.push(CrosEcDriverType::Windows);
229233

230-
#[cfg(feature = "cros_ec_driver")]
234+
#[cfg(target_os = "linux")]
231235
if std::path::Path::new(cros_ec::DEV_PATH).exists() {
232236
drivers.push(CrosEcDriverType::CrosEc);
233237
}
234238

235-
#[cfg(not(feature = "windows"))]
239+
#[cfg(not(windows))]
236240
drivers.push(CrosEcDriverType::Portio);
237241

238242
drivers
@@ -1320,10 +1324,11 @@ impl CrosEcDriver for CrosEc {
13201324

13211325
// TODO: Change this function to return EcResult instead and print the error only in UI code
13221326
print_err(match self.driver {
1327+
#[cfg(not(windows))]
13231328
CrosEcDriverType::Portio => portio::read_memory(offset, length),
1324-
#[cfg(feature = "win_driver")]
1329+
#[cfg(windows)]
13251330
CrosEcDriverType::Windows => windows::read_memory(offset, length),
1326-
#[cfg(feature = "cros_ec_driver")]
1331+
#[cfg(target_os = "linux")]
13271332
CrosEcDriverType::CrosEc => cros_ec::read_memory(offset, length),
13281333
_ => Err(EcError::DeviceError("No EC driver available".to_string())),
13291334
})
@@ -1341,10 +1346,11 @@ impl CrosEcDriver for CrosEc {
13411346
}
13421347

13431348
match self.driver {
1349+
#[cfg(not(windows))]
13441350
CrosEcDriverType::Portio => portio::send_command(command, command_version, data),
1345-
#[cfg(feature = "win_driver")]
1351+
#[cfg(windows)]
13461352
CrosEcDriverType::Windows => windows::send_command(command, command_version, data),
1347-
#[cfg(feature = "cros_ec_driver")]
1353+
#[cfg(target_os = "linux")]
13481354
CrosEcDriverType::CrosEc => cros_ec::send_command(command, command_version, data),
13491355
_ => Err(EcError::DeviceError("No EC driver available".to_string())),
13501356
}

0 commit comments

Comments
 (0)