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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/target
target/
10 changes: 10 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[workspace]
members = [".", "thrust-macros"]
resolver = "2"

[package]
name = "thrust"
version = "0.1.0"
Expand All @@ -18,6 +22,11 @@ name = "ui"
harness = false

[dependencies]
# Workaround until thrust supports invocation via cargo: adding thrust-macros as
# a dependency ensures cargo builds (and rebuilds) it alongside thrust. It is not
# used as a proc-macro here; the dylib is loaded at runtime via --extern.
thrust-macros = { path = "thrust-macros" }

anyhow = "1.0.102"
pretty = { version = "0.12.5", features = ["termcolor"] }
tempfile = "3.27.0"
Expand Down
38 changes: 37 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,36 @@ impl Callbacks for CompilerCalls {
}
}

fn thrust_macros_path() -> Option<std::path::PathBuf> {
let exe = std::env::current_exe().ok()?;
let dir = exe.parent()?;
// When thrust-macros is a cargo dependency it lands in deps/ with a hash
// suffix (e.g. libthrust_macros-<hash>.so), so check both locations.
let search_dirs = [dir.to_path_buf(), dir.join("deps")];
for search_dir in &search_dirs {
for ext in ["so", "dylib", "dll"] {
// First try the exact name (e.g. when built standalone).
let candidate = search_dir.join(format!("libthrust_macros.{ext}"));
if candidate.exists() {
return Some(candidate);
}
// Then scan for libthrust_macros-<hash>.<ext>.
if let Ok(entries) = std::fs::read_dir(search_dir) {
for entry in entries.flatten() {
let name = entry.file_name();
let name = name.to_string_lossy();
if name.starts_with("libthrust_macros-") && name.ends_with(ext) {
return Some(entry.path());
}
}
}
}
}
None
}

pub fn main() {
let args = std::env::args().collect::<Vec<_>>();
let mut args = std::env::args().collect::<Vec<_>>();

use tracing_subscriber::{filter::EnvFilter, prelude::*};
tracing_subscriber::registry()
Expand All @@ -80,6 +108,14 @@ pub fn main() {
)
.init();

if let Some(path) = thrust_macros_path() {
args.push("--extern".to_owned());
args.push(format!("thrust_macros={}", path.display()));
tracing::debug!("linking thrust_macros from {}", path.display());
} else {
tracing::warn!("could not locate thrust_macros library");
}

let code =
rustc_driver::catch_with_exit_code(|| RunCompiler::new(&args, &mut CompilerCalls {}).run());
std::process::exit(code);
Expand Down
Loading