From 09c46b149ec8bd1e419778c657a4d4825e72a0bf Mon Sep 17 00:00:00 2001 From: David Semakula Date: Wed, 26 Feb 2025 08:49:59 +0300 Subject: [PATCH] Retrieve PolkaVM target spec from linker (#1939) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Retrieve PolkaVM target spec from linker * Update changelog --------- Co-authored-by: Michael Müller --- CHANGELOG.md | 3 ++- .../riscv64emac-unknown-none-polkavm.json | 26 ------------------- crates/build/src/args.rs | 20 +++++++++----- 3 files changed, 15 insertions(+), 34 deletions(-) delete mode 100644 crates/build/riscv64emac-unknown-none-polkavm.json diff --git a/CHANGELOG.md b/CHANGELOG.md index fd9ab0100..9bbd052fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [Unreleased] ### Added -- Add option to generate Solidity compatible metadata (via `cargo contract build ---metadata `) - [1930](https://github.com/use-ink/cargo-contract/pull/1930) +- Add option to generate Solidity compatible metadata (via `cargo contract build ---metadata `) - [#1930](https://github.com/use-ink/cargo-contract/pull/1930) - Deny overflowing (and lossy) integer type cast operations - [#1895](https://github.com/use-ink/cargo-contract/pull/1895) ### Changed - Target `pallet-revive` instead of `pallet-contracts` - [#1851](https://github.com/use-ink/cargo-contract/pull/1851) +- Retrieve PolkaVM target spec from linker - [#1939](https://github.com/use-ink/cargo-contract/pull/1939) ## [5.0.1] diff --git a/crates/build/riscv64emac-unknown-none-polkavm.json b/crates/build/riscv64emac-unknown-none-polkavm.json deleted file mode 100644 index a3473ee01..000000000 --- a/crates/build/riscv64emac-unknown-none-polkavm.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "arch": "riscv64", - "cpu": "generic-rv64", - "crt-objects-fallback": "false", - "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S64", - "eh-frame-header": false, - "emit-debug-gdb-scripts": false, - "features": "+e,+m,+a,+c,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov", - "linker": "rust-lld", - "linker-flavor": "ld.lld", - "llvm-abiname": "lp64e", - "llvm-target": "riscv64", - "max-atomic-width": 64, - "panic-strategy": "abort", - "relocation-model": "pie", - "target-pointer-width": "64", - "singlethread": true, - "pre-link-args": { - "ld": [ - "--emit-relocs", - "--unique", - "--relocatable" - ] - }, - "env": "polkavm" -} diff --git a/crates/build/src/args.rs b/crates/build/src/args.rs index 324620279..97d30efb0 100644 --- a/crates/build/src/args.rs +++ b/crates/build/src/args.rs @@ -14,9 +14,6 @@ // You should have received a copy of the GNU General Public License // along with cargo-contract. If not, see . -use crate::CrateMetadata; -use anyhow::Result; -use clap::Args; use std::{ convert::TryFrom, fmt, @@ -26,6 +23,15 @@ use std::{ path::Path, }; +use anyhow::Result; +use clap::Args; +use polkavm_linker::TARGET_JSON_64_BIT as POLKAVM_TARGET_JSON_64_BIT; + +use crate::CrateMetadata; + +/// Name of the rustc/LLVM custom target spec for PolkaVM. +const POLKAVM_TARGET_NAME: &str = "riscv64emac-unknown-none-polkavm"; + #[derive(Default, Clone, Copy, Debug, Args)] pub struct VerbosityFlags { /// No output printed to stdout @@ -145,21 +151,21 @@ impl Target { // target configuration here. The path to the file is passed for the // `rustc --target` argument. We write this file to the `target/` folder. let target_dir = crate_metadata.target_directory.to_string_lossy(); - let path = format!("{}/riscv64emac-unknown-none-polkavm.json", target_dir); + let path = format!("{}/{POLKAVM_TARGET_NAME}.json", target_dir); if !Path::exists(Path::new(&path)) { fs::create_dir_all(&crate_metadata.target_directory).unwrap_or_else(|e| { panic!("unable to create target dir {:?}: {:?}", target_dir, e) }); let mut file = File::create(&path).unwrap(); - let config = include_str!("../riscv64emac-unknown-none-polkavm.json"); - file.write_all(config.as_bytes()).unwrap(); + file.write_all(POLKAVM_TARGET_JSON_64_BIT.as_bytes()) + .unwrap(); } path } /// The name used for the target folder inside the `target/` folder. pub fn llvm_target_alias() -> &'static str { - "riscv64emac-unknown-none-polkavm" + POLKAVM_TARGET_NAME } /// Target specific flags to be set to `CARGO_ENCODED_RUSTFLAGS` while building.