Skip to content

Commit

Permalink
feat(proposal-cli): Support canisters outside the IC repository (#2074)
Browse files Browse the repository at this point in the history
Add support to the `proposal-cli` CLI tool for canisters outside the IC
repository, such as the EVM RPC canister.
  • Loading branch information
gregorydemay authored Oct 17, 2024
1 parent 7503772 commit 2e17a1e
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 69 deletions.
2 changes: 2 additions & 0 deletions rs/cross-chain/proposal-cli/src/candid/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ fn should_parse_constructor_parameters() {
if canister == TargetCanister::IcpArchive1
|| canister == TargetCanister::IcpArchive2
|| canister == TargetCanister::IcpArchive3
//canister lives outside the monorepo
|| canister == TargetCanister::EvmRpc
{
continue;
}
Expand Down
120 changes: 113 additions & 7 deletions rs/cross-chain/proposal-cli/src/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ mod tests;

use std::fmt::Display;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
use strum_macros::EnumIter;

#[derive(Clone, Eq, PartialEq, Debug, EnumIter)]
#[derive(Clone, Eq, PartialEq, Debug, Ord, PartialOrd, EnumIter)]
#[allow(clippy::enum_variant_names)]
pub enum TargetCanister {
CkBtcArchive,
Expand All @@ -24,6 +25,7 @@ pub enum TargetCanister {
IcpIndex,
IcpLedger,
LedgerSuiteOrchestrator,
EvmRpc,
}

impl TargetCanister {
Expand All @@ -40,6 +42,30 @@ impl TargetCanister {
TargetCanister::IcpIndex => "icp-index",
TargetCanister::IcpLedger => "icp-ledger",
TargetCanister::LedgerSuiteOrchestrator => "orchestrator",
TargetCanister::EvmRpc => "evm_rpc",
}
}

pub fn git_repository_url(&self) -> &str {
match &self {
TargetCanister::CkBtcArchive
| TargetCanister::CkBtcIndex
| TargetCanister::CkBtcKyt
| TargetCanister::CkBtcLedger
| TargetCanister::CkBtcMinter
| TargetCanister::CkEthArchive
| TargetCanister::CkEthIndex
| TargetCanister::CkEthLedger
| TargetCanister::CkEthMinter
| TargetCanister::IcpArchive1
| TargetCanister::IcpArchive2
| TargetCanister::IcpArchive3
| TargetCanister::IcpIndex
| TargetCanister::IcpLedger
| TargetCanister::LedgerSuiteOrchestrator => "https://github.com/dfinity/ic.git",
TargetCanister::EvmRpc => {
"https://github.com/internet-computer-protocol/evm-rpc-canister.git"
}
}
}

Expand Down Expand Up @@ -71,11 +97,31 @@ impl TargetCanister {
TargetCanister::LedgerSuiteOrchestrator => {
PathBuf::from("rs/ethereum/ledger-suite-orchestrator/ledger_suite_orchestrator.did")
}
TargetCanister::EvmRpc => PathBuf::from("candid/evm_rpc.did"),
}
}

pub fn repo_dir(&self) -> PathBuf {
self.candid_file().parent().unwrap().to_path_buf()
pub fn repo_dir(&self) -> Option<PathBuf> {
match &self {
TargetCanister::CkBtcArchive
| TargetCanister::CkBtcIndex
| TargetCanister::CkBtcKyt
| TargetCanister::CkBtcLedger
| TargetCanister::CkBtcMinter
| TargetCanister::CkEthArchive
| TargetCanister::CkEthIndex
| TargetCanister::CkEthLedger
| TargetCanister::CkEthMinter
| TargetCanister::IcpArchive1
| TargetCanister::IcpArchive2
| TargetCanister::IcpArchive3
| TargetCanister::IcpIndex
| TargetCanister::IcpLedger
| TargetCanister::LedgerSuiteOrchestrator => {
Some(self.candid_file().parent().unwrap().to_path_buf())
}
TargetCanister::EvmRpc => None,
}
}

pub fn git_log_dirs(&self) -> Vec<PathBuf> {
Expand Down Expand Up @@ -111,14 +157,41 @@ impl TargetCanister {
PathBuf::from("rs/ledger_suite/common/ledger_core/src"),
]
}
_ => {
vec![self.repo_dir()]
}
TargetCanister::CkBtcArchive
| TargetCanister::CkBtcIndex
| TargetCanister::CkBtcKyt
| TargetCanister::CkBtcLedger
| TargetCanister::CkBtcMinter
| TargetCanister::CkEthArchive
| TargetCanister::CkEthIndex
| TargetCanister::CkEthLedger
| TargetCanister::CkEthMinter
| TargetCanister::LedgerSuiteOrchestrator
| TargetCanister::EvmRpc => self.repo_dir().into_iter().collect(),
}
}

pub fn artifact(&self) -> PathBuf {
PathBuf::from("artifacts/canisters").join(self.artifact_file_name())
match &self {
TargetCanister::CkBtcArchive
| TargetCanister::CkBtcIndex
| TargetCanister::CkBtcKyt
| TargetCanister::CkBtcLedger
| TargetCanister::CkBtcMinter
| TargetCanister::CkEthArchive
| TargetCanister::CkEthIndex
| TargetCanister::CkEthLedger
| TargetCanister::CkEthMinter
| TargetCanister::IcpArchive1
| TargetCanister::IcpArchive2
| TargetCanister::IcpArchive3
| TargetCanister::IcpIndex
| TargetCanister::IcpLedger
| TargetCanister::LedgerSuiteOrchestrator => {
PathBuf::from("artifacts/canisters").join(self.artifact_file_name())
}
TargetCanister::EvmRpc => PathBuf::from(self.artifact_file_name()),
}
}

pub fn artifact_file_name(&self) -> &str {
Expand All @@ -140,9 +213,39 @@ impl TargetCanister {
TargetCanister::LedgerSuiteOrchestrator => {
"ic-ledger-suite-orchestrator-canister.wasm.gz"
}
TargetCanister::EvmRpc => "evm_rpc.wasm.gz",
}
}

pub fn build_artifact(&self) -> Command {
match &self {
TargetCanister::CkBtcArchive
| TargetCanister::CkBtcIndex
| TargetCanister::CkBtcKyt
| TargetCanister::CkBtcLedger
| TargetCanister::CkBtcMinter
| TargetCanister::CkEthArchive
| TargetCanister::CkEthIndex
| TargetCanister::CkEthLedger
| TargetCanister::CkEthMinter
| TargetCanister::IcpArchive1
| TargetCanister::IcpArchive2
| TargetCanister::IcpArchive3
| TargetCanister::IcpIndex
| TargetCanister::IcpLedger
| TargetCanister::LedgerSuiteOrchestrator => {
let mut cmd = Command::new("./ci/container/build-ic.sh");
cmd.arg("--canisters");
cmd
}
TargetCanister::EvmRpc => Command::new("./scripts/docker-build"),
}
}

pub fn build_artifact_as_str(&self) -> String {
format!("{:?}", self.build_artifact())
}

pub fn canister_ids_json_file(&self) -> PathBuf {
match self {
TargetCanister::CkBtcArchive
Expand All @@ -164,6 +267,7 @@ impl TargetCanister {
| TargetCanister::IcpArchive3
| TargetCanister::IcpIndex
| TargetCanister::IcpLedger => PathBuf::from("rs/ledger_suite/icp/canister_ids.json"),
TargetCanister::EvmRpc => PathBuf::from("canister_ids.json"),
}
}

Expand Down Expand Up @@ -195,6 +299,7 @@ impl FromStr for TargetCanister {
["icp", "archive3"] => Ok(TargetCanister::IcpArchive3),
["icp", "index"] => Ok(TargetCanister::IcpIndex),
["icp", "ledger"] => Ok(TargetCanister::IcpLedger),
["evm", "rpc"] => Ok(TargetCanister::EvmRpc),
_ => Err(format!("Unknown canister name: {}", canister)),
}
}
Expand All @@ -218,6 +323,7 @@ impl Display for TargetCanister {
TargetCanister::IcpIndex => write!(f, "ICP index"),
TargetCanister::IcpLedger => write!(f, "ICP ledger"),
TargetCanister::LedgerSuiteOrchestrator => write!(f, "ledger suite orchestrator"),
TargetCanister::EvmRpc => write!(f, "EVM RPC"),
}
}
}
25 changes: 15 additions & 10 deletions rs/cross-chain/proposal-cli/src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ pub struct GitRepository {
}

impl GitRepository {
pub fn clone_ic() -> Self {
pub fn clone(url: &str) -> Self {
let repo = TempDir::new().expect("failed to create a temporary directory");
// Blobless clone
// see https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/
let git_clone = Command::new("git")
.arg("clone")
.arg("--filter=blob:none")
.arg("https://github.com/dfinity/ic.git")
.arg(url)
.arg(repo.path())
.status()
.expect("failed to clone the IC repository");
.expect("failed to clone the repository");
assert!(git_clone.success());

GitRepository { dir: repo }
Expand Down Expand Up @@ -159,7 +159,7 @@ impl GitRepository {
git_log.arg(repo_dir);
}
let log = git_log.output().expect("failed to run git log");
assert!(log.status.success());
assert!(log.status.success(), "failed to run git log: {:?}", log);

let executed_command = iter::once(git_log.get_program())
.chain(git_log.get_args())
Expand All @@ -183,16 +183,21 @@ impl GitRepository {
&mut self,
canister: &[TargetCanister],
) -> Vec<CompressedWasmHash> {
self.build_canisters();
canister.iter().map(|c| self.sha256_artifact(c)).collect()
canister
.iter()
.map(|c| {
self.build_canister_artifact(c);
self.sha256_artifact(c)
})
.collect()
}

fn build_canisters(&mut self) {
let build = Command::new("./ci/container/build-ic.sh")
.arg("--canisters")
fn build_canister_artifact(&mut self, canister: &TargetCanister) {
let build = canister
.build_artifact()
.current_dir(self.dir.path())
.status()
.expect("failed to build canister artifacts");
.expect("failed to build canister artifact");
assert!(build.success());
}

Expand Down
Loading

0 comments on commit 2e17a1e

Please sign in to comment.