linera-io/linera-protocol · error · anyhow::Error

build failed

Error message

build failed

What it means

Project::build compiles the application's contract and service with `cargo build --release --target wasm32-unknown-unknown` and reports any non-zero cargo exit as 'build failed'. On success it returns the two .wasm artifacts from workspace target/wasm32-unknown-unknown/release/.

Source

Thrown at linera-service/src/project.rs:304

        (linera_sdk_dep, linera_sdk_dev_dep)
    }

    /// Builds the project's contract and service to Wasm, returning their bytecode paths.
    pub fn build(&self, name: Option<String>) -> Result<(PathBuf, PathBuf), anyhow::Error> {
        let name = match name {
            Some(name) => name,
            None => self.project_package_name()?.replace('-', "_"),
        };
        let contract_name = format!("{name}_contract");
        let service_name = format!("{name}_service");
        let cargo_build = Command::new("cargo")
            .arg("build")
            .arg("--release")
            .args(["--target", "wasm32-unknown-unknown"])
            .current_dir(&self.root)
            .spawn()?
            .wait()?;
        ensure!(cargo_build.success(), "build failed");
        let build_path = self
            .workspace_root()?
            .join("target/wasm32-unknown-unknown/release");
        Ok((
            build_path.join(contract_name).with_extension("wasm"),
            build_path.join(service_name).with_extension("wasm"),
        ))
    }

    fn project_package_name(&self) -> Result<String> {
        let manifest = Manifest::from_path(self.cargo_toml_path())?;
        let name = manifest
            .package
            .context("Cargo.toml is missing `[package]`")?
            .name;
        Ok(name)
    }

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Run `cargo build --release --target wasm32-unknown-unknown` in the project directory yourself to see the real compiler error
  2. Install the target if missing: `rustup target add wasm32-unknown-unknown`
  3. Fix compile errors or replace non-wasm-compatible dependencies in contract/service code
  4. Pin dependency versions in the application project to avoid surprise breakage

Example fix

# before
$ linera project publish .
error: build failed

# after
$ rustup target add wasm32-unknown-unknown
$ cd my-dapp && cargo build --release --target wasm32-unknown-unknown   # shows the real error; fix it
$ cd .. && linera project publish .
Defensive patterns

Strategy: validation

Validate before calling

let out = std::process::Command::new("cargo")
    .args(["check", "--target", "wasm32-unknown-unknown"])
    .current_dir(&project_dir)
    .output()?;
if !out.status.success() {
    eprintln!("{}", String::from_utf8_lossy(&out.stderr)); // surface the real error early
}

Prevention

When it happens

Trigger: `linera project publish` or Project::build where cargo fails: a compile error in the application, the wasm32-unknown-unknown target or required toolchain not installed, or dependency resolution failure.

Common situations: Fresh machine without `rustup target add wasm32-unknown-unknown`; application code using crates that do not compile to wasm (std networking, file IO); dependency drift after an unchecked cargo update.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/8a10d1d6c167ff84. Report an issue: GitHub.