wip go 1.20
This commit is contained in:
parent
0fd73783db
commit
53d89ba627
@ -1 +1 @@
|
|||||||
5.2.0
|
6.0.0
|
||||||
|
@ -6,10 +6,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
|||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "io_bazel_rules_go",
|
name = "io_bazel_rules_go",
|
||||||
sha256 = "56d8c5a5c91e1af73eca71a6fab2ced959b67c86d12ba37feedb0a2dfea441a6",
|
sha256 = "dd926a88a564a9246713a9c00b35315f54cbd46b31a26d5d8fb264c07045f05d",
|
||||||
urls = [
|
urls = [
|
||||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.37.0/rules_go-v0.37.0.zip",
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.38.1/rules_go-v0.38.1.zip",
|
||||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.37.0/rules_go-v0.37.0.zip",
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.38.1/rules_go-v0.38.1.zip",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,8 +32,7 @@ go_rules_dependencies()
|
|||||||
# use latest stable.
|
# use latest stable.
|
||||||
go_download_sdk(
|
go_download_sdk(
|
||||||
name = "go_sdk",
|
name = "go_sdk",
|
||||||
#version = "1.20rc1",
|
version = "1.20",
|
||||||
version = "1.19.5",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
go_register_toolchains()
|
go_register_toolchains()
|
||||||
|
@ -86,8 +86,7 @@ const usage_other = "" ++
|
|||||||
" zig {[zig_tool]s} <args>...\n";
|
" zig {[zig_tool]s} <args>...\n";
|
||||||
|
|
||||||
const Action = enum {
|
const Action = enum {
|
||||||
early_ok,
|
err,
|
||||||
early_err,
|
|
||||||
exec,
|
exec,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,8 +96,7 @@ const ExecParams = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ParseResults = union(Action) {
|
const ParseResults = union(Action) {
|
||||||
early_ok,
|
err: []const u8,
|
||||||
early_err: []const u8,
|
|
||||||
exec: ExecParams,
|
exec: ExecParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,8 +118,7 @@ pub fn main() u8 {
|
|||||||
return fatal("error: {s}\n", .{@errorName(err)});
|
return fatal("error: {s}\n", .{@errorName(err)});
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
.early_ok => return 0,
|
.err => |msg| return fatal("{s}", .{msg}),
|
||||||
.early_err => |msg| return fatal("{s}", .{msg}),
|
|
||||||
.exec => |params| {
|
.exec => |params| {
|
||||||
if (builtin.os.tag == .windows)
|
if (builtin.os.tag == .windows)
|
||||||
return spawnWindows(arena, params)
|
return spawnWindows(arena, params)
|
||||||
@ -224,9 +221,6 @@ fn parseArgs(
|
|||||||
while (argv_it.next()) |arg|
|
while (argv_it.next()) |arg|
|
||||||
try args.append(arena, arg);
|
try args.append(arena, arg);
|
||||||
|
|
||||||
if (mem.eql(u8, zig_tool, "c++") and shouldReturnEarly(args.items))
|
|
||||||
return .early_ok;
|
|
||||||
|
|
||||||
return ParseResults{ .exec = .{ .args = args, .env = env } };
|
return ParseResults{ .exec = .{ .args = args, .env = env } };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +230,7 @@ fn parseFatal(
|
|||||||
args: anytype,
|
args: anytype,
|
||||||
) error{OutOfMemory}!ParseResults {
|
) error{OutOfMemory}!ParseResults {
|
||||||
const msg = try std.fmt.allocPrint(arena, fmt ++ "\n", args);
|
const msg = try std.fmt.allocPrint(arena, fmt ++ "\n", args);
|
||||||
return ParseResults{ .early_err = msg };
|
return ParseResults{ .err = msg };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fatal(comptime fmt: []const u8, args: anytype) u8 {
|
pub fn fatal(comptime fmt: []const u8, args: anytype) u8 {
|
||||||
@ -244,20 +238,6 @@ pub fn fatal(comptime fmt: []const u8, args: anytype) u8 {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Golang probing for a particular linker flag causes many unneeded stubs to be
|
|
||||||
// built, e.g. glibc, musl, libc++. The hackery can probably be deleted after
|
|
||||||
// Go 1.20 is released. In particular,
|
|
||||||
// https://go-review.googlesource.com/c/go/+/436884
|
|
||||||
fn shouldReturnEarly(args: []const []const u8) bool {
|
|
||||||
const prelude = comptimeSplit("-Wl,--no-gc-sections -x c - -o /dev/null");
|
|
||||||
if (args.len < prelude.len)
|
|
||||||
return false;
|
|
||||||
for (prelude) |arg, i|
|
|
||||||
if (!mem.eql(u8, arg, args[args.len - prelude.len + i]))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn getTarget(self_exe: []const u8) error{BadParent}!?[]const u8 {
|
fn getTarget(self_exe: []const u8) error{BadParent}!?[]const u8 {
|
||||||
const here = fs.path.dirname(self_exe) orelse return error.BadParent;
|
const here = fs.path.dirname(self_exe) orelse return error.BadParent;
|
||||||
const triple = fs.path.basename(here);
|
const triple = fs.path.basename(here);
|
||||||
@ -288,35 +268,12 @@ fn getTarget(self_exe: []const u8) error{BadParent}!?[]const u8 {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn comptimeSplit(comptime str: []const u8) [countWords(str)][]const u8 {
|
|
||||||
var arr: [countWords(str)][]const u8 = undefined;
|
|
||||||
var i: usize = 0;
|
|
||||||
var it = mem.split(u8, str, " ");
|
|
||||||
while (it.next()) |arg| : (i += 1)
|
|
||||||
arr[i] = arg;
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn countWords(str: []const u8) usize {
|
fn countWords(str: []const u8) usize {
|
||||||
return mem.count(u8, str, " ") + 1;
|
return mem.count(u8, str, " ") + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
test "launcher:shouldReturnEarly" {
|
|
||||||
inline for (.{
|
|
||||||
"-Wl,--no-gc-sections -x c - -o /dev/null",
|
|
||||||
"foo.c -o main -Wl,--no-gc-sections -x c - -o /dev/null",
|
|
||||||
}) |tt| try testing.expect(shouldReturnEarly(comptimeSplit(tt)[0..]));
|
|
||||||
|
|
||||||
inline for (.{
|
|
||||||
"",
|
|
||||||
"cc -Wl,--no-gc-sections -x c - -o /dev/null x",
|
|
||||||
"-Wl,--no-gc-sections -x c - -o",
|
|
||||||
"incorrect-value -x c - -o /dev/null",
|
|
||||||
}) |tt| try testing.expect(!shouldReturnEarly(comptimeSplit(tt)[0..]));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const TestArgIterator = struct {
|
pub const TestArgIterator = struct {
|
||||||
index: usize = 0,
|
index: usize = 0,
|
||||||
argv: []const [:0]const u8,
|
argv: []const [:0]const u8,
|
||||||
@ -355,8 +312,7 @@ test "launcher:parseArgs" {
|
|||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
precreate_dir: ?[]const u8 = null,
|
precreate_dir: ?[]const u8 = null,
|
||||||
want_result: union(Action) {
|
want_result: union(Action) {
|
||||||
early_ok,
|
err: []const u8,
|
||||||
early_err: []const u8,
|
|
||||||
exec: struct {
|
exec: struct {
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
env_zig_lib_dir: []const u8,
|
env_zig_lib_dir: []const u8,
|
||||||
@ -366,7 +322,7 @@ test "launcher:parseArgs" {
|
|||||||
.{
|
.{
|
||||||
.args = &[_][:0]const u8{"ar" ++ EXE},
|
.args = &[_][:0]const u8{"ar" ++ EXE},
|
||||||
.want_result = .{
|
.want_result = .{
|
||||||
.early_err = std.fmt.comptimePrint(usage_other ++ "\n", .{
|
.err = std.fmt.comptimePrint(usage_other ++ "\n", .{
|
||||||
.zig_tool = "ar",
|
.zig_tool = "ar",
|
||||||
.exe = EXE,
|
.exe = EXE,
|
||||||
}),
|
}),
|
||||||
@ -375,25 +331,12 @@ test "launcher:parseArgs" {
|
|||||||
.{
|
.{
|
||||||
.args = &[_][:0]const u8{"c++" ++ EXE},
|
.args = &[_][:0]const u8{"c++" ++ EXE},
|
||||||
.want_result = .{
|
.want_result = .{
|
||||||
.early_err = std.fmt.comptimePrint(usage_cpp ++ "\n", .{
|
.err = std.fmt.comptimePrint(usage_cpp ++ "\n", .{
|
||||||
.zig_tool = "c++",
|
.zig_tool = "c++",
|
||||||
.exe = EXE,
|
.exe = EXE,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.{
|
|
||||||
.args = &[_][:0]const u8{
|
|
||||||
"external" ++ sep ++ "zig_sdk" ++ "tools" ++ sep ++
|
|
||||||
"x86_64-linux-musl" ++ sep ++ "c++" ++ EXE,
|
|
||||||
"-Wl,--no-gc-sections",
|
|
||||||
"-x",
|
|
||||||
"c",
|
|
||||||
"-",
|
|
||||||
"-o",
|
|
||||||
"/dev/null",
|
|
||||||
},
|
|
||||||
.want_result = .early_ok,
|
|
||||||
},
|
|
||||||
.{
|
.{
|
||||||
.args = &[_][:0]const u8{
|
.args = &[_][:0]const u8{
|
||||||
"tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++ "c++" ++ EXE,
|
"tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++ "c++" ++ EXE,
|
||||||
@ -481,10 +424,9 @@ test "launcher:parseArgs" {
|
|||||||
});
|
});
|
||||||
|
|
||||||
switch (tt.want_result) {
|
switch (tt.want_result) {
|
||||||
.early_ok => try testing.expectEqual(res, .early_ok),
|
.err => |want_msg| try testing.expectEqualStrings(
|
||||||
.early_err => |want_msg| try testing.expectEqualStrings(
|
|
||||||
want_msg,
|
want_msg,
|
||||||
res.early_err,
|
res.err,
|
||||||
),
|
),
|
||||||
.exec => |want| {
|
.exec => |want| {
|
||||||
try compareExec(res, want.args, want.env_zig_lib_dir);
|
try compareExec(res, want.args, want.env_zig_lib_dir);
|
||||||
|
Loading…
Reference in New Issue
Block a user