Skip to content

Commit

Permalink
Merge pull request #47 from FrameworkComputer/freebsd-cross-ci
Browse files Browse the repository at this point in the history
gh-actions: Add FreeBSD cross compilation
  • Loading branch information
JohnAZoidberg authored Aug 1, 2024
2 parents 03d72f9 + f9589f9 commit b6b235c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 63 deletions.
82 changes: 41 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ on:
push:

jobs:
# Won't work because pkg-config can't find hidapi.
# I changed build.rs to search for 'hidapi-libusb', which is how it's installed
# on Ubuntu. But that still can't find it.
# freebsd-cross-build:
# name: Cross-Build for FreeBSD
# runs-on: 'ubuntu-22.04'
# env:
# CARGO_NET_GIT_FETCH_WITH_CLI: true
# steps:
# - uses: actions/checkout@v3

# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y libudev-dev libhidapi-dev

# - name: Setup Rust toolchain
# run: rustup show

# - name: Install cross compilation tool
# run: cargo install cross

# - name: Build FreeBSD tool
# run: cross build --target=x86_64-unknown-freebsd --no-default-features --features unix

# - name: Upload FreeBSD App
# uses: actions/upload-artifact@v3
# with:
# name: framework_tool_freebsd
# path: target/x86_64-unknown-freebsd/debug/framework_tool
freebsd-cross-build:
name: Cross-Build for FreeBSD
runs-on: 'ubuntu-24.04'
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev libhidapi-dev
- name: Setup Rust toolchain
run: |
rm rust-toolchain.toml
rustup toolchain install 1.75.0-x86_64-unknown-freebsd
rustup show
- name: Install cross compilation tool
run: cargo install cross

- name: Build FreeBSD tool
run: cross build --target=x86_64-unknown-freebsd --no-default-features --features cross_freebsd

- name: Upload FreeBSD App
uses: actions/upload-artifact@v4
with:
name: framework_tool_freebsd
path: target/x86_64-unknown-freebsd/debug/framework_tool

build:
name: Build Linux and UEFI
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand All @@ -60,7 +60,7 @@ jobs:
run: cargo run -- --help

- name: Upload Linux App
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: framework_tool
path: target/debug/framework_tool
Expand All @@ -69,7 +69,7 @@ jobs:
run: make -C framework_uefi build/x86_64-unknown-uefi/boot.efi

- name: Upload UEFI App
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: framework.efi
path: framework_uefi/build/x86_64-unknown-uefi/boot.efi
Expand All @@ -86,7 +86,7 @@ jobs:
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Rust toolchain
run: rustup show
Expand All @@ -101,7 +101,7 @@ jobs:
run: cargo run --no-default-features --features "windows" -- --help

- name: Upload Windows App
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: framework_tool.exe
path: target/debug/framework_tool.exe
Expand All @@ -114,7 +114,7 @@ jobs:
CARGO_NET_GIT_FETCH_WITH_CLI: true
steps:
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand All @@ -129,11 +129,11 @@ jobs:

lints:
name: Lints
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand All @@ -152,13 +152,13 @@ jobs:
# Just make sure doc generation works
doc:
name: Generate docs
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
# Fail if warnings are produced
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[target.x86_64-unknown-freebsd]
image = "ghcr.io/cross-rs/x86_64-unknown-freebsd:main"
pre-build = ["""
export FREEBSD_MIRROR=$(/freebsd-fetch-best-mirror.sh) &&
/freebsd-setup-packagesite.sh &&
/freebsd-install-package.sh hidapi
"""]
16 changes: 10 additions & 6 deletions framework_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ build = "build.rs"
default = ["linux"]
# Linux/FreeBSD
unix = ["std", "raw_pio", "smbios", "dep:nix", "dep:libc"]
linux = ["unix", "linux_pio", "cros_ec_driver"]
freebsd = ["unix", "freebsd_pio"]
linux = ["unix", "linux_pio", "cros_ec_driver", "hidapi", "rusb"]
freebsd = ["unix", "freebsd_pio", "hidapi", "rusb"]
# hidapi and rusb don't seem to build in the cross container at the moment
cross_freebsd = ["unix", "freebsd_pio"]
# Windows does not have the cros_ec driver nor raw port I/O access to userspace
windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio"]
windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio", "hidapi", "rusb"]
smbios = ["dep:smbios-lib"]
std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std"]
rusb = ["dep:rusb"]
hidapi = ["dep:hidapi"]
uefi = [
"dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services",
# Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!`
Expand All @@ -40,9 +44,9 @@ built = { version = "0.5", features = ["chrono", "git2"] }

[dependencies]
lazy_static = "1.4.0"
sha2 = { version = "0.10.6", default_features = false, features = [ "force-soft" ] }
sha2 = { version = "0.10.6", default-features = false, features = [ "force-soft" ] }
regex = { version = "1.10.0", default-features = false }
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default_features = false }
redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false }
libc = { version = "0.2.155", optional = true }
clap = { version = "4.0", features = ["derive"], optional = true }
clap-verbosity-flag = { version = "2.0.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/ccgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use self::device::{PdController, PdPort};

pub mod binary;
pub mod device;
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
pub mod hid;

const FW1_METADATA_ROW: u32 = 0x1FE;
Expand Down
22 changes: 11 additions & 11 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use std::fs;
#[cfg(all(not(feature = "uefi"), feature = "std"))]
use std::io::prelude::*;

#[cfg(not(feature = "uefi"))]
#[cfg(feature = "rusb")]
use crate::audio_card::check_synaptics_fw_version;
use crate::built_info;
use crate::capsule;
use crate::capsule_content::{
find_bios_version, find_ec_in_bios_cap, find_pd_in_bios_cap, find_retimer_version,
};
use crate::ccgx::device::{PdController, PdPort};
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CARD_PID};
use crate::ccgx::{self, SiliconId::*};
use crate::chromium_ec;
Expand All @@ -48,7 +48,7 @@ use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
use crate::uefi::enable_page_break;
use crate::util;
use crate::util::Config;
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
use hidapi::HidApi;
use sha2::{Digest, Sha256, Sha384, Sha512};
//use smbioslib::*;
Expand Down Expand Up @@ -197,15 +197,15 @@ fn print_pd_details(ec: &CrosEc) {
print_single_pd_details(&pd_23);
}

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

#[cfg(not(feature = "uefi"))]
#[cfg(feature = "rusb")]
fn print_audio_card_details() {
check_synaptics_fw_version();
}

#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
fn print_dp_hdmi_details() {
match HidApi::new() {
Ok(api) => {
Expand Down Expand Up @@ -270,7 +270,7 @@ fn print_tool_version() {
}

// TODO: Check if HDMI card is same
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
fn flash_dp_hdmi_card(pd_bin_path: &str) {
let data = match fs::read(pd_bin_path) {
Ok(data) => Some(data),
Expand Down Expand Up @@ -616,15 +616,15 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
} else if args.pd_info {
print_pd_details(&ec);
} else if args.dp_hdmi_info {
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
print_dp_hdmi_details();
} else if let Some(pd_bin_path) = &args.dp_hdmi_update {
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "hidapi")]
flash_dp_hdmi_card(pd_bin_path);
#[cfg(feature = "uefi")]
#[cfg(not(feature = "hidapi"))]
let _ = pd_bin_path;
} else if args.audio_card_info {
#[cfg(not(feature = "uefi"))]
#[cfg(feature = "rusb")]
print_audio_card_details();
} else if args.privacy {
if let Some((mic, cam)) = print_err(ec.get_privacy_info()) {
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/esrt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ pub fn get_esrt() -> Option<Esrt> {

#[cfg(target_os = "freebsd")]
#[repr(C)]
struct EfiGetTableIoc {
pub struct EfiGetTableIoc {
buf: *mut u8,
uuid: [u8; 16],
table_len: usize,
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate lazy_static;
#[macro_use]
extern crate log;

#[cfg(not(feature = "uefi"))]
#[cfg(feature = "rusb")]
pub mod audio_card;

#[cfg(feature = "uefi")]
Expand Down
2 changes: 1 addition & 1 deletion framework_lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
}

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

0 comments on commit b6b235c

Please sign in to comment.