Skip to content

Commit

Permalink
userland target as string
Browse files Browse the repository at this point in the history
Signed-off-by: qjerome <[email protected]>
  • Loading branch information
qjerome committed Dec 18, 2023
1 parent 3e742f7 commit 7906fcc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
2 changes: 1 addition & 1 deletion xtask/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Options {
pub update: bool,
/// target to build the build-tools for
#[clap(default_value = "x86_64-unknown-linux-gnu", long)]
pub target: super::user::Target,
pub target: String,
}

pub struct LLVMBuilder {
Expand Down
40 changes: 5 additions & 35 deletions xtask/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,14 @@ use clap::Parser;

use crate::ebpf::{self, BpfTarget};

#[derive(Debug, Copy, Clone)]
pub enum Target {
X86_64Musl,
X86_64Gnu,
Aarch64Musl,
}

impl std::str::FromStr for Target {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"x86_64-unknown-linux-musl" => Target::X86_64Musl,
"x86_64-unknown-linux-gnu" => Target::X86_64Gnu,
"aarch64-unknown-linux-musl" => Target::Aarch64Musl,
_ => return Err("invalid target".to_owned()),
})
}
}

impl std::fmt::Display for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Target::X86_64Musl => "x86_64-unknown-linux-musl",
Target::X86_64Gnu => "x86_64-unknown-linux-gnu",
Target::Aarch64Musl => "aarch64-unknown-linux-musl",
})
}
}

#[derive(Debug, Parser)]
pub struct RunOptions {
/// Build and run the release target
#[clap(long)]
pub release: bool,
/// Set the endianness of the BPF target
/// Specify the building target for userland
#[clap(default_value = "x86_64-unknown-linux-musl", long)]
pub target: Target,
pub target: String,
/// Set the endianness of the BPF target
#[clap(default_value = "bpfel-unknown-none", long)]
pub bpf_target: BpfTarget,
Expand All @@ -69,7 +39,7 @@ impl From<RunOptions> for BuildOptions {
impl From<&RunOptions> for BuildOptions {
fn from(value: &RunOptions) -> Self {
Self {
target: value.target,
target: value.target.clone(),
linker: None,
bpf_target: value.bpf_target,
bpf_linker: value.bpf_linker.clone(),
Expand All @@ -85,9 +55,9 @@ pub struct BuildOptions {
/// Build and run the release target
#[clap(long)]
pub release: bool,
/// Set the endianness of the BPF target
/// Specify the building target for userland
#[clap(default_value = "x86_64-unknown-linux-musl", long)]
pub target: Target,
pub target: String,
/// Set the linker to use to when building userland application
/// this option is useful when cross-compiling
#[clap(long)]
Expand Down

0 comments on commit 7906fcc

Please sign in to comment.