Update to Zig 0.8.1, update patches, add LLVM 13 patch, add conditions

This commit is contained in:
Jan200101 2021-09-12 18:52:57 +02:00
parent 840ad2e520
commit 8b6be487d3
No known key found for this signature in database
GPG Key ID: 5B71B1D78B882E05
5 changed files with 1011812 additions and 244 deletions

View File

@ -1,8 +1,9 @@
From c1ecb97befdb6a1106c1651da69f08cfb34f754a Mon Sep 17 00:00:00 2001
From 9fda724c7fc3ad84b6efb2027e03b4407016230d Mon Sep 17 00:00:00 2001
From: Jan200101 <sentrycraft123@gmail.com>
Date: Sat, 12 Jun 2021 11:23:04 +0200
Subject: [PATCH 1/2] specify the output lib, exe and include paths with flags
Subject: [PATCH 1/3] specify the output lib, exe and include paths with flags
(cherry picked from commit 5a4249fa25ab789a8c060e5ba71ca8b0358e9c8d)
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
---
lib/std/build.zig | 34 ++++++++++++++++++++++++++++----
@ -10,10 +11,10 @@ Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
2 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/lib/std/build.zig b/lib/std/build.zig
index 572f2b2be..a12186464 100644
index 9b7ebb1f4..208e83e71 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -122,6 +122,12 @@ pub const Builder = struct {
@@ -124,6 +124,12 @@ pub const Builder = struct {
description: []const u8,
};
@ -26,7 +27,7 @@ index 572f2b2be..a12186464 100644
pub fn create(
allocator: *Allocator,
zig_exe: []const u8,
@@ -190,7 +196,7 @@ pub const Builder = struct {
@@ -192,7 +198,7 @@ pub const Builder = struct {
}
/// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
@ -35,7 +36,7 @@ index 572f2b2be..a12186464 100644
if (self.dest_dir) |dest_dir| {
self.install_prefix = install_prefix orelse "/usr";
self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;
@@ -199,9 +205,29 @@ pub const Builder = struct {
@@ -201,9 +207,29 @@ pub const Builder = struct {
(fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
self.install_path = self.install_prefix;
}
@ -69,7 +70,7 @@ index 572f2b2be..a12186464 100644
pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig
index c6185ef09..da50548c6 100644
index d1154add0..d3f066a19 100644
--- a/lib/std/special/build_runner.zig
+++ b/lib/std/special/build_runner.zig
@@ -61,6 +61,8 @@ pub fn main() !void {
@ -100,10 +101,10 @@ index c6185ef09..da50548c6 100644
+ warn("Expected argument after {s}\n\n", .{arg});
+ return usageAndErr(builder, false, stderr_stream);
+ };
} else if (mem.eql(u8, arg, "--search-prefix")) {
const search_prefix = nextArg(args, &arg_idx) orelse {
warn("Expected argument after --search-prefix\n\n", .{});
@@ -135,7 +152,7 @@ pub fn main() !void {
} else if (mem.eql(u8, arg, "--sysroot")) {
const sysroot = nextArg(args, &arg_idx) orelse {
warn("Expected argument after --sysroot\n\n", .{});
@@ -147,7 +164,7 @@ pub fn main() !void {
}
}
@ -112,7 +113,7 @@ index c6185ef09..da50548c6 100644
try runBuild(builder);
if (builder.validateUserInputDidItFail())
@@ -163,7 +180,7 @@ fn runBuild(builder: *Builder) anyerror!void {
@@ -175,7 +192,7 @@ fn runBuild(builder: *Builder) anyerror!void {
fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {
// run the build script to collect the options
if (!already_ran_build) {
@ -121,16 +122,16 @@ index c6185ef09..da50548c6 100644
try runBuild(builder);
}
@@ -189,6 +206,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
@@ -201,6 +218,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
\\ -h, --help Print this help and exit
\\ --verbose Print commands before executing them
\\ -p, --prefix [path] Override default install prefix
+ \\ --lib-dir [path] Override default library directory path
+ \\ --exe-dir [path] Override default executable directory path
+ \\ --include-dir [path] Override default include directory path
\\ --sysroot [path] Set the system root directory (usually /)
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --color [auto|off|on] Enable or disable colored error messages
\\
\\ --libc [file] Provide a file which specifies libc paths
--
2.31.1

View File

@ -1,18 +1,19 @@
From c95b2bd1f14f602b78f90714d5e614251fa83552 Mon Sep 17 00:00:00 2001
From 2128aaf02ac91cf07c449062c0cbffb3ab1fbe42 Mon Sep 17 00:00:00 2001
From: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 14 Jun 2021 11:56:58 -0700
Subject: [PATCH 2/2] zig build: rename --lib-dir, --include-dir, --exe-dir
Subject: [PATCH 2/3] zig build: rename --lib-dir, --include-dir, --exe-dir
To --prefix-lib-dir, --prefix-include-dir, --prefix-exe-dir,
respectively.
(cherry picked from commit 7d5538c32b7acfb6878be4178af2f71977d0cf9d)
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
---
lib/std/special/build_runner.zig | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
lib/std/special/build_runner.zig | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig
index da50548c6..f3c74279a 100644
index d3f066a19..366a0a2dc 100644
--- a/lib/std/special/build_runner.zig
+++ b/lib/std/special/build_runner.zig
@@ -89,17 +89,17 @@ pub fn main() !void {
@ -36,24 +37,27 @@ index da50548c6..f3c74279a 100644
dir_list.include_dir = nextArg(args, &arg_idx) orelse {
warn("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
@@ -203,13 +203,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
@@ -215,15 +215,17 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
try out_stream.writeAll(
\\
\\General Options:
- \\ -h, --help Print this help and exit
- \\ --verbose Print commands before executing them
- \\ -p, --prefix [path] Override default install prefix
- \\ --lib-dir [path] Override default library directory path
- \\ --exe-dir [path] Override default executable directory path
- \\ --include-dir [path] Override default include directory path
+ \\ -p, --prefix [path] Override default install prefix
+ \\ --prefix-lib-dir [path] Override default library directory path
+ \\ --prefix-exe-dir [path] Override default executable directory path
+ \\ --prefix-include-dir [path] Override default include directory path
+ \\
+ \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --sysroot [path] Set the system root directory (usually /)
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --libc [file] Provide a file which specifies libc paths
+ \\
\\ -h, --help Print this help and exit
\\ --verbose Print commands before executing them
- \\ -p, --prefix [path] Override default install prefix
- \\ --lib-dir [path] Override default library directory path
- \\ --exe-dir [path] Override default executable directory path
- \\ --include-dir [path] Override default include directory path
- \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
+ \\ -h, --help Print this help and exit
+ \\ --verbose Print commands before executing them
\\ --color [auto|off|on] Enable or disable colored error messages
\\
\\Project-Specific Options:

1011717
0003-LLVM-13-rebase.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,192 +0,0 @@
From 7c6f80f74395e546382c0400ef6db50c1b3e6439 Mon Sep 17 00:00:00 2001
From: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 8 Jun 2021 12:48:48 -0700
Subject: [PATCH] native libc detection: respect spaces in CC env var
Zig has detection for when it is accidentally being called recursively
when trying to find the native libc installation. However it was not
working, resulting in a cryptic failure, because zig tried to execute
a command which had spaces in it rather than tokenizing it.
This improves the user experience of `zig cc` for systems that Zig
does not support cross-compiling for.
Closes #8960
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
---
src/libc_installation.zig | 99 +++++++++++++++++++++++++++------------
1 file changed, 70 insertions(+), 29 deletions(-)
diff --git a/src/libc_installation.zig b/src/libc_installation.zig
index 2286b2c85..783f76b9b 100644
--- a/src/libc_installation.zig
+++ b/src/libc_installation.zig
@@ -237,26 +237,38 @@ pub const LibCInstallation = struct {
fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) FindError!void {
const allocator = args.allocator;
+
+ // Detect infinite loops.
+ var env_map = try std.process.getEnvMap(allocator);
+ defer env_map.deinit();
+ const skip_cc_env_var = if (env_map.get(inf_loop_env_key)) |phase| blk: {
+ if (std.mem.eql(u8, phase, "1")) {
+ try env_map.put(inf_loop_env_key, "2");
+ break :blk true;
+ } else {
+ return error.ZigIsTheCCompiler;
+ }
+ } else blk: {
+ try env_map.put(inf_loop_env_key, "1");
+ break :blk false;
+ };
+
const dev_null = if (is_windows) "nul" else "/dev/null";
- const cc_exe = std.os.getenvZ("CC") orelse default_cc_exe;
- const argv = [_][]const u8{
- cc_exe,
+
+ var argv = std.ArrayList([]const u8).init(allocator);
+ defer argv.deinit();
+
+ try appendCcExe(&argv, skip_cc_env_var);
+ try argv.appendSlice(&.{
"-E",
"-Wp,-v",
"-xc",
dev_null,
- };
- var env_map = try std.process.getEnvMap(allocator);
- defer env_map.deinit();
-
- // Detect infinite loops.
- const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS";
- if (env_map.get(inf_loop_env_key) != null) return error.ZigIsTheCCompiler;
- try env_map.put(inf_loop_env_key, "1");
+ });
const exec_res = std.ChildProcess.exec(.{
.allocator = allocator,
- .argv = &argv,
+ .argv = argv.items,
.max_output_bytes = 1024 * 1024,
.env_map = &env_map,
// Some C compilers, such as Clang, are known to rely on argv[0] to find the path
@@ -267,7 +279,7 @@ pub const LibCInstallation = struct {
}) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => {
- printVerboseInvocation(&argv, null, args.verbose, null);
+ printVerboseInvocation(argv.items, null, args.verbose, null);
return error.UnableToSpawnCCompiler;
},
};
@@ -277,11 +289,11 @@ pub const LibCInstallation = struct {
}
switch (exec_res.term) {
.Exited => |code| if (code != 0) {
- printVerboseInvocation(&argv, null, args.verbose, exec_res.stderr);
+ printVerboseInvocation(argv.items, null, args.verbose, exec_res.stderr);
return error.CCompilerExitCode;
},
else => {
- printVerboseInvocation(&argv, null, args.verbose, exec_res.stderr);
+ printVerboseInvocation(argv.items, null, args.verbose, exec_res.stderr);
return error.CCompilerCrashed;
},
}
@@ -540,8 +552,6 @@ pub const LibCInstallation = struct {
}
};
-const default_cc_exe = if (is_windows) "cc.exe" else "cc";
-
pub const CCPrintFileNameOptions = struct {
allocator: *Allocator,
search_basename: []const u8,
@@ -553,22 +563,33 @@ pub const CCPrintFileNameOptions = struct {
fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
const allocator = args.allocator;
- const cc_exe = std.os.getenvZ("CC") orelse default_cc_exe;
- const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={s}", .{args.search_basename});
- defer allocator.free(arg1);
- const argv = [_][]const u8{ cc_exe, arg1 };
-
+ // Detect infinite loops.
var env_map = try std.process.getEnvMap(allocator);
defer env_map.deinit();
+ const skip_cc_env_var = if (env_map.get(inf_loop_env_key)) |phase| blk: {
+ if (std.mem.eql(u8, phase, "1")) {
+ try env_map.put(inf_loop_env_key, "2");
+ break :blk true;
+ } else {
+ return error.ZigIsTheCCompiler;
+ }
+ } else blk: {
+ try env_map.put(inf_loop_env_key, "1");
+ break :blk false;
+ };
- // Detect infinite loops.
- const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS";
- if (env_map.get(inf_loop_env_key) != null) return error.ZigIsTheCCompiler;
- try env_map.put(inf_loop_env_key, "1");
+ var argv = std.ArrayList([]const u8).init(allocator);
+ defer argv.deinit();
+
+ const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={s}", .{args.search_basename});
+ defer allocator.free(arg1);
+
+ try appendCcExe(&argv, skip_cc_env_var);
+ try argv.append(arg1);
const exec_res = std.ChildProcess.exec(.{
.allocator = allocator,
- .argv = &argv,
+ .argv = argv.items,
.max_output_bytes = 1024 * 1024,
.env_map = &env_map,
// Some C compilers, such as Clang, are known to rely on argv[0] to find the path
@@ -586,11 +607,11 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
}
switch (exec_res.term) {
.Exited => |code| if (code != 0) {
- printVerboseInvocation(&argv, args.search_basename, args.verbose, exec_res.stderr);
+ printVerboseInvocation(argv.items, args.search_basename, args.verbose, exec_res.stderr);
return error.CCompilerExitCode;
},
else => {
- printVerboseInvocation(&argv, args.search_basename, args.verbose, exec_res.stderr);
+ printVerboseInvocation(argv.items, args.search_basename, args.verbose, exec_res.stderr);
return error.CCompilerCrashed;
},
}
@@ -659,3 +680,23 @@ fn fillSearch(search_buf: *[2]Search, sdk: *ZigWindowsSDK) []Search {
}
return search_buf[0..search_end];
}
+
+const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS";
+
+fn appendCcExe(args: *std.ArrayList([]const u8), skip_cc_env_var: bool) !void {
+ const default_cc_exe = if (is_windows) "cc.exe" else "cc";
+ try args.ensureUnusedCapacity(1);
+ if (skip_cc_env_var) {
+ args.appendAssumeCapacity(default_cc_exe);
+ return;
+ }
+ const cc_env_var = std.os.getenvZ("CC") orelse {
+ args.appendAssumeCapacity(default_cc_exe);
+ return;
+ };
+ // Respect space-separated flags to the C compiler.
+ var it = std.mem.tokenize(cc_env_var, " ");
+ while (it.next()) |arg| {
+ try args.append(arg);
+ }
+}
--
2.31.1

View File

@ -1,13 +1,29 @@
# https://ziglang.org/download/0.8.0/release-notes.html#Support-Table
# https://ziglang.org/download/0.8.1/release-notes.html#Support-Table
# 32 bit builds currently run out of memory https://github.com/ziglang/zig/issues/6485
%global zig_arches x86_64 aarch64 riscv64 %{mips64}
%if %{fedora} >= 35
%bcond_without llvm13
# documentation and tests do not build due to an unsupported glibc version
%global rawhide 35
%bcond_with test
%bcond_with docs
%global llvm_version 13.0.0
%else
%bcond_with llvm13
%bcond_without test
%bcond_without docs
%global llvm_version 12.0.0
%endif
%bcond_without macro
Name: zig
Version: 0.8.0
Release: 8%{?dist}
Version: 0.8.1
Release: 1%{?dist}
Summary: Programming language for maintaining robust, optimal, and reusable software
License: MIT and NCSA and LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and ISC and Public Domain and GFDL and ZPLv2.1
@ -18,9 +34,8 @@ Source1: macros.%{name}
# https://github.com/ziglang/zig/pull/9020
Patch0: 0001-specify-the-output-lib-exe-and-include-paths-with-fl.patch
Patch1: 0002-zig-build-rename-lib-dir-include-dir-exe-dir.patch
# https://github.com/ziglang/zig/commit/d128ec39df4c0a701523d7d7161df3808a6939d2
# prevents zig from recursively calling itself
Patch2: 0003-native-libc-detection-respect-spaces-in-CC-env-var.patch
Patch100: 0003-LLVM-13-rebase.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -30,30 +45,37 @@ BuildRequires: clang-devel
BuildRequires: lld-devel
# for man page generation
BuildRequires: help2man
# for the macro
%if %{with macro}
BuildRequires: sed
%endif
%if %{with test}
# for testing
#BuildRequires: elfutils-libelf-devel
#BuildRequires: libstdc++-static
BuildRequires: elfutils-libelf-devel
BuildRequires: libstdc++-static
%endif
Requires: %{name}-libs = %{version}
# These packages are bundled as source
# NCSA
Provides: bundled(compiler-rt) = 12.0.0
Provides: bundled(compiler-rt) = %{llvm_version}
# LGPLv2+, LGPLv2+ with exceptions, GPLv2+, GPLv2+ with exceptions, BSD, Inner-Net, ISC, Public Domain and GFDL
Provides: bundled(glibc) = 2.33
# NCSA
Provides: bundled(libcxx) = 12.0.0
Provides: bundled(libcxx) = %{llvm_version}
# NCSA
Provides: bundled(libcxxabi) = 12.0.0
Provides: bundled(libcxxabi) = %{llvm_version}
# NCSA
Provides: bundled(libunwind) = 12.0.0
Provides: bundled(libunwind) = %{llvm_version}
# BSD, LGPG, ZPL
Provides: bundled(mingw) = 8.0.0
Provides: bundled(mingw) = 9.0.0
# MIT
Provides: bundled(musl) = 1.2.2
# CC0, BSD, MIT, Apache2, Apache2 with exceptions
Provides: bundled(wasi-libc) = 82fc2c4f449e56319112f6f2583195c7f4e714b1
ExclusiveArch: %{zig_arches}
@ -69,6 +91,7 @@ BuildArch: noarch
%description libs
Standard Zig library
%if %{with docs}
%package doc
Summary: Documentation for %{name}
BuildArch: noarch
@ -76,7 +99,9 @@ Requires: %{name} = %{version}
%description doc
Documentation for %{name}. For more information, visit %{url}
%endif
%if %{with macro}
%package rpm-macros
Summary: Common RPM macros for %{name}
Requires: rpm
@ -84,9 +109,16 @@ BuildArch: noarch
%description rpm-macros
This package contains common RPM macros for %{name}.
%endif
%prep
%autosetup -p1
%setup -q
%patch0 -p1
%patch1 -p1
%if %{with llvm13}
%patch100 -p1
%endif
%build
@ -102,7 +134,7 @@ help2man --no-discard-stderr "%{__cmake_builddir}/zig" --version-option=version
ln -s lib "%{__cmake_builddir}/"
%if %{rawhide} > 0%{?fedora}
%if %{with docs}
%{__cmake_builddir}/zig build docs -Dversion-string="%{version}"
%endif
mkdir -p zig-cache
@ -121,11 +153,10 @@ sed -i -e "s|@@ZIG_VERSION@@|%{version}|" %{buildroot}%{_rpmconfigdir}/macros.d
%check
%if %{rawhide} > 0%{?fedora}
# tests are affected by an LLVM regression
# https://bugs.llvm.org/show_bug.cgi?id=49401
# https://github.com/ziglang/zig/issues/8130
# %%{__cmake_builddir}/zig build test
%if %{with test}
# Issues with tests stop them from completing successfully
# https://github.com/ziglang/zig/issues/9738
#%%{__cmake_builddir}/zig build test
%endif
%files
@ -136,14 +167,21 @@ sed -i -e "s|@@ZIG_VERSION@@|%{version}|" %{buildroot}%{_rpmconfigdir}/macros.d
%files libs
%{_prefix}/lib/%{name}
%if %{with docs}
%files doc
%doc README.md
%doc zig-cache/langref.html
%endif
%if %{with macro}
%files rpm-macros
%{_rpmconfigdir}/macros.d/macros.%{name}
%endif
%changelog
* Sun Sep 12 2021 Jan Drögehoff <sentrycraft123@gmail.com> - 0.8.1-1
- Update to Zig 0.8.1, add LLVM 13 patch
* Wed Aug 18 2021 Jan Drögehoff <sentrycraft123@gmail.com> - 0.8.0-8
- Rebuilt for lld soname bump