-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/apply patch #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/apply patch #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2025 Megaton contributors | ||
|
|
||
| use std::path::Path; | ||
|
|
||
| use cu::Result; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2025 Megaton contributors | ||
|
|
||
| use std::path::{Path, PathBuf}; | ||
| use std::{io::stdout, path::{Path, PathBuf}}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused? |
||
|
|
||
| use cu::pre::*; | ||
|
|
||
|
|
@@ -13,6 +13,9 @@ static TOOLCHAIN_NAME: &str = "megaton"; | |
| static RUST_REPO: &str = "https://github.com/rust-lang/rust"; | ||
| /// The "blessed" commit hash to use (i.e. tested and will work) | ||
| static RUST_COMMIT: &str = "caadc8df3519f1c92ef59ea816eb628345d9f52a"; | ||
| // This is a patch for the rust stdlib | ||
| // static PATCH_FILE: &'static str = "../../../../patches/rust_std.patch"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove the commented out lint |
||
| static PATCH_FILE: &'static str = include_str!("../../../../patches/rust_std.patch"); | ||
|
|
||
| /// Manage the custom `megaton` Rust toolchain | ||
| #[derive(Debug, Clone, clap::Subcommand)] | ||
|
|
@@ -23,6 +26,7 @@ pub enum CmdToolchain { | |
| Install { | ||
| /// Keep the rustc/llvm build output. This may consume a lot of disk space, | ||
| /// but makes it faster when debugging the toolchain | ||
| /// | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove extra line |
||
| #[clap(short, long)] | ||
| keep: bool, | ||
|
|
||
|
|
@@ -138,14 +142,20 @@ fn install(keep: bool, clean: bool) -> cu::Result<()> { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // verify the blessed commit is checked out | ||
| let actual_commit = try_get_rust_source_commit(&rust_path) | ||
| .context("failed to verify the blessed commit is checked out")?; | ||
| if actual_commit != RUST_COMMIT { | ||
| cu::bail!("failed to checkout the blessed commit."); | ||
| } | ||
|
|
||
| match patch_rust_std(&rust_path) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cu::check!(patch_rust_std(&rust_path), "failed to apply rust std patches")?; |
||
| Ok(_) => {}, | ||
| Err(_) => { | ||
| cu::bail!("failed to apply patches"); | ||
| } | ||
| } | ||
|
|
||
| let mut bootstrap_toml = String::new(); | ||
| // using the compiler profile, since it usually builds the fastest (compared to other) | ||
| bootstrap_toml += "profile = 'compiler'\n"; | ||
|
|
@@ -407,6 +417,23 @@ fn checkout_blessed_commit(path: &Path) -> cu::Result<()> { | |
| Ok(()) | ||
| } | ||
|
|
||
| // patch our rust stdlib to do all the things we want | ||
| fn patch_rust_std(path: &Path) -> cu::Result<()> { | ||
| let git = cu::which("git")?; | ||
| git.command() | ||
| .add(cu::args![ | ||
| "-C", | ||
| &path, | ||
| "apply", | ||
| "-" | ||
| ]) | ||
| .stdoe(cu::lv::W) | ||
| .stdin(cu::pio::write(PATCH_FILE)) | ||
| .spawn()? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can just do |
||
| .wait()?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Get the rust source commit of the currently checked out rust repo, | ||
| /// if any | ||
| fn try_get_rust_source_commit(path: &Path) -> cu::Result<String> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| diff --git a/library/std/src/sys/env/hermit.rs b/library/std/src/sys/env/hermit.rs | ||
| index 445ecdeb..bcf3aeb4 100644 | ||
| --- a/library/std/src/sys/env/hermit.rs | ||
| +++ b/library/std/src/sys/env/hermit.rs | ||
| @@ -1,17 +1,20 @@ | ||
| use core::slice::memchr; | ||
|
|
||
| pub use super::common::Env; | ||
| -use crate::collections::HashMap; | ||
| +use crate::collections::BTreeMap; | ||
| +// use crate::collections::HashMap; | ||
| use crate::ffi::{CStr, OsStr, OsString, c_char}; | ||
| use crate::io; | ||
| use crate::os::hermit::ffi::OsStringExt; | ||
| use crate::sync::Mutex; | ||
|
|
||
| -static ENV: Mutex<Option<HashMap<OsString, OsString>>> = Mutex::new(None); | ||
| +static ENV: Mutex<BTreeMap<OsString, OsString>> = Mutex::new(BTreeMap::new()); | ||
| +// static ENV: Mutex<Option<HashMap<OsString, OsString>>> = Mutex::new(None); | ||
|
|
||
| pub fn init(env: *const *const c_char) { | ||
| let mut guard = ENV.lock().unwrap(); | ||
| - let map = guard.insert(HashMap::new()); | ||
| + let map = &mut guard; | ||
| + // let map = guard.insert(HashMap::new()); | ||
|
|
||
| if env.is_null() { | ||
| return; | ||
| @@ -49,7 +52,8 @@ fn parse(input: &[u8]) -> Option<(OsString, OsString)> { | ||
| /// environment variables of the current process. | ||
| pub fn env() -> Env { | ||
| let guard = ENV.lock().unwrap(); | ||
| - let env = guard.as_ref().unwrap(); | ||
| + let env = &guard; | ||
| + // let env = guard.as_ref().unwrap(); | ||
|
|
||
| let result = env.iter().map(|(key, value)| (key.clone(), value.clone())).collect(); | ||
|
|
||
| @@ -57,16 +61,16 @@ pub fn env() -> Env { | ||
| } | ||
|
|
||
| pub fn getenv(k: &OsStr) -> Option<OsString> { | ||
| - ENV.lock().unwrap().as_ref().unwrap().get(k).cloned() | ||
| + ENV.lock().unwrap().get(k).cloned() | ||
| } | ||
|
|
||
| pub unsafe fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { | ||
| let (k, v) = (k.to_owned(), v.to_owned()); | ||
| - ENV.lock().unwrap().as_mut().unwrap().insert(k, v); | ||
| + ENV.lock().unwrap().insert(k, v); | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub unsafe fn unsetenv(k: &OsStr) -> io::Result<()> { | ||
| - ENV.lock().unwrap().as_mut().unwrap().remove(k); | ||
| + ENV.lock().unwrap().remove(k); | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: don't have to fix right now, but module comments start with
//!