Skip to content

Commit c8e2f8d

Browse files
authored
Merge pull request #76 from jfleitz/jfleitz/go-symlink
get go bin path from go and support symlink
2 parents 5b8eef1 + 3b2edfc commit c8e2f8d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎src/utils.rs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,24 @@ pub fn check_go_version(go_path: &Path) -> Result<()> {
274274
}
275275
}
276276

277+
// go_root() returns `None` if the `go` binary cannot be executed or does not return a valid `GOROOT`.
278+
fn go_root(go: &Path) -> Option<PathBuf> {
279+
let output = Command::new(go).args(["env", "GOROOT"]).output().ok()?;
280+
if !output.status.success() {
281+
return None;
282+
}
283+
let root = String::from_utf8(output.stdout).ok()?;
284+
let root = root.trim();
285+
if root.is_empty() {
286+
None
287+
} else {
288+
Some(PathBuf::from(root))
289+
}
290+
}
291+
277292
fn check_go_async_support(go: &Path) -> Option<()> {
278293
fs::read_to_string(
279-
go.parent()?
280-
.parent()?
294+
go_root(go)?
281295
.join("src")
282296
.join("runtime")
283297
.join("lock_wasip1.go"),

0 commit comments

Comments
 (0)