Skip to content

Commit 922bbc5

Browse files
Merge pull request #126 from FrameworkComputer/cargo-build-windows
Simplify features and detect based on OS
2 parents 526ba80 + f73981d commit 922bbc5

File tree

17 files changed

+213
-260
lines changed

17 files changed

+213
-260
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: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,10 @@ 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 = ["hidapi", "rusb"]
2212
rusb = ["dep:rusb"]
2313
hidapi = ["dep:hidapi"]
24-
uefi = [
25-
"dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services",
26-
# Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!`
27-
# Seems to be a Ruset/LLVM bug when SSE is enabled.
28-
# See: https://github.com/rust-lang/rust/issues/61721
29-
"sha2/force-soft"
30-
]
31-
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 = []
14+
uefi = [ "lazy_static/spin_no_std" ]
4315

4416
[build-dependencies]
4517
built = { version = "0.5", features = ["chrono", "git2"] }
@@ -48,39 +20,42 @@ built = { version = "0.5", features = ["chrono", "git2"] }
4820
lazy_static = "1.4.0"
4921
sha2 = { version = "0.10.8", default-features = false, features = [ "force-soft" ] }
5022
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 }
5723
num = { version = "0.4", default-features = false }
5824
num-derive = { version = "0.4", default-features = false }
5925
num-traits = { version = "0.2", default-features = false }
60-
env_logger = { version = "0.11", optional = true }
6126
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 }
27+
spin = { version = "0.9.8" }
6828
no-std-compat = { version = "0.4.1", features = [ "alloc" ] }
6929
guid_macros = { path = "../guid_macros" }
70-
wmi = { version = "0.15.0", optional = true }
30+
hidapi = { version = "2.6.3", features = [ "windows-native" ], optional = true }
31+
rusb = { version = "0.9.4", optional = true }
32+
33+
[target.'cfg(target_os = "uefi")'.dependencies]
34+
uefi = { version = "0.20", features = ["alloc"] }
35+
uefi-services = "0.17"
36+
plain = "0.2.3"
37+
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
38+
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std", default-features = false }
39+
40+
[target.'cfg(windows)'.dependencies]
41+
wmi = "0.15.0"
42+
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std" }
43+
env_logger = "0.11"
44+
clap = { version = "4.5", features = ["derive", "cargo"] }
45+
clap-num = { version = "1.2.0" }
46+
clap-verbosity-flag = { version = "2.2.1" }
7147

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"
48+
[target.'cfg(unix)'.dependencies]
49+
libc = "0.2.155"
50+
nix = { version = "0.29.0", features = ["ioctl", "user"] }
51+
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd" }
52+
smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std" }
53+
env_logger = "0.11"
54+
clap = { version = "4.5", features = ["derive", "cargo"] }
55+
clap-num = { version = "1.2.0" }
56+
clap-verbosity-flag = { version = "2.2.1" }
8157

82-
[dependencies.windows]
83-
optional = true
58+
[target.'cfg(windows)'.dependencies.windows]
8459
version = "0.59.0"
8560
features = [
8661
"Win32_Foundation",

framework_lib/src/capsule.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use std::prelude::v1::*;
1212

1313
use core::prelude::rust_2021::derive;
14-
#[cfg(all(not(feature = "uefi"), feature = "std"))]
14+
#[cfg(not(feature = "uefi"))]
1515
use std::fs::File;
16-
#[cfg(all(not(feature = "uefi"), feature = "std"))]
16+
#[cfg(not(feature = "uefi"))]
1717
use std::io::prelude::*;
1818

1919
#[cfg(not(feature = "uefi"))]
@@ -180,7 +180,7 @@ pub fn dump_winux_image(data: &[u8], header: &DisplayCapsule, filename: &str) {
180180

181181
let image = &data[header_len..image_size];
182182

183-
#[cfg(all(not(feature = "uefi"), feature = "std"))]
183+
#[cfg(not(feature = "uefi"))]
184184
{
185185
let mut file = File::create(filename).unwrap();
186186
file.write_all(image).unwrap();

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)