authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-12-29 18:52:53+01:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2021-01-03 17:23:30+01:00
log0ed04aac8bc0cfaa0b2489f7392a6df4e3915b0f
tree8fe360becae88e873172c510d0e87f6dbc697f42
parent5aac2fc28111e59a2a05a4fae42b6e19d4e0b7ca

stage2: fix building self-hosted compiler with -Dstatic-llvm

This supersedes c81ae52ee0b2e952f8ed9c5c6517af8182bb09c1

2 files changed, 42 insertions(+), 21 deletions(-)

build.zig+23-20
...@@ -91,6 +91,20 @@ pub fn build(b: *Builder) !void {...@@ -91,6 +91,20 @@ pub fn build(b: *Builder) !void {
91 exe.addBuildOption(bool, "have_llvm", enable_llvm);91 exe.addBuildOption(bool, "have_llvm", enable_llvm);
92 if (enable_llvm) {92 if (enable_llvm) {
93 const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);93 const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
94
95 const exe_cflags = [_][]const u8{
96 "-std=c++14",
97 "-D__STDC_CONSTANT_MACROS",
98 "-D__STDC_FORMAT_MACROS",
99 "-D__STDC_LIMIT_MACROS",
100 "-D_GNU_SOURCE",
101 "-fvisibility-inlines-hidden",
102 "-fno-exceptions",
103 "-fno-rtti",
104 "-Werror=type-limits",
105 "-Wno-missing-braces",
106 "-Wno-comment",
107 };
94 if (is_stage1) {108 if (is_stage1) {
95 exe.addIncludeDir("src");109 exe.addIncludeDir("src");
96 exe.addIncludeDir("deps/SoftFloat-3e/source/include");110 exe.addIncludeDir("deps/SoftFloat-3e/source/include");
...@@ -109,28 +123,8 @@ pub fn build(b: *Builder) !void {...@@ -109,28 +123,8 @@ pub fn build(b: *Builder) !void {
109 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });123 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
110 exe.linkLibrary(softfloat);124 exe.linkLibrary(softfloat);
111125
112 const exe_cflags = [_][]const u8{
113 "-std=c++14",
114 "-D__STDC_CONSTANT_MACROS",
115 "-D__STDC_FORMAT_MACROS",
116 "-D__STDC_LIMIT_MACROS",
117 "-D_GNU_SOURCE",
118 "-fvisibility-inlines-hidden",
119 "-fno-exceptions",
120 "-fno-rtti",
121 "-Werror=type-limits",
122 "-Wno-missing-braces",
123 "-Wno-comment",
124 };
125 exe.addCSourceFiles(&stage1_sources, &exe_cflags);126 exe.addCSourceFiles(&stage1_sources, &exe_cflags);
126 exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });127 exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
127 if (cmake_cfg == null) {
128 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
129 // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is
130 // unavailable when LLVM is compiled in Release mode.
131 const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
132 exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);
133 }
134 }128 }
135 if (cmake_cfg) |cfg| {129 if (cmake_cfg) |cfg| {
136 // Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.130 // Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
...@@ -193,6 +187,15 @@ pub fn build(b: *Builder) !void {...@@ -193,6 +187,15 @@ pub fn build(b: *Builder) !void {
193 }187 }
194 } else {188 } else {
195 // Here we are -Denable-llvm but no cmake integration.189 // Here we are -Denable-llvm but no cmake integration.
190
191 // Adds the Zig C++ sources which both stage1 and stage2 need.
192 //
193 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
194 // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is
195 // unavailable when LLVM is compiled in Release mode.
196 const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
197 exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);
198
196 for (clang_libs) |lib_name| {199 for (clang_libs) |lib_name| {
197 exe.linkSystemLibrary(lib_name);200 exe.linkSystemLibrary(lib_name);
198 }201 }
src/zig_clang.h+19-1
...@@ -8,14 +8,32 @@...@@ -8,14 +8,32 @@
8#ifndef ZIG_ZIG_CLANG_H8#ifndef ZIG_ZIG_CLANG_H
9#define ZIG_ZIG_CLANG_H9#define ZIG_ZIG_CLANG_H
1010
11#include "stage1/stage2.h"
12#include <inttypes.h>11#include <inttypes.h>
13#include <stdbool.h>12#include <stdbool.h>
13#include <stddef.h>
14
15#ifdef __cplusplus
16#define ZIG_EXTERN_C extern "C"
17#else
18#define ZIG_EXTERN_C
19#endif
1420
15// ATTENTION: If you modify this file, be sure to update the corresponding21// ATTENTION: If you modify this file, be sure to update the corresponding
16// extern function declarations in the self-hosted compiler file22// extern function declarations in the self-hosted compiler file
17// src/clang.zig.23// src/clang.zig.
1824
25// ABI warning
26struct Stage2ErrorMsg {
27 const char *filename_ptr; // can be null
28 size_t filename_len;
29 const char *msg_ptr;
30 size_t msg_len;
31 const char *source; // valid until the ASTUnit is freed. can be null
32 unsigned line; // 0 based
33 unsigned column; // 0 based
34 unsigned offset; // byte offset into source
35};
36
19struct ZigClangSourceLocation {37struct ZigClangSourceLocation {
20 unsigned ID;38 unsigned ID;
21};39};