Skip to content

Commit

Permalink
Contracts use polkavm workspace deps (paritytech#3715)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou authored and dharjeezy committed Mar 24, 2024
1 parent 3da0e41 commit b817603
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 57 deletions.
61 changes: 9 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/frame/contracts/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parity-wasm = "0.45.0"
tempfile = "3.8.1"
toml = "0.8.2"
twox-hash = "1.6.3"
polkavm-linker = { version = "0.5.0", optional = true }
polkavm-linker = { workspace = true, optional = true }
anyhow = "1.0.0"

[features]
Expand Down
7 changes: 6 additions & 1 deletion substrate/frame/contracts/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ fn collect_entries(contracts_dir: &Path, out_dir: &Path) -> Vec<Entry> {
/// Create a `Cargo.toml` to compile the given contract entries.
fn create_cargo_toml<'a>(
fixtures_dir: &Path,
root_cargo_toml: &Path,
entries: impl Iterator<Item = &'a Entry>,
output_dir: &Path,
) -> Result<()> {
let root_toml: toml::Value = toml::from_str(&fs::read_to_string(root_cargo_toml)?)?;
let mut cargo_toml: toml::Value = toml::from_str(include_str!("./build/Cargo.toml"))?;
let mut set_dep = |name, path| -> Result<()> {
cargo_toml["dependencies"][name]["path"] = toml::Value::String(
Expand All @@ -133,6 +135,8 @@ fn create_cargo_toml<'a>(
};
set_dep("uapi", "../uapi")?;
set_dep("common", "./contracts/common")?;
cargo_toml["dependencies"]["polkavm-derive"]["version"] =
root_toml["workspace"]["dependencies"]["polkavm-derive"].clone();

cargo_toml["bin"] = toml::Value::Array(
entries
Expand Down Expand Up @@ -324,6 +328,7 @@ fn main() -> Result<()> {
let contracts_dir = fixtures_dir.join("contracts");
let out_dir: PathBuf = env::var("OUT_DIR")?.into();
let workspace_root = find_workspace_root(&fixtures_dir).expect("workspace root exists; qed");
let root_cargo_toml = workspace_root.join("Cargo.toml");

let entries = collect_entries(&contracts_dir, &out_dir);
if entries.is_empty() {
Expand All @@ -333,7 +338,7 @@ fn main() -> Result<()> {
let tmp_dir = tempfile::tempdir()?;
let tmp_dir_path = tmp_dir.path();

create_cargo_toml(&fixtures_dir, entries.iter(), tmp_dir.path())?;
create_cargo_toml(&fixtures_dir, &root_cargo_toml, entries.iter(), tmp_dir.path())?;
invoke_cargo_fmt(
&workspace_root.join(".rustfmt.toml"),
entries.iter().map(|entry| &entry.path as _),
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/contracts/fixtures/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2021"
# Binary targets are injected dynamically by the build script.
[[bin]]

# local path are injected dynamically by the build script.
# All paths or versions are injected dynamically by the build script.
[dependencies]
uapi = { package = 'pallet-contracts-uapi', path = "", default-features = false }
common = { package = 'pallet-contracts-fixtures-common', path = "" }
polkavm-derive = '0.5.0'
polkavm-derive = { version = "" }

[profile.release]
opt-level = 3
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/contracts/uapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ scale = { package = "parity-scale-codec", version = "3.6.1", default-features =
], optional = true }

[target.'cfg(target_arch = "riscv32")'.dependencies]
polkavm-derive = '0.5.0'
polkavm-derive = { workspace = true }

[package.metadata.docs.rs]
default-target = ["wasm32-unknown-unknown"]
Expand Down

0 comments on commit b817603

Please sign in to comment.