Skip to content
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

Make paths msys2 friendly #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ name = "libdtrace_rs"
path = "src/lib.rs"

[build-dependencies]
anyhow = "1.0.79"
bindgen = "0.69.1"
48 changes: 35 additions & 13 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use std::env;
use std::path::PathBuf;
use std::process::Command;

const DTRACE_SRC_DIR: &str = "_dtrace";

// Set-ExecutionPolicy RemoteSigned –Scope Process
// 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe' opendtrace.sln /t:dtrace_dll:Rebuild /p:Configuration=Release /p:Platform=x64
fn get_dtrace_libpath() -> PathBuf {
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
std::path::Path::new(&dir).join("target\\dtrace\\build\\x64\\Release\\lib\\")
std::path::Path::new(&dir)
.join(DTRACE_SRC_DIR)
.join("dtrace/build/x64/Release/lib")
Comment on lines +11 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong path, evaluates to libdtrace-rs\_dtrace\dtrace/build/x64/Release/lib

Should be libdtrace-rs\target\_dtrace/build/x64/Release/lib

}

fn main() {
Expand All @@ -20,7 +24,10 @@ fn main() {
get_dtrace_libpath().display()
);

build_dtrace();
print!("Trying to buidld dtrace library... ");
build_dtrace().unwrap();
println!("\t....[DONE]");

let outdir = std::path::Path::new(&env::var("OUT_DIR").unwrap()).join("dtrace.dll");
std::fs::copy(get_dtrace_libpath().join("dtrace.dll"), outdir).expect("Failed to copy dll");

Expand Down Expand Up @@ -54,18 +61,33 @@ fn main() {
.expect("Couldn't write bindings!");
}

fn build_dtrace() {
Command::new("git")
.args(&[
"clone",
"https://github.com/microsoft/DTrace-on-Windows.git",
"target\\dtrace",
])
.output()
.expect("Failed to clone dtrace");
fn build_dtrace() -> anyhow::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's no Err variant. Why even return a result?

let output = if !PathBuf::from(DTRACE_SRC_DIR).is_dir() {
Command::new("git")
.args(&[
"clone",
"https://github.com/microsoft/DTrace-on-Windows.git",
DTRACE_SRC_DIR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't clone anything inside root directory, use the target directory for any external dependencies

])
.output()
.expect("Failed to clone dtrace");
} else {
Command::new("git")
.arg("udpate")
.current_dir(DTRACE_SRC_DIR)
.output()
.expect("Failed to update dtrace");
Comment on lines +75 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

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

git update is not a valid command.

};

let _ = Command::new("powershell")
.args(&[".\\build-dtrace.ps1"])
println!("> git update/clone {output:?}");

let output = Command::new("powershell.exe")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need this output, build logs get generated inside dtrace directory not in stdout

.arg("-F")
Copy link
Collaborator

Choose a reason for hiding this comment

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

-F is not a valid option to powershell.

.arg("./build-dtrace.ps1")
.output()
.expect("failed to get external tools");

println!("> git clone {output:?}");

Ok(())
}