mirror of
https://framagit.org/ppom/reaction
synced 2026-03-14 20:55:47 +01:00
Cross-compile C binaries too
This commit is contained in:
parent
8f5511b415
commit
ccd9f53758
1 changed files with 21 additions and 5 deletions
26
build.rs
26
build.rs
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
env::var_os,
|
||||
env::{var, var_os},
|
||||
io::{self, ErrorKind},
|
||||
path::Path,
|
||||
process,
|
||||
|
|
@ -10,8 +10,22 @@ use clap_complete::shells;
|
|||
// SubCommand defined here
|
||||
include!("src/cli.rs");
|
||||
|
||||
fn compile_helper(name: &str, out_dir: &Path) -> io::Result<()> {
|
||||
process::Command::new("gcc")
|
||||
fn gcc() -> String {
|
||||
// TARGET looks like aarch64-unknown-linux-musl
|
||||
match var("TARGET") {
|
||||
Ok(target) => {
|
||||
// We're looking for an environment variable looking like
|
||||
// CC_aarch64_unknown_linux_musl
|
||||
let target = target.replace("-", "_");
|
||||
var(format!("CC_{}", target.replace("-", "_"))).ok()
|
||||
}
|
||||
Err(_) => None,
|
||||
}
|
||||
.unwrap_or("gcc".into())
|
||||
}
|
||||
|
||||
fn compile_helper(cc: &str, name: &str, out_dir: &Path) -> io::Result<()> {
|
||||
process::Command::new(cc)
|
||||
.args([
|
||||
&format!("helpers_c/{name}.c"),
|
||||
"-o",
|
||||
|
|
@ -26,8 +40,10 @@ fn main() -> io::Result<()> {
|
|||
let out_dir = PathBuf::from(var_os("OUT_DIR").ok_or(ErrorKind::NotFound)?).join("../../..");
|
||||
|
||||
// Compile C helpers
|
||||
compile_helper("ip46tables", &out_dir)?;
|
||||
compile_helper("nft46", &out_dir)?;
|
||||
let cc = gcc();
|
||||
println!("CC is: {}", cc);
|
||||
compile_helper(&cc, "ip46tables", &out_dir)?;
|
||||
compile_helper(&cc, "nft46", &out_dir)?;
|
||||
|
||||
// Build CLI
|
||||
let cli = clap::Command::new("reaction");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue