Implement builds, add some recipes

This commit is contained in:
Jeremy Soller 2020-05-20 15:44:37 -06:00
parent fa00a61b95
commit 204e968016
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
9 changed files with 5819 additions and 38 deletions

6
.gitignore vendored
View File

@ -12,3 +12,9 @@ stage.tar.gz
stage.toml
sysroot
xargo
#Added by cargo
/target
**/*.rs.bk

6
recipes/acid/recipe.toml Normal file
View File

@ -0,0 +1,6 @@
[source]
git = "https://gitlab.redox-os.org/redox-os/acid.git"
branch = "master"
[build]
template = "cargo"

View File

@ -0,0 +1,8 @@
[source]
tar = "https://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz"
patches = [
"redox.patch"
]
[build]
template = "configure"

2820
recipes/libffi/redox.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
[source]
tar = "http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz"
blake3 = "8220c0e4082fa26c07b10bfe31f641d2e33ebe1d1bb0b20221b7016bc8b78a3a"
patches = [
"redox.patch"
]
[build]
template = "configure"

2833
recipes/libogg/redox.patch Normal file

File diff suppressed because it is too large Load Diff

8
recipes/pcre/recipe.toml Normal file
View File

@ -0,0 +1,8 @@
[source]
tar = "https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.bz2"
patches = [
"redox.patch"
]
[build]
template = "configure"

View File

@ -58,6 +58,48 @@ fn run_command(mut command: process::Command) -> Result<(), String> {
Ok(())
}
fn run_command_stdin(mut command: process::Command, stdin_data: &[u8]) -> Result<(), String> {
command.stdin(Stdio::piped());
let mut child = command.spawn().map_err(|err| format!(
"failed to spawn {:?}: {}\n{:#?}",
command,
err,
err
))?;
if let Some(ref mut stdin) = child.stdin {
stdin.write_all(stdin_data).map_err(|err| format!(
"failed to write stdin of {:?}: {}\n{:#?}",
command,
err,
err
))?;
} else {
return Err(format!(
"failed to find stdin of {:?}",
command
));
}
let status = child.wait().map_err(|err| format!(
"failed to run {:?}: {}\n{:#?}",
command,
err,
err
))?;
if ! status.success() {
return Err(format!(
"failed to run {:?}: exited with status {}",
command,
status
));
}
Ok(())
}
fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> {
let source_dir = recipe_dir.join("source");
match source {
@ -73,7 +115,7 @@ fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> {
if let Some(branch) = branch {
command.arg("--branch").arg(&branch);
}
command.arg(&source_dir);
command.arg(&source_dir_tmp);
run_command(command)?;
// Move source.tmp to source atomically
@ -221,43 +263,7 @@ fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> {
let mut command = Command::new("patch");
command.arg("--directory").arg(&source_dir_tmp);
command.arg("--strip=1");
command.stdin(Stdio::piped());
let mut child = command.spawn().map_err(|err| format!(
"failed to spawn {:?}: {}\n{:#?}",
command,
err,
err
))?;
if let Some(ref mut stdin) = child.stdin {
stdin.write_all(patch.as_bytes()).map_err(|err| format!(
"failed to write stdin of {:?}: {}\n{:#?}",
command,
err,
err
))?;
} else {
return Err(format!(
"failed to find stdin of {:?}",
command
));
}
let status = child.wait().map_err(|err| format!(
"failed to run {:?}: {}\n{:#?}",
command,
err,
err
))?;
if ! status.success() {
return Err(format!(
"failed to run {:?}: exited with status {}",
command,
status
));
}
run_command_stdin(command, patch.as_bytes())?;
}
// Move source.tmp to source atomically
@ -269,6 +275,83 @@ fn fetch(recipe_dir: &Path, source: &SourceRecipe) -> Result<PathBuf, String> {
Ok(source_dir)
}
fn build(recipe_dir: &Path, source_dir: &Path, build: &BuildRecipe) -> Result<PathBuf, String> {
let stage_dir = recipe_dir.join("stage");
if ! stage_dir.is_dir() {
// Create stage.tmp
let stage_dir_tmp = recipe_dir.join("stage.tmp");
create_dir_clean(&stage_dir_tmp)?;
// Create build, if it does not exist
//TODO: flag for clean builds where build is wiped out
let build_dir = recipe_dir.join("build");
if ! build_dir.is_dir() {
create_dir_clean(&build_dir)?;
}
//TODO: better integration with redoxer (library instead of binary)
//TODO: configurable target
match build {
BuildRecipe::Cargo => {
let mut command = Command::new("redoxer");
command.arg("install");
//TODO: --debug if desired
command.arg("--path").arg(&source_dir);
command.arg("--root").arg(&stage_dir_tmp);
command.env("CARGO_TARGET_DIR", &build_dir);
run_command(command)?;
},
BuildRecipe::Configure => {
//TODO: Add more configurability, convert script to Rust
let mut command = Command::new("redoxer");
command.arg("env");
command.arg("bash").arg("-ex");
//TODO: remove unwraps
command.env("COOKBOOK_STAGE", &stage_dir_tmp.canonicalize().unwrap());
command.env("COOKBOOK_SOURCE", &source_dir.canonicalize().unwrap());
command.current_dir(&build_dir);
run_command_stdin(command, r#"
export LDFLAGS="--static"
"${COOKBOOK_SOURCE}/configure" \
--host="${TARGET}" \
--prefix="" \
--disable-shared \
--enable-static
make -j "$(nproc)"
make install DESTDIR="${COOKBOOK_STAGE}"
# Strip binaries
if [ -d "${COOKBOOK_STAGE}/bin" ]
then
find "${COOKBOOK_STAGE}/bin" -type f -exec "${TARGET}-strip" -v {} ';'
fi
# Remove libtool files
if [ -d "${COOKBOOK_STAGE}/lib" ]
then
find "${COOKBOOK_STAGE}/lib" -type f -name '*.la' -exec rm -fv {} ';'
fi
"#.as_bytes())?;
},
BuildRecipe::Custom { script } => {
let mut command = Command::new("redoxer");
command.arg("env");
command.arg("bash").arg("-ex");
//TODO: remove unwraps
command.env("COOKBOOK_STAGE", &stage_dir_tmp.canonicalize().unwrap());
command.env("COOKBOOK_SOURCE", &source_dir.canonicalize().unwrap());
command.current_dir(&build_dir);
run_command_stdin(command, script.as_bytes())?;
},
}
// Move stage.tmp to stage atomically
rename(&stage_dir_tmp, &stage_dir)?;
}
Ok(stage_dir)
}
fn cook(recipe_name: &str) -> Result<(), String> {
//TODO: sanitize recipe name?
let recipe_dir = Path::new("recipes").join(recipe_name);
@ -306,6 +389,11 @@ fn cook(recipe_name: &str) -> Result<(), String> {
err
))?;
let stage_dir = build(&recipe_dir, &source_dir, &recipe.build).map_err(|err| format!(
"failed to build: {}",
err
))?;
Ok(())
}

View File

@ -39,6 +39,9 @@ pub enum BuildRecipe {
/// Will build and install using cargo
#[serde(rename = "cargo")]
Cargo,
/// Will build and install using configure and make
#[serde(rename = "configure")]
Configure,
/// Will build and install using custom commands
#[serde(rename = "custom")]
Custom {