Skip to content

Commit

Permalink
Merge pull request #154 from serpent-os/task/deasyncify
Browse files Browse the repository at this point in the history
Deasyncify all but network fetching
  • Loading branch information
ikeycode authored Mar 2, 2024
2 parents c888db2 + 9f5ea30 commit 4acc6c9
Show file tree
Hide file tree
Showing 56 changed files with 1,573 additions and 1,936 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions boulder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition.workspace = true
config = { path = "../crates/config" }
container = { path = "../crates/container" }
moss = { path = "../moss" }
stone = { path = "../crates/stone" }
stone_recipe = { path = "../crates/stone_recipe" }
tui = { path = "../crates/tui" }
yaml = { path = "../crates/yaml" }
Expand Down
31 changes: 20 additions & 11 deletions boulder/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use std::{
os::unix::process::ExitStatusExt,
path::{Path, PathBuf},
process, thread,
time::Duration,
};

use itertools::Itertools;
use moss::runtime;
use nix::{
sys::signal::Signal,
unistd::{getpgrp, setpgid, Pid},
Expand All @@ -31,7 +33,7 @@ use crate::{
architecture::BuildTarget,
container, macros,
package::{self, Packager},
profile, recipe, util, Env, Macros, Paths, Recipe, Runtime,
profile, recipe, util, Env, Macros, Paths, Recipe,
};

pub struct Builder {
Expand Down Expand Up @@ -103,18 +105,25 @@ impl Builder {
pub fn setup(&self) -> Result<(), Error> {
root::clean(self)?;

let rt = Runtime::new()?;
rt.block_on(async {
let profiles = profile::Manager::new(&self.env).await;
let rt = runtime::init();

let repos = profiles.repositories(&self.profile)?.clone();
let profiles = profile::Manager::new(&self.env);
let repos = profiles.repositories(&self.profile)?.clone();

root::populate(self, repos).await?;
upstream::sync(&self.recipe, &self.paths).await?;
root::populate(self, repos)?;
upstream::sync(&self.recipe, &self.paths)?;

Ok(()) as Result<_, Error>
})?;
rt.destroy();
// We want to ensure no threads exist before
// cloning into container. Sometimes a deadlock
// occurs which appears related to a race condition
// from some thread artifacts still existing. Adding
// this delay allows things to get cleaned up.
// NOTE: This appears to reliably fix the problem,
// I ran boulder 100 times w/ and w/out this delay
// and the deadlock never occured w/ it, but w/out
// it occured within 10 attempts.
thread::sleep(Duration::from_millis(50));

Ok(())
}
Expand Down Expand Up @@ -143,11 +152,11 @@ impl Builder {
let is_pgo = job.pgo_stage.is_some();

// Recreate work dir for each job
util::sync::recreate_dir(&job.work_dir)?;
util::recreate_dir(&job.work_dir)?;
// Ensure pgo dir exists
if is_pgo {
let pgo_dir = PathBuf::from(format!("{}-pgo", job.build_dir.display()));
util::sync::ensure_dir_exists(&pgo_dir)?;
util::ensure_dir_exists(&pgo_dir)?;
}

if let Some(stage) = job.pgo_stage {
Expand Down
23 changes: 14 additions & 9 deletions boulder/src/build/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@
use std::collections::HashSet;
use std::io;

use moss::repository;
use moss::{repository, runtime};
use stone_recipe::{tuning::Toolchain, Upstream};
use thiserror::Error;

use crate::build::Builder;
use crate::{container, util};

pub async fn populate(builder: &Builder, repositories: repository::Map) -> Result<(), Error> {
pub fn populate(builder: &Builder, repositories: repository::Map) -> Result<(), Error> {
let packages = packages(builder);

let rootfs = builder.paths.rootfs().host;

// Recreate root
util::recreate_dir(&rootfs).await?;
util::recreate_dir(&rootfs)?;

let mut moss_client = moss::Client::with_explicit_repositories("boulder", &builder.env.moss_dir, repositories)
.await?
.ephemeral(&rootfs)?;
// Create the moss client
let mut moss_client =
moss::Client::with_explicit_repositories("boulder", &builder.env.moss_dir, repositories)?.ephemeral(&rootfs)?;

moss_client.install(&packages, true).await?;
// Ensure all configured repos have been initialized (important since users
// might add profile configs from an editor)
runtime::block_on(moss_client.ensure_repos_initialized())?;

// Install packages
moss_client.install(&packages, true)?;

Ok(())
}
Expand All @@ -40,12 +45,12 @@ pub fn clean(builder: &Builder) -> Result<(), Error> {
// and there's subuid mappings into the user namespace
container::exec(&builder.paths, false, || {
// Recreate `install` dir
util::sync::recreate_dir(&builder.paths.install().guest)?;
util::recreate_dir(&builder.paths.install().guest)?;

for target in &builder.targets {
for job in &target.jobs {
// Recerate build dir
util::sync::recreate_dir(&job.build_dir)?;
util::recreate_dir(&job.build_dir)?;
}
}

Expand Down
Loading

0 comments on commit 4acc6c9

Please sign in to comment.