Skip to content
Open
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
5 changes: 5 additions & 0 deletions cargo-dist-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ impl TripleNameRef {
self.0.contains("linux")
}

/// Returns true if this target triple contains the word "freebsd"
pub fn is_freebsd(&self) -> bool {
self.0.contains("freebsd")
}

/// Returns true if this target triple contains the word "apple"
pub fn is_apple(&self) -> bool {
self.0.contains("apple")
Expand Down
34 changes: 32 additions & 2 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,13 @@ fn github_runner_for_target(
} else {
runner_to_config(GithubRunnerRef::from_str("windows-2022"))
}
},
OperatingSystem::Freebsd => {
if target_triple.architecture == Architecture::X86_64 {
runner_to_config(GithubRunnerRef::from_str("ubuntu-latest"))
} else {
return Ok(None);
}
}
_ => return Ok(None),
});
Expand Down Expand Up @@ -744,6 +751,9 @@ fn system_deps_install_script(
let mut chocolatey_packages: SortedSet<(ChocolateyPackageName, Option<PackageVersion>)> =
Default::default();

let binstall_needed = targets.iter().any(|t| t.is_freebsd());

let mut lines = Vec::<String>::new();
let host = rc.real_triple();
match host.operating_system {
OperatingSystem::Darwin(_) => {
Expand All @@ -755,9 +765,16 @@ fn system_deps_install_script(
continue;
}
brew_packages.insert(name.clone());
if binstall_needed {
brew_packages.insert(HomebrewPackageName::new("cargo-binstall".to_string()));
}
}
}
OperatingSystem::Linux => {
// We can use Freebsd here because it is getting cross-compiled from Linux
OperatingSystem::Freebsd | OperatingSystem::Linux => {
if binstall_needed {
lines.push("curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash;".to_string());
}
// We currently don't support non-apt package managers on Linux
// is_none() means a native build, probably on GitHub's
// apt-using runners.
Expand Down Expand Up @@ -786,6 +803,9 @@ fn system_deps_install_script(
}
}
OperatingSystem::Windows => {
if binstall_needed {
lines.push("Set-ExecutionPolicy Unrestricted -Scope Process; iex (iwr \"https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1\").Content".to_string());
}
for (name, pkg) in &packages.chocolatey {
if !pkg.0.stage_wanted(&DependencyKind::Build) {
continue;
Expand All @@ -804,7 +824,6 @@ fn system_deps_install_script(
}
}

let mut lines = vec![];
if !brew_packages.is_empty() {
lines.push(brew_bundle_command(brew_packages.iter()))
}
Expand Down Expand Up @@ -852,6 +871,11 @@ fn system_deps_install_script(
pip_pkgs.insert(PipPackageName::new("cargo-xwin".to_owned()));
}

let mut cargo_binstall_pkgs: SortedSet<String> = Default::default();
if required_wrappers.contains(&CargoBuildWrapper::Cross) {
cargo_binstall_pkgs.insert("cross".to_string());
}

if !pip_pkgs.is_empty() {
let push_pip_install_lines = |lines: &mut Vec<String>| {
if host.operating_system == OperatingSystem::Linux {
Expand Down Expand Up @@ -890,6 +914,12 @@ fn system_deps_install_script(
}
}

if !cargo_binstall_pkgs.is_empty() {
// lines.push()
let to_install_packages = cargo_binstall_pkgs.into_iter().join(" ");
lines.push(format!("cargo binstall {to_install_packages}"))
}

Ok(if lines.is_empty() {
None
} else {
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/src/backend/ci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub trait InstallStrategy {
/// Return the right install method for a given set of targets
fn for_triple(&self, triple: &Triple) -> GhaRunStep {
match triple.operating_system {
OperatingSystem::Linux | OperatingSystem::Darwin(_) => self.dash(),
OperatingSystem::Freebsd | OperatingSystem::Linux | OperatingSystem::Darwin(_) => self.dash(),
OperatingSystem::Windows => self.powershell(),
_ => panic!("unsupported host triple {triple}"),
}
Expand Down
33 changes: 22 additions & 11 deletions cargo-dist/src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn make_build_cargo_target_command(
rustflags: &str,
step: &CargoBuildStep,
auditable: bool,
) -> DistResult<Cmd> {
) -> DistResult<(Cmd, Option<CargoBuildWrapper>)> {
let target: Triple = step.target_triple.parse()?;

eprint!("building {target} target");
Expand All @@ -186,9 +186,11 @@ pub fn make_build_cargo_target_command(
if auditable {
command.arg("auditable");
}
match wrapper {
let wrapper = match wrapper {
None => {
command.arg("build");

None
}
Some(CargoBuildWrapper::ZigBuild) => {
if auditable {
Expand All @@ -198,19 +200,29 @@ pub fn make_build_cargo_target_command(
});
}
command.arg("zigbuild");

Some(CargoBuildWrapper::ZigBuild)
}
Some(CargoBuildWrapper::Xwin) => {
// cf. <https://github.com/rust-cross/cargo-xwin?tab=readme-ov-file#customization>
let arch = match target.architecture {
Architecture::X86_32(_) => "x86",
Architecture::X86_64 => "x86_64",
Architecture::Aarch64(_) => "aarch64",
_ => panic!("cargo-xwin doesn't support {target} because of its architecture",),
_ => panic!("cargo-xwin doesn't support {target} because of its architecture", ),
};
command.env("XWIN_ARCH", arch);
command.arg("xwin").arg("build");

Some(CargoBuildWrapper::Xwin)
}
}
Some(CargoBuildWrapper::Cross) => {
command = Cmd::new("cross", "Cross compile using cross.");
command.arg("build");

Some(CargoBuildWrapper::Cross)
}
};
command
.arg("--profile")
.arg(&step.profile)
Expand Down Expand Up @@ -249,7 +261,7 @@ pub fn make_build_cargo_target_command(
}
}

Ok(command)
Ok((command, wrapper))
}

/// Build a cargo target
Expand All @@ -273,7 +285,7 @@ pub fn build_cargo_target(

let auditable = dist_graph.config.builds.cargo.cargo_auditable;
let host = dist_schema::target_lexicon::HOST;
let mut command =
let (mut command, wrapper) =
make_build_cargo_target_command(&host, &cargo.cmd, &rustflags, step, auditable)?;

// If we generated any extra environment variables to
Expand All @@ -298,7 +310,7 @@ pub fn build_cargo_target(
match message {
cargo_metadata::Message::CompilerArtifact(artifact) => {
// Hey we got some files, record that fact
expected.found_bins(artifact.package_id.to_string(), artifact.filenames);
expected.found_bins(artifact.package_id.to_string(), artifact.filenames, wrapper);
}
_ => {
// Nothing else interesting?
Expand Down Expand Up @@ -334,7 +346,6 @@ fn determine_brew_rustflags(base_rustflags: &str, environment: &SortedMap<&str,

#[cfg(test)]
mod tests {

use super::make_build_cargo_target_command;
use crate::platform::targets;
use crate::tasks::{CargoTargetFeatureList, CargoTargetFeatures, CargoTargetPackages};
Expand All @@ -360,14 +371,14 @@ mod tests {
working_dir: ".".to_string().into(), // this feels mildly cursed -duckinator.
};

let cmd = make_build_cargo_target_command(
let (cmd, _) = make_build_cargo_target_command(
&step.target_triple.parse().unwrap(),
&cargo_cmd,
&rustflags,
&step,
auditable,
)
.unwrap();
.unwrap();

let mut args = cmd.inner.get_args();

Expand Down Expand Up @@ -395,7 +406,7 @@ mod tests {
working_dir: ".".to_string().into(), // this feels mildly cursed -duckinator.
};

let cmd = make_build_cargo_target_command(
let (cmd, _) = make_build_cargo_target_command(
&step.target_triple.parse().unwrap(),
&cargo_cmd,
&rustflags,
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/src/build/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn build_fake_binaries(
let real_fake_bin = tempdir.join(&binary.file_name);
let package_id = super::package_id_string(binary.pkg_id.as_ref());
LocalAsset::write_new_all("", &real_fake_bin)?;
expectations.found_bins(package_id, vec![real_fake_bin]);
expectations.found_bins(package_id, vec![real_fake_bin], None);
}

expectations.process_bins(dist, manifest)?;
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/src/build/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub fn build_generic_target(
for binary_idx in &target.expected_binaries {
let binary = dist_graph.binary(*binary_idx);
let src_path = target.out_dir.join(&binary.file_name);
expected.found_bins(package_id_string(binary.pkg_id.as_ref()), vec![src_path]);
expected.found_bins(package_id_string(binary.pkg_id.as_ref()), vec![src_path], None);
}

// Check and process the binaries
Expand Down
18 changes: 12 additions & 6 deletions cargo-dist/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use camino::Utf8PathBuf;
use dist_schema::{AssetInfo, DistManifest, TripleNameRef};
use tracing::info;

use crate::{
copy_file, linkage::determine_linkage, Binary, BinaryIdx, BinaryKind, DistError, DistGraph,
DistResult, SortedMap,
};
use crate::{copy_file, linkage::determine_linkage, Binary, BinaryIdx, BinaryKind, CargoBuildWrapper, DistError, DistGraph, DistResult, SortedMap};

pub mod cargo;
pub mod fake;
Expand Down Expand Up @@ -89,7 +86,7 @@ impl BuildExpectations {
///
/// NOTE: it is correct/expected to hand this a bunch of random paths to things
/// that vaguely might be what we want, assuming it knows how to pick the right ones out.
pub fn found_bins(&mut self, pkg_id: String, filenames: Vec<Utf8PathBuf>) {
pub fn found_bins(&mut self, pkg_id: String, filenames: Vec<Utf8PathBuf>, wrapper: Option<CargoBuildWrapper>) {
// The files we're given by cargo are one big mush of
// the executables, libraries, symbols, etc.
// Try to partition this into what's probably symbols
Expand All @@ -111,7 +108,16 @@ impl BuildExpectations {
// of feature resolution), this can produce a bunch of binaries for examples or
// packages you don't care about, which cargo/rustc will happily report back to us,
// and we need to be aware enough to throw those irrelevant results out.
for src_path in maybe_bins {
for mut src_path in maybe_bins {
// Due to cross being docker based we get a weird absolute path back from the analytics
// that starts with `/target`.
// To handle these kinds of path we simply convert them to relative path.
if wrapper.eq(&Some(CargoBuildWrapper::Cross)) && src_path.starts_with("/target") {
if let Ok(path) = src_path.strip_prefix("/") {
src_path = Utf8PathBuf::from(path);
}
}

info!("got a new binary: {}", src_path);

// lookup the binary in the package
Expand Down
6 changes: 6 additions & 0 deletions cargo-dist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn do_env_test(cfg: &Config) -> DistResult<()> {
let need_omnibor = builds.omnibor;
let mut need_xwin = false;
let mut need_zigbuild = false;
let mut need_cross = false;

let tools = dist.tools;
let host = tools.host_target.parse()?;
Expand All @@ -95,6 +96,9 @@ pub fn do_env_test(cfg: &Config) -> DistResult<()> {
Some(CargoBuildWrapper::ZigBuild) => {
need_zigbuild = true;
}
Some(CargoBuildWrapper::Cross) => {
need_cross = true;
}
None => {}
}
}
Expand All @@ -111,6 +115,7 @@ pub fn do_env_test(cfg: &Config) -> DistResult<()> {
need_omnibor.then(|| tools.omnibor()),
need_xwin.then(|| tools.cargo_xwin()),
need_zigbuild.then(|| tools.cargo_zigbuild()),
need_cross.then(|| tools.cargo_cross()),
];

// Drop `None`s, then extract the values from the remaining `Option`s.
Expand Down Expand Up @@ -990,5 +995,6 @@ pub fn known_desktop_targets() -> Vec<TripleName> {
t::TARGET_ARM64_MAC.to_owned(),
t::TARGET_ARM64_LINUX_GNU.to_owned(),
t::TARGET_ARM64_WINDOWS.to_owned(),
t::TARGET_X64_FREEBSD.to_owned(),
]
}
2 changes: 1 addition & 1 deletion cargo-dist/src/linkage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub fn determine_linkage(path: &Utf8PathBuf, target: &TripleNameRef) -> Linkage
fn try_determine_linkage(path: &Utf8PathBuf, target: &TripleNameRef) -> DistResult<Linkage> {
let libraries = if target.is_darwin() {
do_otool(path)?
} else if target.is_linux() {
} else if target.is_linux() || target.is_freebsd() {
// Currently can only be run on Linux
if std::env::consts::OS != "linux" {
return Err(DistError::LinkageCheckInvalidOS {
Expand Down
3 changes: 3 additions & 0 deletions cargo-dist/src/platform/github_runners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ lazy_static::lazy_static! {
m.insert(GithubRunnerRef::from_str("macos-latest"), t::TARGET_ARM64_MAC);
m.insert(GithubRunnerRef::from_str("macos-latest-xlarge"), t::TARGET_ARM64_MAC);

//-------- FreeBSD
m.insert(GithubRunnerRef::from_str("ubuntu-latest"), t::TARGET_X64_FREEBSD);

m
};
}
Expand Down
Loading