-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
CLI: explicit integration with cgo #7377
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -343,3 +343,79 @@ pub fn is_libcpp_lib_name(target: std.Target, name: []const u8) bool { | |||||||||
pub fn hasDebugInfo(target: std.Target) bool { | ||||||||||
return !target.cpu.arch.isWasm(); | ||||||||||
} | ||||||||||
|
||||||||||
pub fn fromGoTarget(go_arch: []const u8, go_os: []const u8) !std.zig.CrossTarget { | ||||||||||
var os_tag: ?std.Target.Os.Tag = undefined; | ||||||||||
var abi: ?std.Target.Abi = null; | ||||||||||
if (std.mem.eql(u8, go_os, "native")) { | ||||||||||
os_tag = null; | ||||||||||
} else if (std.mem.eql(u8, go_os, "aix")) { | ||||||||||
os_tag = .aix; | ||||||||||
} else if (std.mem.eql(u8, go_os, "android")) { | ||||||||||
os_tag = .linux; | ||||||||||
abi = .android; | ||||||||||
} else if (std.mem.eql(u8, go_os, "darwin")) { | ||||||||||
os_tag = .macos; | ||||||||||
} else if (std.mem.eql(u8, go_os, "dragonfly")) { | ||||||||||
os_tag = .dragonfly; | ||||||||||
} else if (std.mem.eql(u8, go_os, "freebsd")) { | ||||||||||
os_tag = .freebsd; | ||||||||||
} else if (std.mem.eql(u8, go_os, "illumos")) { | ||||||||||
return error.UnsupportedOperatingSystem; | ||||||||||
} else if (std.mem.eql(u8, go_os, "js")) { | ||||||||||
return error.UnsupportedOperatingSystem; | ||||||||||
} else if (std.mem.eql(u8, go_os, "linux")) { | ||||||||||
os_tag = .linux; | ||||||||||
abi = .musl; // go wants static linking on linux | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is an ok default behaviour, but this should be configurable via a flag or env var. |
||||||||||
} else if (std.mem.eql(u8, go_os, "netbsd")) { | ||||||||||
os_tag = .netbsd; | ||||||||||
} else if (std.mem.eql(u8, go_os, "openbsd")) { | ||||||||||
os_tag = .openbsd; | ||||||||||
} else if (std.mem.eql(u8, go_os, "plan9")) { | ||||||||||
return error.UnsupportedOperatingSystem; | ||||||||||
} else if (std.mem.eql(u8, go_os, "solaris")) { | ||||||||||
os_tag = .solaris; | ||||||||||
} else if (std.mem.eql(u8, go_os, "windows")) { | ||||||||||
os_tag = .windows; | ||||||||||
abi = .gnu; // so we can provide libc | ||||||||||
} else { | ||||||||||
return error.UnrecognizedOperatingSystem; | ||||||||||
} | ||||||||||
|
||||||||||
var cpu_arch: ?std.Target.Cpu.Arch = undefined; | ||||||||||
if (std.mem.eql(u8, go_arch, "386")) { | ||||||||||
cpu_arch = null; | ||||||||||
Comment on lines
+386
to
+387
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} else if (std.mem.eql(u8, go_arch, "386")) { | ||||||||||
cpu_arch = .i386; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "amd64")) { | ||||||||||
cpu_arch = .x86_64; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "arm")) { | ||||||||||
cpu_arch = .arm; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "arm64")) { | ||||||||||
cpu_arch = .aarch64; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "mips")) { | ||||||||||
cpu_arch = .mips; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "mips64")) { | ||||||||||
cpu_arch = .mips64; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "mips64le")) { | ||||||||||
cpu_arch = .mips64el; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "mipsle")) { | ||||||||||
cpu_arch = .mipsel; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "ppc64")) { | ||||||||||
cpu_arch = .powerpc64; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "ppc64le")) { | ||||||||||
cpu_arch = .powerpc64le; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "riscv64")) { | ||||||||||
cpu_arch = .riscv64; | ||||||||||
} else if (std.mem.eql(u8, go_arch, "s390x")) { | ||||||||||
cpu_arch = .s390x; | ||||||||||
} else { | ||||||||||
return error.UnrecognizedCPUArchitecture; | ||||||||||
} | ||||||||||
|
||||||||||
return std.zig.CrossTarget{ | ||||||||||
.cpu_arch = cpu_arch, | ||||||||||
.os_tag = os_tag, | ||||||||||
.abi = abi, | ||||||||||
}; | ||||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://go-review.googlesource.com/c/go/+/276412/ which is under review may fix this.