diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-12 16:44:51 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-15 19:06:39 -0700 |
| commit | bcfebb4b2b17dcac445fc5dedbbd259cc8c2f306 (patch) | |
| tree | 48950201c23c8ccde48e2e31c91464c7e96e6163 /src/Compilation.zig | |
| parent | 429cd2b5dd27bec15a4a3351114ce1bcd12d8d01 (diff) | |
| download | zig-bcfebb4b2b17dcac445fc5dedbbd259cc8c2f306.tar.gz zig-bcfebb4b2b17dcac445fc5dedbbd259cc8c2f306.zip | |
stage2: improvements aimed at std lib integration
* AstGen: emit decl lookup ZIR instructions rather than directly
looking up decls in AstGen. This is necessary because we want to
reuse the same immutable ZIR code for multiple generic instantiations
(and comptime function calls).
* AstGen: fix using members_len instead of fields_len for struct decls.
* structs: the struct_decl ZIR instruction is now also a block. This is
so that the type expressions, default field value expressions, and
alignment expressions can be evaluated in a scope that contains the
decls from the struct namespace itself.
* Add "std" and "builtin" packages to the builtin package.
* Don't try to build glibc, musl, or mingw-w64 when using `-ofmt=c`.
* builtin.zig is generated without `usingnamespace`.
* builtin.zig takes advantage of `std.zig.fmtId` for CPU features.
* A first pass at implementing `usingnamespace`. It's problematic and
should either be deleted, or polished, before merging this branch.
* Sema: allow explicitly specifying the namespace in which to look up
Decls. This is used by `struct_decl` in order to put the decls from
the struct namespace itself in scope when evaluating the type
expressions, default value expressions, and alignment expressions.
* Module: fix `analyzeNamespace` assuming that it is the top-level root
declaration node.
* Sema: implement comptime and runtime cmp operator.
* Sema: implement peer type resolution for enums and enum literals.
* Pull in the changes from master branch:
262e09c482d98a78531c049a18b7f24146fe157f.
* ZIR: complete out simple_ptr_type debug printing
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index eaf9b7f5b4..cef24204d1 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -531,7 +531,7 @@ pub const InitOptions = struct { /// is externally modified - essentially anything other than zig-cache - then /// this flag would be set to disable this machinery to avoid false positives. disable_lld_caching: bool = false, - object_format: ?std.builtin.ObjectFormat = null, + object_format: ?std.Target.ObjectFormat = null, optimize_mode: std.builtin.Mode = .Debug, keep_source_files_loaded: bool = false, clang_argv: []const []const u8 = &[0][]const u8{}, @@ -1041,6 +1041,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { try std_pkg.add(gpa, "builtin", builtin_pkg); try std_pkg.add(gpa, "root", root_pkg); + try std_pkg.add(gpa, "std", std_pkg); + + try builtin_pkg.add(gpa, "std", std_pkg); + try builtin_pkg.add(gpa, "builtin", builtin_pkg); } // TODO when we implement serialization and deserialization of incremental @@ -2993,7 +2997,8 @@ fn wantBuildLibCFromSource(comp: Compilation) bool { .Exe => true, }; return comp.bin_file.options.link_libc and is_exe_or_dyn_lib and - comp.bin_file.options.libc_installation == null; + comp.bin_file.options.libc_installation == null and + comp.bin_file.options.object_format != .c; } fn wantBuildGLibCFromSource(comp: Compilation) bool { @@ -3017,6 +3022,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { }; return comp.bin_file.options.link_libc and is_exe_or_dyn_lib and comp.bin_file.options.libc_installation == null and + comp.bin_file.options.object_format != .c and target_util.libcNeedsLibUnwind(comp.getTarget()); } @@ -3068,26 +3074,21 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc @setEvalBranchQuota(4000); try buffer.writer().print( - \\usingnamespace @import("std").builtin; - \\/// Deprecated - \\pub const arch = Target.current.cpu.arch; - \\/// Deprecated - \\pub const endian = Target.current.cpu.arch.endian(); - \\ + \\const std = @import("std"); \\/// Zig version. When writing code that supports multiple versions of Zig, prefer \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks. - \\pub const zig_version = try @import("std").SemanticVersion.parse("{s}"); + \\pub const zig_version = try std.SemanticVersion.parse("{s}"); \\pub const zig_is_stage2 = {}; \\ - \\pub const output_mode = OutputMode.{}; - \\pub const link_mode = LinkMode.{}; + \\pub const output_mode = std.builtin.OutputMode.{}; + \\pub const link_mode = std.builtin.LinkMode.{}; \\pub const is_test = {}; \\pub const single_threaded = {}; - \\pub const abi = Abi.{}; - \\pub const cpu: Cpu = Cpu{{ + \\pub const abi = std.Target.Abi.{}; + \\pub const cpu: std.Target.Cpu = .{{ \\ .arch = .{}, - \\ .model = &Target.{}.cpu.{}, - \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{ + \\ .model = &std.Target.{}.cpu.{}, + \\ .features = std.Target.{}.featureSet(&[_]std.Target.{}.Feature{{ \\ , .{ build_options.version, @@ -3115,7 +3116,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc try buffer.writer().print( \\ }}), \\}}; - \\pub const os = Os{{ + \\pub const os = std.Target.Os{{ \\ .tag = .{}, \\ .version_range = .{{ , @@ -3202,8 +3203,13 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc (comp.bin_file.options.skip_linker_dependencies and comp.bin_file.options.parent_compilation_link_libc); try buffer.writer().print( - \\pub const object_format = ObjectFormat.{}; - \\pub const mode = Mode.{}; + \\pub const target = std.Target{{ + \\ .cpu = cpu, + \\ .os = os, + \\ .abi = abi, + \\}}; + \\pub const object_format = std.Target.ObjectFormat.{}; + \\pub const mode = std.builtin.Mode.{}; \\pub const link_libc = {}; \\pub const link_libcpp = {}; \\pub const have_error_return_tracing = {}; @@ -3211,7 +3217,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc \\pub const position_independent_code = {}; \\pub const position_independent_executable = {}; \\pub const strip_debug_info = {}; - \\pub const code_model = CodeModel.{}; + \\pub const code_model = std.builtin.CodeModel.{}; \\ , .{ std.zig.fmtId(@tagName(comp.bin_file.options.object_format)), |
