Skip to content

Commit

Permalink
Merge pull request #66 from TheWaWaR/allow-custom-toolchain-dir
Browse files Browse the repository at this point in the history
feat: allow custom rustup dir
  • Loading branch information
TheWaWaR authored Aug 19, 2022
2 parents 9f39477 + 0330ae2 commit d367373
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/bin/capsule.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::env;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::exit;
use std::str::FromStr;

Expand Down Expand Up @@ -104,6 +104,7 @@ fn run_cli() -> Result<()> {
.arg(Arg::with_name("release").long("release").help("Build contracts in release mode."))
.arg(Arg::with_name("debug-output").long("debug-output").help("Always enable debugging output"))
.arg(Arg::with_name("host").long("host").help("Docker runs in host mode"))
.arg(Arg::with_name("rustup-dir").long("rustup-dir").takes_value(true).help("Mount the directory to /root/.rustup in docker image"))
.display_order(3))
.subcommand(SubCommand::with_name("run").about("Run command in contract build image").usage("ckb_capsule run --name <name> 'echo list contract dir: && ls'")
.args(&[Arg::with_name("name").short("n").long("name").required(true).takes_value(true).help("contract name"),
Expand Down Expand Up @@ -279,8 +280,22 @@ fn run_cli() -> Result<()> {
BuildEnv::Debug
};
let always_debug = args.is_present("debug-output");
let rustup_dir = args
.value_of("rustup-dir")
.map(|value| {
let path = Path::new(value);
if !path.exists() {
return Err(anyhow!("rustup path not exists: {}", value));
}
if !path.is_dir() {
return Err(anyhow!("rustup path is not directory: {}", value));
}
Ok(value.to_string())
})
.transpose()?;
context.use_docker_host = args.is_present("host");
context.docker_env_file = docker_env_file;
context.rustup_dir = rustup_dir;
let build_config = BuildConfig {
build_env,
always_debug,
Expand Down
2 changes: 2 additions & 0 deletions src/project_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct Context {
pub config: Config,
pub use_docker_host: bool,
pub docker_env_file: String,
pub rustup_dir: Option<String>,
}

impl Context {
Expand Down Expand Up @@ -92,6 +93,7 @@ impl Context {
project_path,
use_docker_host: false,
docker_env_file: String::new(),
rustup_dir: None,
})
}

Expand Down
6 changes: 5 additions & 1 deletion src/recipe/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Recipe for Rust {
fn run(&self, contract: &Contract, build_cmd: String, signal: &Signal) -> Result<()> {
let project_path = self.context.project_path.to_str().expect("path");
let contract_relative_path = self.contract_relative_path(&contract.name);
let cmd = DockerCommand::with_context(
let mut cmd = DockerCommand::with_context(
&self.context,
self.docker_image(),
project_path.to_string(),
Expand All @@ -181,6 +181,9 @@ impl Recipe for Rust {
.fix_dir_permission("/code/target".to_string())
.fix_dir_permission("/code/Cargo.lock".to_string())
.host_network(self.context.use_docker_host);
if let Some(rustup_dir) = self.context.rustup_dir.as_ref() {
cmd = cmd.map_volume(rustup_dir.to_string(), "/root/.rustup".to_string());
}

cmd.run(build_cmd, &signal)?;
Ok(())
Expand Down Expand Up @@ -224,6 +227,7 @@ impl Recipe for Rust {
rust_target = RUST_TARGET,
build_env = build_cmd_opt
);
log::debug!("[build cmd]: {}", build_cmd);
self.run(contract, build_cmd, signal)?;

// copy to build dir
Expand Down
2 changes: 1 addition & 1 deletion templates/capsule.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# capsule version
version = "{{ version }}"
# path of deployment config file
deployment = "deployment.toml"
deployment = "deployment.toml"

0 comments on commit d367373

Please sign in to comment.