Skip to content

Commit

Permalink
revert #2865 in favor of stabilized panic_info_message
Browse files Browse the repository at this point in the history
  • Loading branch information
StackOverflowExcept1on committed Jul 29, 2024
1 parent df3a39c commit 9b03fbe
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 56 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion utils/wasm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ log.workspace = true
pathdiff.workspace = true
which.workspace = true
colored.workspace = true
dirs.workspace = true
gmeta.workspace = true
gear-core.workspace = true
gear-wasm-instrument.workspace = true
Expand Down
25 changes: 0 additions & 25 deletions utils/wasm-builder/src/cargo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct CargoCommand {
toolchain: Toolchain,
check_recommended_toolchain: bool,
force_recommended_toolchain: bool,
paths_to_remap: Vec<(PathBuf, &'static str)>,
}

impl CargoCommand {
Expand All @@ -50,7 +49,6 @@ impl CargoCommand {
toolchain: Toolchain::try_from_rustup().expect("Failed to get toolchain from rustup"),
check_recommended_toolchain: false,
force_recommended_toolchain: false,
paths_to_remap: vec![],
}
}
}
Expand Down Expand Up @@ -94,13 +92,6 @@ impl CargoCommand {
self.force_recommended_toolchain = force_recommended_toolchain;
}

/// Set paths to remap.
///
/// Used to hide the username from the panic message.
pub fn set_paths_to_remap(&mut self, paths_to_remap: &[(PathBuf, &'static str)]) {
self.paths_to_remap = paths_to_remap.into();
}

/// Execute the `cargo` command with invoking supplied arguments.
pub fn run(&self) -> Result<()> {
if self.check_recommended_toolchain {
Expand Down Expand Up @@ -141,22 +132,6 @@ impl CargoCommand {

self.remove_cargo_encoded_rustflags(&mut cargo);

if !self.paths_to_remap.is_empty() {
// `--remap-path-prefix` is used to remove username from panic messages
// https://doc.rust-lang.org/rustc/command-line-arguments.html#--remap-path-prefix-remap-source-names-in-output
let global_encoded_rustflags = self
.paths_to_remap
.iter()
.map(|(from, to)| format!("--remap-path-prefix={from}={to}", from = from.display()))
.collect::<Vec<_>>()
.join("\x1f");

// The environment variable `CARGO_ENCODED_RUSTFLAGS` is used to globally remap path prefix.
// It is also separated by `\x1f` to support folders with spaces or any unusual characters.
// Unlike `cargo rust`, this is useful for passing flags to all dependencies (i.e. globally).
cargo.env("CARGO_ENCODED_RUSTFLAGS", global_encoded_rustflags);
}

let status = cargo.status().context("unable to execute cargo command")?;
ensure!(
status.success(),
Expand Down
26 changes: 2 additions & 24 deletions utils/wasm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub use cargo_command::CargoCommand;
pub use wasm_project::{PreProcessor, PreProcessorResult, PreProcessorTarget};

use crate::wasm_project::WasmProject;
use anyhow::{Context, Result};
use anyhow::Result;
use gmeta::{Metadata, MetadataRepr};
use regex::Regex;
use std::{env, path::PathBuf, process};
use std::{env, process};
use wasm_project::ProjectType;

mod builder_error;
Expand Down Expand Up @@ -128,9 +128,6 @@ impl WasmBuilder {
let profile = if profile == "debug" { "dev" } else { profile };
self.cargo.set_profile(profile.to_string());
self.cargo.set_features(&self.enabled_features()?);
if env::var("GEAR_WASM_BUILDER_PATH_REMAPPING").is_ok() {
self.cargo.set_paths_to_remap(&self.paths_to_remap()?);
}

self.cargo.run()?;
self.wasm_project.postprocess()
Expand Down Expand Up @@ -199,25 +196,6 @@ impl WasmBuilder {
.filter(|feature| feature != "gcli")
.collect())
}

fn paths_to_remap(&self) -> Result<Vec<(PathBuf, &'static str)>> {
let home_dir = dirs::home_dir().context("unable to get home directory")?;

let project_dir = self.wasm_project.original_dir();

let cargo_dir = std::env::var_os("CARGO_HOME")
.map(PathBuf::from)
.context("unable to get cargo home directory")?;

let cargo_checkouts_dir = cargo_dir.join("git").join("checkouts");

Ok(vec![
(home_dir, "/home"),
(project_dir, "/code"),
(cargo_dir, "/cargo"),
(cargo_checkouts_dir, "/deps"),
])
}
}

impl Default for WasmBuilder {
Expand Down
5 changes: 0 additions & 5 deletions utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ impl WasmProject {
self.out_dir.join("Cargo.toml")
}

/// Return the path to the original project directory.
pub fn original_dir(&self) -> PathBuf {
self.original_dir.clone()
}

/// Return the path to the target directory.
pub fn target_dir(&self) -> PathBuf {
self.target_dir.clone()
Expand Down

0 comments on commit 9b03fbe

Please sign in to comment.