"generate .h files" feature is no longer supported in stage1

This commit is contained in:
Andrew Kelley 2020-03-20 18:33:36 -04:00
parent 8429ddecf8
commit 3a2c490889
7 changed files with 36 additions and 22 deletions

View File

@ -622,7 +622,6 @@ set(BUILD_LIBSTAGE2_ARGS "build-lib"
--cache on
--output-dir "${CMAKE_BINARY_DIR}"
${LIBSTAGE2_RELEASE_ARG}
--disable-gen-h
--bundle-compiler-rt
-fPIC
-lc

View File

@ -134,7 +134,8 @@ pub fn build(b: *Builder) !void {
test_step.dependOn(tests.addRuntimeSafetyTests(b, test_filter, modes));
test_step.dependOn(tests.addTranslateCTests(b, test_filter));
test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter));
test_step.dependOn(tests.addGenHTests(b, test_filter));
// tests for this feature are disabled until we have the self-hosted compiler available
//test_step.dependOn(tests.addGenHTests(b, test_filter));
test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
test_step.dependOn(docs_step);
}

View File

@ -1121,7 +1121,7 @@ pub const LibExeObjStep = struct {
emit_llvm_ir: bool = false,
emit_asm: bool = false,
emit_bin: bool = true,
disable_gen_h: bool,
emit_h: bool = false,
bundle_compiler_rt: bool,
disable_stack_probing: bool,
disable_sanitize_c: bool,
@ -1281,7 +1281,6 @@ pub const LibExeObjStep = struct {
.exec_cmd_args = null,
.name_prefix = "",
.filter = null,
.disable_gen_h = false,
.bundle_compiler_rt = false,
.disable_stack_probing = false,
.disable_sanitize_c = false,
@ -1600,8 +1599,9 @@ pub const LibExeObjStep = struct {
self.main_pkg_path = dir_path;
}
pub fn setDisableGenH(self: *LibExeObjStep, value: bool) void {
self.disable_gen_h = value;
/// Deprecated; just set the field directly.
pub fn setDisableGenH(self: *LibExeObjStep, is_disabled: bool) void {
self.emit_h = !is_disabled;
}
pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void {
@ -1632,7 +1632,7 @@ pub const LibExeObjStep = struct {
/// the make step, from a step that has declared a dependency on this one.
pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
assert(self.kind != Kind.Exe);
assert(!self.disable_gen_h);
assert(self.emit_h);
return fs.path.join(
self.builder.allocator,
&[_][]const u8{ self.output_dir.?, self.out_h_filename },
@ -1884,6 +1884,7 @@ pub const LibExeObjStep = struct {
if (self.emit_llvm_ir) try zig_args.append("-femit-llvm-ir");
if (self.emit_asm) try zig_args.append("-femit-asm");
if (!self.emit_bin) try zig_args.append("-fno-emit-bin");
if (self.emit_h) try zig_args.append("-femit-h");
if (self.strip) {
try zig_args.append("--strip");
@ -1929,9 +1930,6 @@ pub const LibExeObjStep = struct {
if (self.is_dynamic) {
try zig_args.append("-dynamic");
}
if (self.disable_gen_h) {
try zig_args.append("--disable-gen-h");
}
if (self.bundle_compiler_rt) {
try zig_args.append("--bundle-compiler-rt");
}
@ -2069,7 +2067,7 @@ pub const LibExeObjStep = struct {
try zig_args.append("-isystem");
try zig_args.append(self.builder.pathFromRoot(include_path));
},
.OtherStep => |other| if (!other.disable_gen_h) {
.OtherStep => |other| if (other.emit_h) {
const h_path = other.getOutputHPath();
try zig_args.append("-isystem");
try zig_args.append(fs.path.dirname(h_path).?);
@ -2209,7 +2207,7 @@ const InstallArtifactStep = struct {
break :blk InstallDir.Lib;
}
} else null,
.h_dir = if (artifact.kind == .Lib and !artifact.disable_gen_h) .Header else null,
.h_dir = if (artifact.kind == .Lib and artifact.emit_h) .Header else null,
};
self.step.dependOn(&artifact.step);
artifact.install_step = self;

View File

@ -41,6 +41,10 @@ fn _DllMainCRTStartup(
fdwReason: std.os.windows.DWORD,
lpReserved: std.os.windows.LPVOID,
) callconv(.Stdcall) std.os.windows.BOOL {
if (!builtin.single_threaded) {
_ = @import("start_windows_tls.zig");
}
if (@hasDecl(root, "DllMain")) {
return root.DllMain(hinstDLL, fdwReason, lpReserved);
}

View File

@ -54,7 +54,6 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
" --cache-dir [path] override the local cache directory\n"
" --cache [auto|off|on] build in cache, print output path to stdout\n"
" --color [auto|off|on] enable or disable colored error messages\n"
" --disable-gen-h do not generate a C header file (.h)\n"
" --disable-valgrind omit valgrind client requests in debug builds\n"
" --eh-frame-hdr enable C++ exception handling by passing --eh-frame-hdr to linker\n"
" --enable-valgrind include valgrind client requests release builds\n"
@ -77,6 +76,8 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
" -fno-emit-asm (default) do not output .s (assembly code)\n"
" -femit-llvm-ir produce a .ll file with LLVM IR\n"
" -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"
" -femit-h generate a C header file (.h)\n"
" -fno-emit-h (default) do not generate a C header file (.h)\n"
" --libc [file] Provide a file which specifies libc paths\n"
" --name [name] override output name\n"
" --output-dir [dir] override output directory (defaults to cwd)\n"
@ -431,6 +432,7 @@ static int main0(int argc, char **argv) {
bool emit_bin = true;
bool emit_asm = false;
bool emit_llvm_ir = false;
bool emit_h = false;
const char *cache_dir = nullptr;
CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>();
BuildMode build_mode = BuildModeDebug;
@ -439,7 +441,6 @@ static int main0(int argc, char **argv) {
bool system_linker_hack = false;
TargetSubsystem subsystem = TargetSubsystemAuto;
bool want_single_threaded = false;
bool disable_gen_h = false;
bool bundle_compiler_rt = false;
Buf *override_lib_dir = nullptr;
Buf *main_pkg_path = nullptr;
@ -660,9 +661,7 @@ static int main0(int argc, char **argv) {
} else if (strcmp(arg, "--system-linker-hack") == 0) {
system_linker_hack = true;
} else if (strcmp(arg, "--single-threaded") == 0) {
want_single_threaded = true;
} else if (strcmp(arg, "--disable-gen-h") == 0) {
disable_gen_h = true;
want_single_threaded = true;;
} else if (strcmp(arg, "--bundle-compiler-rt") == 0) {
bundle_compiler_rt = true;
} else if (strcmp(arg, "--test-cmd-bin") == 0) {
@ -719,6 +718,11 @@ static int main0(int argc, char **argv) {
emit_llvm_ir = true;
} else if (strcmp(arg, "-fno-emit-llvm-ir") == 0) {
emit_llvm_ir = false;
} else if (strcmp(arg, "-femit-h") == 0) {
emit_h = true;
} else if (strcmp(arg, "-fno-emit-h") == 0 || strcmp(arg, "--disable-gen-h") == 0) {
// the --disable-gen-h is there to support godbolt. once they upgrade to -fno-emit-h then we can remove this
emit_h = false;
} else if (str_starts_with(arg, "-mcpu=")) {
mcpu = arg + strlen("-mcpu=");
} else if (i + 1 >= argc) {
@ -1202,7 +1206,7 @@ static int main0(int argc, char **argv) {
g->verbose_cc = verbose_cc;
g->verbose_llvm_cpu_features = verbose_llvm_cpu_features;
g->output_dir = output_dir;
g->disable_gen_h = disable_gen_h;
g->disable_gen_h = !emit_h;
g->bundle_compiler_rt = bundle_compiler_rt;
codegen_set_errmsg_color(g, color);
g->system_linker_hack = system_linker_hack;

View File

@ -1,10 +1,12 @@
// This header is generated by zig from base64.zig
#include "base64.h"
#include <assert.h>
#include <string.h>
#include <stdint.h>
// TODO we would like to #include "base64.h" here but this feature has been disabled in
// the stage1 compiler. Users will have to wait until self-hosted is available for
// the "generate .h file" feature.
size_t decode_base_64(uint8_t *dest_ptr, size_t dest_len, const uint8_t *source_ptr, size_t source_len);
extern int *x_ptr;
int main(int argc, char **argv) {

View File

@ -1,6 +1,12 @@
#include "mathtest.h"
#include <assert.h>
// TODO we would like to #include "mathtest.h" here but this feature has been disabled in
// the stage1 compiler. Users will have to wait until self-hosted is available for
// the "generate .h file" feature.
#include <stdint.h>
int32_t add(int32_t a, int32_t b);
int main(int argc, char **argv) {
assert(add(42, 1337) == 1379);
return 0;