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
7 changes: 6 additions & 1 deletion crates/icp-app/src/context/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ pub fn initialize(
pkg_cache,
});

// The project's files come from this machine.
let files = Arc::new(icp_project::files::HostFileSystem);

// Canister builder
let builder = Arc::new(Builder::new(wasm.clone()));
let builder = Arc::new(Builder::new(wasm.clone(), files.clone()));

// Canister syncer
let syncer = Arc::new(Syncer::host(wasm.clone()));
Expand All @@ -116,6 +119,7 @@ pub fn initialize(
let pload = ProjectLoadImpl {
project_root_locate: project_root_locate.clone(),
recipe,
files: files.clone(),
};

let pload = Lazy::new(pload);
Expand Down Expand Up @@ -153,6 +157,7 @@ pub fn initialize(
Ok(Context {
host: Host {
project: pload,
files,
ids,
artifacts,
builder,
Expand Down
1 change: 1 addition & 0 deletions crates/icp-cli/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub(crate) async fn exec(ctx: &Context, args: &BuildArgs) -> Result<(), anyhow::
environment_selection.name(),
ctx.host.builder.clone(),
ctx.host.artifacts.clone(),
ctx.host.files.as_ref(),
reporter,
)
.await
Expand Down
1 change: 1 addition & 0 deletions crates/icp-cli/src/commands/project/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub(crate) async fn exec(ctx: &Context, args: &BundleArgs) -> Result<(), anyhow:

rendered(ctx.debug, async |reporter| {
create_bundle(
ctx.host.files.as_ref(),
&project.dir,
canisters,
&selected,
Expand Down
12 changes: 12 additions & 0 deletions crates/icp-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ license = { workspace = true }
publish.workspace = true

[features]
default = ["host"]
# Implementations of this crate's seams that use the machine it is running on:
# the filesystem and the project-local `.icp` stores. Turned off for a build
# that has to run somewhere without them, such as inside a canister.
#
# It does not yet cover everything host-shaped here — the step runners still
# spawn subprocesses and drive a wasmtime sandbox unconditionally, `create`
# draws entropy from `rand`, and a bundle's plugin directories go through
# `tar`'s own directory walk. Each is a seam of its own to draw, and every
# dependency is still non-optional besides, so this is the boundary the feature
# claims rather than a canister target.
host = []
Comment thread
adamspofford-dfinity marked this conversation as resolved.
# Exposes this crate's mocks and fixtures so downstream crates can test against
# the same seams. Off in a normal build, so none of it ships.
test-util = []
Expand Down
16 changes: 11 additions & 5 deletions crates/icp-project/src/canister/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ pub trait Build: Sync + Send {
/// a pre-built step by asking [`wasm::Fetch`] for the module.
pub struct Builder {
wasm: Arc<dyn wasm::Fetch>,
files: Arc<dyn crate::files::FileSystem>,
}

impl Builder {
pub fn new(wasm: Arc<dyn wasm::Fetch>) -> Self {
Self { wasm }
pub fn new(wasm: Arc<dyn wasm::Fetch>, files: Arc<dyn crate::files::FileSystem>) -> Self {
Self { wasm, files }
}
}

Expand All @@ -57,9 +58,14 @@ impl Build for Builder {
reporter: &StepReporter,
) -> Result<(), BuildError> {
match step {
BuildStep::Prebuilt(adapter) => {
Ok(prebuilt::build(adapter, params, reporter, self.wasm.as_ref()).await?)
}
BuildStep::Prebuilt(adapter) => Ok(prebuilt::build(
adapter,
params,
reporter,
self.wasm.as_ref(),
self.files.as_ref(),
)
.await?),
BuildStep::Script(adapter) => Ok(script::build(adapter, params, reporter).await?),
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/icp-project/src/canister/build/prebuilt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use icp_events::StepReporter;
use snafu::prelude::*;

use crate::{canister::wasm, fs, manifest::adapter::prebuilt::Adapter};
use crate::{canister::wasm, manifest::adapter::prebuilt::Adapter};

use super::Params;

Expand All @@ -11,14 +11,15 @@ pub enum PrebuiltError {
Wasm { source: wasm::FetchError },

#[snafu(display("failed to copy wasm to output file"))]
CopyFile { source: crate::fs::CopyError },
CopyFile { source: crate::files::FsError },
}

pub(super) async fn build(
adapter: &Adapter,
params: &Params,
reporter: &StepReporter,
wasm: &dyn wasm::Fetch,
files: &dyn crate::files::FileSystem,
) -> Result<(), PrebuiltError> {
let src = wasm
.wasm(
Expand All @@ -30,7 +31,10 @@ pub(super) async fn build(
.await?;

reporter.info(format!("Writing WASM file: {}", params.output));
fs::copy(&src, &params.output).context(CopyFileSnafu)?;
files
.copy(&src, &params.output)
.await
.context(CopyFileSnafu)?;

Ok(())
}
Loading
Loading