Skip to content

Commit

Permalink
[Misc]: Update the scrypto version used.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Jan 21, 2024
1 parent 07e808b commit c15c98f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 61 deletions.
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ edition = "2021"
description = "The implementation of project Ignition in Scrypto for the Radix Ledger"

[workspace.dependencies]
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine-stores = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine-derive = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine-stores = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine-derive = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }

scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
scrypto-test = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "9663c7c7dbcb91309b01f0b931195194b75b2718" }
scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }
scrypto-test = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ea46347402a5553d4f0a594ff003e5f455d2b5d1" }

[profile.release]
opt-level = 'z'
Expand Down
108 changes: 61 additions & 47 deletions libraries/package-loader/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,66 +56,80 @@ fn build_blueprints() -> Result<(), Error> {
.flatten()
.collect::<Vec<_>>();

// Building each of the packages that have been discovered.
let mut packages = HashMap::new();
for package_name in package_names {
// Build the package
let status = Command::new("cargo")
.args([
"build",
"--target",
"wasm32-unknown-unknown",
"--release",
"--target-dir",
builds_target_path.as_path().display().to_string().as_str(),
"--package",
package_name.as_str(),
])
.status()?;
if !status.success() {
return Err(Error::CompilationOfPackageFailed(package_name));
}

// Construct the path to the WASM file.
// Build 1: Building each of the packages with the package definition.
let status = Command::new("cargo")
.args([
"build",
"--target",
"wasm32-unknown-unknown",
"--release",
"--target-dir",
builds_target_path.as_path().display().to_string().as_str(),
])
.args(package_names.iter().flat_map(|package_name| {
["--package".to_owned(), package_name.to_owned()]
}))
.status()?;
if !status.success() {
return Err(Error::CompilationOfPackageFailed);
}

// Read the package definition of the various packages - assume code to be
// an empty byte array for now.
let mut packages = package_names
.iter()
.map(|package_name| {
let wasm_path = builds_target_path
.join("wasm32-unknown-unknown")
.join("release")
.join(format!("{}.wasm", package_name.replace('-', "_")));

let package_definition =
radix_engine::utils::extract_definition(&read(wasm_path)?)?;

Ok::<_, Error>((
package_name.clone(),
(Vec::<u8>::new(), package_definition),
))
})
.collect::<Result<IndexMap<_, _>, _>>()?;

// Build 2: Build without the package definition.
let status = Command::new("cargo")
.args([
"build",
"--target",
"wasm32-unknown-unknown",
"--release",
"--target-dir",
builds_target_path.as_path().display().to_string().as_str(),
"--features",
"scrypto/no-schema",
])
.args(package_names.iter().flat_map(|package_name| {
["--package".to_owned(), package_name.to_owned()]
}))
.status()?;
if !status.success() {
return Err(Error::CompilationOfPackageFailed);
}

for package_name in package_names.iter() {
let wasm_path = builds_target_path
.join("wasm32-unknown-unknown")
.join("release")
.join(format!("{}.wasm", package_name.replace('-', "_")));

// Extract the package definition
let package_definition =
radix_engine::utils::extract_definition(&read(&wasm_path)?)?;

// Build a new WASM build without any of the schema information
let status = Command::new("cargo")
.args([
"build",
"--target",
"wasm32-unknown-unknown",
"--release",
"--target-dir",
builds_target_path.as_path().display().to_string().as_str(),
"--package",
package_name.as_str(),
"--features",
"scrypto/no-schema",
])
.status()?;
if !status.success() {
return Err(Error::CompilationOfPackageFailed(package_name));
}

// Optimize the WASM using wasm-opt for size
wasm_opt::OptimizationOptions::new_optimize_for_size_aggressively()
.add_pass(wasm_opt::Pass::StripDebug)
.add_pass(wasm_opt::Pass::StripDwarf)
.add_pass(wasm_opt::Pass::StripProducers)
.run(&wasm_path, &wasm_path)?;

// Read the final wasm.
let wasm = read(wasm_path)?;

packages.insert(package_name, (wasm, package_definition));
packages.get_mut(package_name.as_str()).unwrap().0 = wasm;
}

let out_dir =
Expand All @@ -137,7 +151,7 @@ pub enum Error {
IoError(std::io::Error),
#[cfg(feature = "build-time-blueprints")]
ManifestError(cargo_toml::Error),
CompilationOfPackageFailed(String),
CompilationOfPackageFailed,
#[cfg(feature = "build-time-blueprints")]
ExtractSchemaError(radix_engine::utils::ExtractSchemaError),
#[cfg(feature = "build-time-blueprints")]
Expand Down
4 changes: 2 additions & 2 deletions tests/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::prelude::*;
/// that must happen after the creation of the environment.
pub struct Environment {
/* Test Environment */
pub environment: TestEnvironment,
pub environment: TestEnvironment<InMemorySubstateDatabase>,
/* Various entities */
pub resources: ResourceInformation<ResourceAddress>,
pub protocol: ProtocolEntities,
Expand Down Expand Up @@ -285,7 +285,7 @@ impl Environment {

fn publish_package(
name: &str,
env: &mut TestEnvironment,
env: &mut TestEnvironment<InMemorySubstateDatabase>,
) -> Result<PackageAddress, RuntimeError> {
let (code, definition) = package_loader::PackageLoader::get(name);
Package::publish(code, definition, Default::default(), env)
Expand Down

0 comments on commit c15c98f

Please sign in to comment.