Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 87 additions & 127 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ members = [

[workspace.dependencies.cu]
package = "pistonite-cu"
version = "0.5.2"
version = "0.6.0"
# path = "../../../cu/packages/copper"
3 changes: 3 additions & 0 deletions packages/cli/src/cmds/cmd_build/compile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Megaton contributors

// This modules handles compiling c/c++/asm/rust code
Copy link
Collaborator

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 //!


use cu::Result;
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/cmds/cmd_build/generate.rs
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;
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/cmds/cmd_build/link.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Megaton contributors

// This module manages linking the mod and library

use cu::Result;
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/cmds/cmd_build/scan.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Megaton contributors

// This module handles scanning the mod/library source

use cu::{Error, Result};
Expand Down
31 changes: 29 additions & 2 deletions packages/cli/src/cmds/cmd_toolchain.rs
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}};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?


use cu::pre::*;

Expand All @@ -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";
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)]
Expand All @@ -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
///
Copy link
Collaborator

@Pistonight Pistonight Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra line

#[clap(short, long)]
keep: bool,

Expand Down Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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";
Expand Down Expand Up @@ -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()?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do .wait_nz()? instead of .spawn()?.wait()?. _nz means wait for non-zero exit status (will error if command fails)

.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> {
Expand Down
58 changes: 58 additions & 0 deletions patches/rust_std.patch
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(())
}
Loading