diff --git a/.github/workflows/contracts.yml b/.github/workflows/contracts.yml index 16e5aa06..fb6a80c9 100644 --- a/.github/workflows/contracts.yml +++ b/.github/workflows/contracts.yml @@ -37,9 +37,6 @@ jobs: - name: Prepare target run: rustup target add wasm32-unknown-unknown - - name: Build specific contracts dependencies - run: cargo build -p voting --release --target wasm32-unknown-unknown --verbose - - name: Build ${{ matrix.contract }} dep run: cargo build -p ${{ matrix.contract }} --release --target wasm32-unknown-unknown --verbose diff --git a/contracts/governance/Cargo.toml b/contracts/governance/Cargo.toml index 33774a19..98275b8e 100644 --- a/contracts/governance/Cargo.toml +++ b/contracts/governance/Cargo.toml @@ -12,5 +12,14 @@ crate-type = ["cdylib"] soroban-sdk = { workspace = true } shared = { path= "../shared"} +[build-dependencies] +nebula = { path = "../../" } + + [dev-dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } + +# Adds nebula oci contract import +[package.metadata.nebula.imports] +voting = "ghcr.io/eigerco/nebula/contracts/voting:v0.2.0" + diff --git a/contracts/governance/build.rs b/contracts/governance/build.rs new file mode 100644 index 00000000..123ea3e1 --- /dev/null +++ b/contracts/governance/build.rs @@ -0,0 +1,3 @@ +fn main() { + nebula::build::import_all_contracts(); +} diff --git a/contracts/governance/src/lib.rs b/contracts/governance/src/lib.rs index 9590b8a1..fae06605 100644 --- a/contracts/governance/src/lib.rs +++ b/contracts/governance/src/lib.rs @@ -42,10 +42,8 @@ use soroban_sdk::{ token, vec, Address, BytesN, Env, IntoVal, Map, Symbol, Val, }; -#[allow(clippy::too_many_arguments)] -mod voting_contract { - soroban_sdk::contractimport!(file = "../../target/wasm32-unknown-unknown/release/voting.wasm"); -} +// Imports the OCI contracts +include!(concat!(env!("OUT_DIR"), "/nebula_importer.rs")); mod participant; @@ -123,7 +121,7 @@ impl GovernanceContract { } // Deploy the voting contract (A dependency of this one) - let voting_contract_hash = env.deployer().upload_contract_wasm(voting_contract::WASM); + let voting_contract_hash = env.deployer().upload_contract_wasm(voting::WASM); let deployer = env.deployer().with_current_contract(salt); let voting_contract_address = deployer.deploy(voting_contract_hash); diff --git a/crates/nebula-importer/src/lib.rs b/crates/nebula-importer/src/lib.rs index 5fc814b8..bfc95f9b 100644 --- a/crates/nebula-importer/src/lib.rs +++ b/crates/nebula-importer/src/lib.rs @@ -85,11 +85,11 @@ pub fn import_all_contracts() { }); std::fs::create_dir_all(&contracts_dir) .expect("[importer] Contracts path could not be resolved"); - sync_contracts(&config, &contracts_dir).expect("[importer] Could not sync contracts."); + sync_contracts(config, &contracts_dir).expect("[importer] Could not sync contracts."); } /// Syncs contracts to a specific path -pub fn sync_contracts(config: &Config, cache: &PathBuf) -> anyhow::Result<()> { +pub fn sync_contracts(config: &Config, cache: &Path) -> anyhow::Result<()> { let client = Client::new(oci_distribution::client::ClientConfig { protocol: oci_distribution::client::ClientProtocol::Https, ..Default::default() @@ -105,7 +105,7 @@ pub fn sync_contracts(config: &Config, cache: &PathBuf) -> anyhow::Result<()> { .block_on(runtime.spawn(find_and_sync_contract( name.clone(), contract.clone(), - cache.clone(), + cache.to_path_buf(), client.clone(), ))) .context(format!("Loading contract: {:?}", contract))?; @@ -140,6 +140,15 @@ async fn find_and_sync_contract( let mut client = client.lock().await; let reference = contract.reference(); pull_wasm(&mut client, &RegistryAuth::Anonymous, &reference, &path).await; + let path_str = path.to_str().unwrap().to_string(); + let name = syn::Ident::new(&name, Span::call_site()); + + let code = quote::quote! { + pub (crate) mod #name { + soroban_sdk::contractimport!(file = #path_str); + } + }; + generate_file(&dest_path, code.to_string().as_bytes()); } Err(e) => throw_warning!("{e:?}"), }; @@ -154,10 +163,8 @@ pub(crate) async fn pull_wasm( let image_content = client .pull(reference, auth, vec![manifest::WASM_LAYER_MEDIA_TYPE]) .await - .expect(&format!( - "Cannot pull Wasm module from {}", - reference.to_string() - )) + .unwrap_or_else(|_| panic!("Cannot pull Wasm module from {}", + reference)) .layers .into_iter() .next()