ability to build stage1 using only a zig tarball

The main idea here is that there are now 2 ways to get a stage1 zig
binary:

 * The cmake path. Requirements: cmake, system C++ compiler, system
   LLVM, LLD, Clang libraries, compiled by the system C++ compiler.

 * The zig path. Requirements: a zig installation, system LLVM, LLD,
   Clang libraries, compiled by the zig installation.

Note that the former can be used to now take the latter path.

Removed config.h.in and config.zig.in. The build.zig script no longer is
coupled to the cmake script.

cmake no longer tries to determine the zig version. A build with cmake
will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to
get reverted.

`zig build` now accepts `-Dstage1` which will build the stage1 compiler,
and put the stage2 backend behind a feature flag.

build.zig is simplified to only support the use case of enabling LLVM
support when the LLVM, LLD, and Clang libraries were built by zig. This
part is probably sadly going to have to get reverted to make package
maintainers happy.

Zig build system addBuildOption supports a couple new types.

The biggest reason to make this change is that the zig path is an
attractive option for doing compiler development work on Windows. It
allows people to work on the compiler without having MSVC installed,
using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
This commit is contained in:
Andrew Kelley
2020-12-04 21:33:29 -07:00
parent 5f7b97e84c
commit 5a65caa2a3
18 changed files with 533 additions and 423 deletions

View File

@@ -251,6 +251,20 @@ const Error = extern enum {
Locked,
};
// ABI warning
export fn stage2_version_string() [*:0]const u8 {
return build_options.version;
}
// ABI warning
export fn stage2_version() Stage2SemVer {
return .{
.major = build_options.semver.major,
.minor = build_options.semver.minor,
.patch = build_options.semver.patch,
};
}
// ABI warning
export fn stage2_attach_segfault_handler() void {
if (std.debug.runtime_safety and std.debug.have_segfault_handling_support) {

View File

@@ -8,7 +8,6 @@
#include "analyze.hpp"
#include "ast_render.hpp"
#include "codegen.hpp"
#include "config.h"
#include "error.hpp"
#include "ir.hpp"
#include "ir_print.hpp"

View File

@@ -8,7 +8,6 @@
#include "analyze.hpp"
#include "ast_render.hpp"
#include "codegen.hpp"
#include "config.h"
#include "errmsg.hpp"
#include "error.hpp"
#include "hash_map.hpp"
@@ -9051,7 +9050,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_append_str(contents, "/// Deprecated: use `std.Target.current.cpu.arch.endian()`\n");
buf_append_str(contents, "pub const endian = Target.current.cpu.arch.endian();\n");
buf_appendf(contents, "pub const output_mode = OutputMode.Obj;\n");
buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", ZIG_LINK_MODE);
buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", ZIG_QUOTE(ZIG_LINK_MODE));
buf_appendf(contents, "pub const is_test = false;\n");
buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
@@ -9251,9 +9250,9 @@ static void init(CodeGen *g) {
g->builder = LLVMCreateBuilder();
g->dbuilder = ZigLLVMCreateDIBuilder(g->module, true);
// Don't use ZIG_VERSION_STRING here, llvm misparses it when it includes
// the git revision.
Buf *producer = buf_sprintf("zig %d.%d.%d", ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH);
// Don't use the version string here, llvm misparses it when it includes the git revision.
Stage2SemVer semver = stage2_version();
Buf *producer = buf_sprintf("zig %d.%d.%d", semver.major, semver.minor, semver.patch);
const char *flags = "";
unsigned runtime_version = 0;
@@ -9551,9 +9550,9 @@ void codegen_build_object(CodeGen *g) {
}
do_code_gen(g);
codegen_add_time_event(g, "LLVM Emit Output");
codegen_add_time_event(g, "LLVM Emit Object");
{
const char *progress_name = "LLVM Emit Output";
const char *progress_name = "LLVM Emit Object";
codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
progress_name, strlen(progress_name), 0));
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright (c) 2016 Andrew Kelley
*
* This file is part of zig, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
#ifndef ZIG_CONFIG_H
#define ZIG_CONFIG_H
#define ZIG_VERSION_MAJOR @ZIG_VERSION_MAJOR@
#define ZIG_VERSION_MINOR @ZIG_VERSION_MINOR@
#define ZIG_VERSION_PATCH @ZIG_VERSION_PATCH@
#define ZIG_VERSION_STRING "@ZIG_VERSION@"
// Used for communicating build information to self hosted build.
#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
#define ZIG_LINK_MODE "@ZIG_LINK_MODE@"
#endif

View File

@@ -7,7 +7,6 @@
#include "dump_analysis.hpp"
#include "analyze.hpp"
#include "config.h"
#include "ir.hpp"
#include "codegen.hpp"
#include "os.hpp"
@@ -1237,7 +1236,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
jw_begin_object(jw);
{
jw_object_field(jw, "zigVersion");
jw_string(jw, ZIG_VERSION_STRING);
jw_string(jw, stage2_version_string());
jw_object_field(jw, "builds");
jw_begin_array(jw);

View File

@@ -8,7 +8,6 @@
#include <new>
#include <string.h>
#include "config.h"
#include "heap.hpp"
namespace heap {

View File

@@ -8,7 +8,6 @@
#ifndef ZIG_HEAP_HPP
#define ZIG_HEAP_HPP
#include "config.h"
#include "util_base.hpp"
#include "mem.hpp"

View File

@@ -5,7 +5,6 @@
* See http://opensource.org/licenses/MIT
*/
#include "config.h"
#include "mem.hpp"
#include "heap.hpp"

View File

@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "util_base.hpp"
#include "mem_type_info.hpp"

View File

@@ -8,8 +8,6 @@
#ifndef ZIG_MEM_TYPE_INFO_HPP
#define ZIG_MEM_TYPE_INFO_HPP
#include "config.h"
namespace mem {
struct TypeInfo {

View File

@@ -156,6 +156,12 @@ struct Stage2SemVer {
uint32_t patch;
};
// ABI warning
ZIG_EXTERN_C const char *stage2_version_string(void);
// ABI warning
ZIG_EXTERN_C Stage2SemVer stage2_version(void);
// ABI warning
ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
const char *dynamic_linker);

View File

@@ -17,7 +17,9 @@
#include <intrin.h>
#endif
#include "config.h"
#define ZIG_Q(x) #x
#define ZIG_QUOTE(x) ZIG_Q(x)
#include "util_base.hpp"
#include "heap.hpp"
#include "mem.hpp"

View File

@@ -537,3 +537,11 @@ const char *stage2_add_link_lib(struct ZigStage1 *stage1,
{
return nullptr;
}
const char *stage2_version_string(void) {
return "0.0.0+zig0";
}
struct Stage2SemVer stage2_version(void) {
return {0, 0, 0};
}

View File

@@ -1,5 +1,11 @@
pub const have_llvm = true;
pub const version: []const u8 = "@ZIG_VERSION@";
pub const version: [:0]const u8 = "0.0.0+zig0";
pub const semver: @import("std").SemanticVersion = .{
.major = 0,
.minor = 0,
.patch = 0,
.build = "zig0",
};
pub const log_scopes: []const []const u8 = &[_][]const u8{};
pub const zir_dumps: []const []const u8 = &[_][]const u8{};
pub const enable_tracy = false;

View File

@@ -8,7 +8,7 @@
#ifndef ZIG_ZIG_CLANG_H
#define ZIG_ZIG_CLANG_H
#include "stage2.h"
#include "stage1/stage2.h"
#include <inttypes.h>
#include <stdbool.h>