1
Fork 0

wip go 1.20

nix
Motiejus Jakštys 2023-02-10 15:44:56 +02:00
parent 0fd73783db
commit 53d89ba627
3 changed files with 14 additions and 73 deletions

View File

@ -1 +1 @@
5.2.0
6.0.0

View File

@ -6,10 +6,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "56d8c5a5c91e1af73eca71a6fab2ced959b67c86d12ba37feedb0a2dfea441a6",
sha256 = "dd926a88a564a9246713a9c00b35315f54cbd46b31a26d5d8fb264c07045f05d",
urls = [
"https://mirror.bazel.build/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.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.38.1/rules_go-v0.38.1.zip",
],
)
@ -32,8 +32,7 @@ go_rules_dependencies()
# use latest stable.
go_download_sdk(
name = "go_sdk",
#version = "1.20rc1",
version = "1.19.5",
version = "1.20",
)
go_register_toolchains()

View File

@ -86,8 +86,7 @@ const usage_other = "" ++
" zig {[zig_tool]s} <args>...\n";
const Action = enum {
early_ok,
early_err,
err,
exec,
};
@ -97,8 +96,7 @@ const ExecParams = struct {
};
const ParseResults = union(Action) {
early_ok,
early_err: []const u8,
err: []const u8,
exec: ExecParams,
};
@ -120,8 +118,7 @@ pub fn main() u8 {
return fatal("error: {s}\n", .{@errorName(err)});
switch (action) {
.early_ok => return 0,
.early_err => |msg| return fatal("{s}", .{msg}),
.err => |msg| return fatal("{s}", .{msg}),
.exec => |params| {
if (builtin.os.tag == .windows)
return spawnWindows(arena, params)
@ -224,9 +221,6 @@ fn parseArgs(
while (argv_it.next()) |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 } };
}
@ -236,7 +230,7 @@ fn parseFatal(
args: anytype,
) error{OutOfMemory}!ParseResults {
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 {
@ -244,20 +238,6 @@ pub fn fatal(comptime fmt: []const u8, args: anytype) u8 {
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 {
const here = fs.path.dirname(self_exe) orelse return error.BadParent;
const triple = fs.path.basename(here);
@ -288,35 +268,12 @@ fn getTarget(self_exe: []const u8) error{BadParent}!?[]const u8 {
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 {
return mem.count(u8, str, " ") + 1;
}
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 {
index: usize = 0,
argv: []const [:0]const u8,
@ -355,8 +312,7 @@ test "launcher:parseArgs" {
args: []const [:0]const u8,
precreate_dir: ?[]const u8 = null,
want_result: union(Action) {
early_ok,
early_err: []const u8,
err: []const u8,
exec: struct {
args: []const [:0]const u8,
env_zig_lib_dir: []const u8,
@ -366,7 +322,7 @@ test "launcher:parseArgs" {
.{
.args = &[_][:0]const u8{"ar" ++ EXE},
.want_result = .{
.early_err = std.fmt.comptimePrint(usage_other ++ "\n", .{
.err = std.fmt.comptimePrint(usage_other ++ "\n", .{
.zig_tool = "ar",
.exe = EXE,
}),
@ -375,25 +331,12 @@ test "launcher:parseArgs" {
.{
.args = &[_][:0]const u8{"c++" ++ EXE},
.want_result = .{
.early_err = std.fmt.comptimePrint(usage_cpp ++ "\n", .{
.err = std.fmt.comptimePrint(usage_cpp ++ "\n", .{
.zig_tool = "c++",
.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{
"tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++ "c++" ++ EXE,
@ -481,10 +424,9 @@ test "launcher:parseArgs" {
});
switch (tt.want_result) {
.early_ok => try testing.expectEqual(res, .early_ok),
.early_err => |want_msg| try testing.expectEqualStrings(
.err => |want_msg| try testing.expectEqualStrings(
want_msg,
res.early_err,
res.err,
),
.exec => |want| {
try compareExec(res, want.args, want.env_zig_lib_dir);