Skip to content

Commit

Permalink
Retrieve PolkaVM target spec from linker
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsemakula committed Feb 14, 2025
1 parent 2c9f826 commit ae484a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
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 ae484a3

Please sign in to comment.