Skip to content

Commit

Permalink
Retrieve PolkaVM target spec from linker (#1939)
Browse files Browse the repository at this point in the history
* Retrieve PolkaVM target spec from linker

* Update changelog

---------

Co-authored-by: Michael Müller <[email protected]>
  • Loading branch information
davidsemakula and cmichi authored Feb 26, 2025
1 parent 84da2b9 commit 09c46b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ink|solidity>`) - [1930](https://github.com/use-ink/cargo-contract/pull/1930)
- Add option to generate Solidity compatible metadata (via `cargo contract build ---metadata <ink|solidity>`) - [#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]

Expand Down
26 changes: 0 additions & 26 deletions crates/build/riscv64emac-unknown-none-polkavm.json

This file was deleted.

20 changes: 13 additions & 7 deletions crates/build/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

use crate::CrateMetadata;
use anyhow::Result;
use clap::Args;
use std::{
convert::TryFrom,
fmt,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 09c46b1

Please sign in to comment.