Skip to content

Commit b6b235c

Browse files
Merge pull request #47 from FrameworkComputer/freebsd-cross-ci
gh-actions: Add FreeBSD cross compilation
2 parents 03d72f9 + f9589f9 commit b6b235c

9 files changed

Lines changed: 74 additions & 63 deletions

File tree

.github/workflows/ci.yml

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@ on:
33
push:
44

55
jobs:
6-
# Won't work because pkg-config can't find hidapi.
7-
# I changed build.rs to search for 'hidapi-libusb', which is how it's installed
8-
# on Ubuntu. But that still can't find it.
9-
# freebsd-cross-build:
10-
# name: Cross-Build for FreeBSD
11-
# runs-on: 'ubuntu-22.04'
12-
# env:
13-
# CARGO_NET_GIT_FETCH_WITH_CLI: true
14-
# steps:
15-
# - uses: actions/checkout@v3
16-
17-
# - name: Install dependencies
18-
# run: |
19-
# sudo apt-get update
20-
# sudo apt-get install -y libudev-dev libhidapi-dev
21-
22-
# - name: Setup Rust toolchain
23-
# run: rustup show
24-
25-
# - name: Install cross compilation tool
26-
# run: cargo install cross
27-
28-
# - name: Build FreeBSD tool
29-
# run: cross build --target=x86_64-unknown-freebsd --no-default-features --features unix
30-
31-
# - name: Upload FreeBSD App
32-
# uses: actions/upload-artifact@v3
33-
# with:
34-
# name: framework_tool_freebsd
35-
# path: target/x86_64-unknown-freebsd/debug/framework_tool
6+
freebsd-cross-build:
7+
name: Cross-Build for FreeBSD
8+
runs-on: 'ubuntu-24.04'
9+
env:
10+
CARGO_NET_GIT_FETCH_WITH_CLI: true
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install dependencies
15+
run: |
16+
sudo apt-get update
17+
sudo apt-get install -y libudev-dev libhidapi-dev
18+
19+
- name: Setup Rust toolchain
20+
run: |
21+
rm rust-toolchain.toml
22+
rustup toolchain install 1.75.0-x86_64-unknown-freebsd
23+
rustup show
24+
25+
- name: Install cross compilation tool
26+
run: cargo install cross
27+
28+
- name: Build FreeBSD tool
29+
run: cross build --target=x86_64-unknown-freebsd --no-default-features --features cross_freebsd
30+
31+
- name: Upload FreeBSD App
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: framework_tool_freebsd
35+
path: target/x86_64-unknown-freebsd/debug/framework_tool
3636

3737
build:
3838
name: Build Linux and UEFI
39-
runs-on: ubuntu-22.04
39+
runs-on: ubuntu-24.04
4040
env:
4141
CARGO_NET_GIT_FETCH_WITH_CLI: true
4242
steps:
43-
- uses: actions/checkout@v3
43+
- uses: actions/checkout@v4
4444

4545
- name: Install dependencies
4646
run: |
@@ -60,7 +60,7 @@ jobs:
6060
run: cargo run -- --help
6161

6262
- name: Upload Linux App
63-
uses: actions/upload-artifact@v3
63+
uses: actions/upload-artifact@v4
6464
with:
6565
name: framework_tool
6666
path: target/debug/framework_tool
@@ -69,7 +69,7 @@ jobs:
6969
run: make -C framework_uefi build/x86_64-unknown-uefi/boot.efi
7070

7171
- name: Upload UEFI App
72-
uses: actions/upload-artifact@v3
72+
uses: actions/upload-artifact@v4
7373
with:
7474
name: framework.efi
7575
path: framework_uefi/build/x86_64-unknown-uefi/boot.efi
@@ -86,7 +86,7 @@ jobs:
8686
env:
8787
CARGO_NET_GIT_FETCH_WITH_CLI: true
8888
steps:
89-
- uses: actions/checkout@v3
89+
- uses: actions/checkout@v4
9090

9191
- name: Setup Rust toolchain
9292
run: rustup show
@@ -101,7 +101,7 @@ jobs:
101101
run: cargo run --no-default-features --features "windows" -- --help
102102

103103
- name: Upload Windows App
104-
uses: actions/upload-artifact@v3
104+
uses: actions/upload-artifact@v4
105105
with:
106106
name: framework_tool.exe
107107
path: target/debug/framework_tool.exe
@@ -114,7 +114,7 @@ jobs:
114114
CARGO_NET_GIT_FETCH_WITH_CLI: true
115115
steps:
116116
- name: Checkout sources
117-
uses: actions/checkout@v3
117+
uses: actions/checkout@v4
118118

119119
- name: Install dependencies
120120
run: |
@@ -129,11 +129,11 @@ jobs:
129129

130130
lints:
131131
name: Lints
132-
runs-on: ubuntu-22.04
132+
runs-on: ubuntu-24.04
133133
env:
134134
CARGO_NET_GIT_FETCH_WITH_CLI: true
135135
steps:
136-
- uses: actions/checkout@v3
136+
- uses: actions/checkout@v4
137137

138138
- name: Install dependencies
139139
run: |
@@ -152,13 +152,13 @@ jobs:
152152
# Just make sure doc generation works
153153
doc:
154154
name: Generate docs
155-
runs-on: ubuntu-22.04
155+
runs-on: ubuntu-24.04
156156
env:
157157
CARGO_NET_GIT_FETCH_WITH_CLI: true
158158
# Fail if warnings are produced
159159
RUSTDOCFLAGS: -Dwarnings
160160
steps:
161-
- uses: actions/checkout@v3
161+
- uses: actions/checkout@v4
162162

163163
- name: Install dependencies
164164
run: |

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cross.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[target.x86_64-unknown-freebsd]
2+
image = "ghcr.io/cross-rs/x86_64-unknown-freebsd:main"
3+
pre-build = ["""
4+
export FREEBSD_MIRROR=$(/freebsd-fetch-best-mirror.sh) &&
5+
/freebsd-setup-packagesite.sh &&
6+
/freebsd-install-package.sh hidapi
7+
"""]

framework_lib/Cargo.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ build = "build.rs"
99
default = ["linux"]
1010
# Linux/FreeBSD
1111
unix = ["std", "raw_pio", "smbios", "dep:nix", "dep:libc"]
12-
linux = ["unix", "linux_pio", "cros_ec_driver"]
13-
freebsd = ["unix", "freebsd_pio"]
12+
linux = ["unix", "linux_pio", "cros_ec_driver", "hidapi", "rusb"]
13+
freebsd = ["unix", "freebsd_pio", "hidapi", "rusb"]
14+
# hidapi and rusb don't seem to build in the cross container at the moment
15+
cross_freebsd = ["unix", "freebsd_pio"]
1416
# Windows does not have the cros_ec driver nor raw port I/O access to userspace
15-
windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio"]
17+
windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio", "hidapi", "rusb"]
1618
smbios = ["dep:smbios-lib"]
17-
std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
19+
std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std"]
20+
rusb = ["dep:rusb"]
21+
hidapi = ["dep:hidapi"]
1822
uefi = [
1923
"dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services",
2024
# Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!`
@@ -40,9 +44,9 @@ built = { version = "0.5", features = ["chrono", "git2"] }
4044

4145
[dependencies]
4246
lazy_static = "1.4.0"
43-
sha2 = { version = "0.10.6", default_features = false, features = [ "force-soft" ] }
47+
sha2 = { version = "0.10.6", default-features = false, features = [ "force-soft" ] }
4448
regex = { version = "1.10.0", default-features = false }
45-
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default_features = false }
49+
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
4650
libc = { version = "0.2.155", optional = true }
4751
clap = { version = "4.0", features = ["derive"], optional = true }
4852
clap-verbosity-flag = { version = "2.0.1", optional = true }

framework_lib/src/ccgx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use self::device::{PdController, PdPort};
1111

1212
pub mod binary;
1313
pub mod device;
14-
#[cfg(not(feature = "uefi"))]
14+
#[cfg(feature = "hidapi")]
1515
pub mod hid;
1616

1717
const FW1_METADATA_ROW: u32 = 0x1FE;

framework_lib/src/commandline/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ use std::fs;
1919
#[cfg(all(not(feature = "uefi"), feature = "std"))]
2020
use std::io::prelude::*;
2121

22-
#[cfg(not(feature = "uefi"))]
22+
#[cfg(feature = "rusb")]
2323
use crate::audio_card::check_synaptics_fw_version;
2424
use crate::built_info;
2525
use crate::capsule;
2626
use crate::capsule_content::{
2727
find_bios_version, find_ec_in_bios_cap, find_pd_in_bios_cap, find_retimer_version,
2828
};
2929
use crate::ccgx::device::{PdController, PdPort};
30-
#[cfg(not(feature = "uefi"))]
30+
#[cfg(feature = "hidapi")]
3131
use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CARD_PID};
3232
use crate::ccgx::{self, SiliconId::*};
3333
use crate::chromium_ec;
@@ -48,7 +48,7 @@ use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
4848
use crate::uefi::enable_page_break;
4949
use crate::util;
5050
use crate::util::Config;
51-
#[cfg(not(feature = "uefi"))]
51+
#[cfg(feature = "hidapi")]
5252
use hidapi::HidApi;
5353
use sha2::{Digest, Sha256, Sha384, Sha512};
5454
//use smbioslib::*;
@@ -197,15 +197,15 @@ fn print_pd_details(ec: &CrosEc) {
197197
print_single_pd_details(&pd_23);
198198
}
199199

200-
#[cfg(not(feature = "uefi"))]
200+
#[cfg(feature = "hidapi")]
201201
const NOT_SET: &str = "NOT SET";
202202

203-
#[cfg(not(feature = "uefi"))]
203+
#[cfg(feature = "rusb")]
204204
fn print_audio_card_details() {
205205
check_synaptics_fw_version();
206206
}
207207

208-
#[cfg(not(feature = "uefi"))]
208+
#[cfg(feature = "hidapi")]
209209
fn print_dp_hdmi_details() {
210210
match HidApi::new() {
211211
Ok(api) => {
@@ -270,7 +270,7 @@ fn print_tool_version() {
270270
}
271271

272272
// TODO: Check if HDMI card is same
273-
#[cfg(not(feature = "uefi"))]
273+
#[cfg(feature = "hidapi")]
274274
fn flash_dp_hdmi_card(pd_bin_path: &str) {
275275
let data = match fs::read(pd_bin_path) {
276276
Ok(data) => Some(data),
@@ -616,15 +616,15 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
616616
} else if args.pd_info {
617617
print_pd_details(&ec);
618618
} else if args.dp_hdmi_info {
619-
#[cfg(not(feature = "uefi"))]
619+
#[cfg(feature = "hidapi")]
620620
print_dp_hdmi_details();
621621
} else if let Some(pd_bin_path) = &args.dp_hdmi_update {
622-
#[cfg(not(feature = "uefi"))]
622+
#[cfg(feature = "hidapi")]
623623
flash_dp_hdmi_card(pd_bin_path);
624-
#[cfg(feature = "uefi")]
624+
#[cfg(not(feature = "hidapi"))]
625625
let _ = pd_bin_path;
626626
} else if args.audio_card_info {
627-
#[cfg(not(feature = "uefi"))]
627+
#[cfg(feature = "rusb")]
628628
print_audio_card_details();
629629
} else if args.privacy {
630630
if let Some((mic, cam)) = print_err(ec.get_privacy_info()) {

framework_lib/src/esrt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn get_esrt() -> Option<Esrt> {
341341

342342
#[cfg(target_os = "freebsd")]
343343
#[repr(C)]
344-
struct EfiGetTableIoc {
344+
pub struct EfiGetTableIoc {
345345
buf: *mut u8,
346346
uuid: [u8; 16],
347347
table_len: usize,

framework_lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern crate lazy_static;
1212
#[macro_use]
1313
extern crate log;
1414

15-
#[cfg(not(feature = "uefi"))]
15+
#[cfg(feature = "rusb")]
1616
pub mod audio_card;
1717

1818
#[cfg(feature = "uefi")]

framework_lib/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
9696
}
9797

9898
/// Convert any type to a mut u8 slice (Like a C byte buffer)
99-
#[cfg(not(feature = "uefi"))]
99+
#[cfg(feature = "rusb")]
100100
pub unsafe fn any_as_mut_u8_slice<T: Sized>(p: &mut T) -> &mut [u8] {
101101
let len = ::std::mem::size_of::<T>();
102102
::std::slice::from_raw_parts_mut((p as *mut T) as *mut u8, len)

0 commit comments

Comments
 (0)