Skip to content

Commit a0dc407

Browse files
apet2929lwbuchanan
andauthored
Fix build by making unpacked lib its own cargo workspace (#112)
* Add megaton as a dependency of test_mod and exclude test_mod from top-level cargo workspace * Re-add test-mod to cargo workspace * fixed build * please ignore properly * Fixes according to PR comments * Run formatter --------- Co-authored-by: Luke Buchanan <luke1020will@gmail.com>
1 parent 6f82596 commit a0dc407

9 files changed

Lines changed: 256 additions & 368 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/cmds/cmd_build/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ async fn run_build(args: CmdBuild) -> cu::Result<()> {
9696
static_libs.push(
9797
rust_ctx
9898
.get_output()
99+
.await
99100
.context("Failed to get cargo output")?,
100101
);
101102
} else if rust_ctx.has_build_script() {

packages/cli/src/cmds/cmd_build/rust.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use super::config::CargoConfig;
1616
#[derive(Debug, Clone)]
1717
pub struct RustCtx {
1818
pub manifest: PathBuf,
19-
target_path: PathBuf,
2019
source_paths: Vec<PathBuf>,
2120
header_suffix: String,
2221
}
@@ -62,12 +61,8 @@ impl RustCtx {
6261
.map(|rel_path| crate_root.join(rel_path))
6362
.collect::<Vec<_>>();
6463

65-
// This should always be target, even if the megaton target dir is different
66-
let target_path = crate_root.join("target");
67-
6864
Ok(Self {
6965
manifest,
70-
target_path,
7166
source_paths,
7267
header_suffix,
7368
})
@@ -117,7 +112,7 @@ impl RustCtx {
117112
rustflags: &str,
118113
check: bool,
119114
) -> cu::Result<bool> {
120-
let old_output = self.get_output();
115+
let old_output = self.get_output().await;
121116
let old_mtime = match old_output {
122117
Ok(file) => cu::fs::get_mtime(file).unwrap_or(None),
123118
Err(_) => None,
@@ -151,7 +146,7 @@ impl RustCtx {
151146
return Ok(false);
152147
}
153148

154-
let new_output = self.get_output().unwrap();
149+
let new_output = self.get_output().await?;
155150
let new_mtime = cu::fs::get_mtime(new_output).unwrap();
156151

157152
// Return true if artifact changed
@@ -161,9 +156,30 @@ impl RustCtx {
161156
/// Gets the path to the static lib compiled by cargo
162157
/// Error if the Cargo manifest can't be parsed, filename
163158
/// can't be parsed, or if file doesn't exist
164-
pub fn get_output(&self) -> cu::Result<PathBuf> {
165-
let rel_path = self
166-
.target_path
159+
pub async fn get_output(&self) -> cu::Result<PathBuf> {
160+
let cargo = cu::which("cargo")
161+
.context("Cargo executable not found: ensure rust is properly installed")?;
162+
let (child, stdout_handle) = cargo
163+
.command()
164+
.add(cu::args![
165+
"locate-project",
166+
"--workspace",
167+
"--message-format=plain",
168+
"--manifest-path",
169+
&self.manifest,
170+
])
171+
.stdie_null()
172+
.stdout(cu::pio::string())
173+
.co_spawn()
174+
.await?;
175+
child.co_wait_nz().await?;
176+
177+
let workspace_root = PathBuf::from(stdout_handle.co_join().await??);
178+
179+
let workspace_path = workspace_root
180+
.parent()
181+
.unwrap()
182+
.join("target")
167183
.join("aarch64-unknown-hermit")
168184
.join("release");
169185

@@ -177,7 +193,7 @@ impl RustCtx {
177193
let name = name.replace("-", "_");
178194

179195
let filename = format!("lib{name}.a");
180-
rel_path.join(&filename).normalize_exists()
196+
workspace_path.join(&filename).normalize_exists()
181197
}
182198

183199
/// Scan rust sources and generate cxxbridge sources and headers

packages/lib/src/alloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <nn/os/os_Mutex.h>
66
#include <mutex>
77

8-
#include <megaton/__internal/tlsf.h>
8+
#include <megaton/__external/tlsf.h>
99

1010
#define BSS_ALLOC_SIZE 0x20000
1111
static u8 bss_alloc[BSS_ALLOC_SIZE] = {0};

packages/test-mod/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
/target
1+
target/
2+
target/**
23
debug-font
4+
compile_commands.json
5+
Cargo.lock

0 commit comments

Comments
 (0)