diff --git a/build.zig b/build.zig index 6cb3e35488cb..493d4e100391 100644 --- a/build.zig +++ b/build.zig @@ -35,9 +35,13 @@ pub fn build(b: *std.Build) !void { const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse deprecated_skip_install_lib_files; const skip_install_langref = b.option(bool, "no-langref", "skip copying of langref to the installation prefix") orelse skip_install_lib_files; + const docgen_module = b.createModule(.{ + .source_file = .{ .path = "doc/docgen.zig" }, + }); + const docgen_exe = b.addExecutable(.{ .name = "docgen", - .root_source_file = .{ .path = "doc/docgen.zig" }, + .main_module = docgen_module, .target = .{}, .optimize = .Debug, }); @@ -64,9 +68,12 @@ pub fn build(b: *std.Build) !void { legacy_write_to_cache.addCopyFileToSource(langref_file, "zig-cache/langref.html"); docs_step.dependOn(&legacy_write_to_cache.step); + const check_case_mod = b.createModule(.{ + .source_file = .{ .path = "test/src/Cases.zig" }, + }); const check_case_exe = b.addExecutable(.{ .name = "check-case", - .root_source_file = .{ .path = "test/src/Cases.zig" }, + .main_module = check_case_mod, .optimize = optimize, }); check_case_exe.main_pkg_path = "."; @@ -537,9 +544,12 @@ fn addCompilerStep( optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, ) *std.Build.CompileStep { + const exe_mod = b.createModule(.{ + .source_file = .{ .path = "src/main.zig" }, + }); const exe = b.addExecutable(.{ .name = "zig", - .root_source_file = .{ .path = "src/main.zig" }, + .main_module = exe_mod, .target = target, .optimize = optimize, }); diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 34806adf488f..71ea1cd6aa2e 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -20,6 +20,7 @@ const Sha256 = std.crypto.hash.sha2.Sha256; const Build = @This(); pub const Cache = @import("Build/Cache.zig"); +pub const Module = @import("Build/Module.zig"); /// deprecated: use `CompileStep`. pub const LibExeObjStep = CompileStep; @@ -448,7 +449,7 @@ pub fn addOptions(self: *Build) *OptionsStep { pub const ExecutableOptions = struct { name: []const u8, - root_source_file: ?FileSource = null, + main_module: *Module, version: ?std.builtin.Version = null, target: CrossTarget = .{}, optimize: std.builtin.Mode = .Debug, @@ -463,7 +464,7 @@ pub const ExecutableOptions = struct { pub fn addExecutable(b: *Build, options: ExecutableOptions) *CompileStep { return CompileStep.create(b, .{ .name = options.name, - .root_source_file = options.root_source_file, + .main_module = options.main_module, .version = options.version, .target = options.target, .optimize = options.optimize, @@ -479,7 +480,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *CompileStep { pub const ObjectOptions = struct { name: []const u8, - root_source_file: ?FileSource = null, + main_module: *Module, target: CrossTarget, optimize: std.builtin.Mode, max_rss: usize = 0, @@ -492,7 +493,7 @@ pub const ObjectOptions = struct { pub fn addObject(b: *Build, options: ObjectOptions) *CompileStep { return CompileStep.create(b, .{ .name = options.name, - .root_source_file = options.root_source_file, + .main_module = options.main_module, .target = options.target, .optimize = options.optimize, .kind = .obj, @@ -506,7 +507,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *CompileStep { pub const SharedLibraryOptions = struct { name: []const u8, - root_source_file: ?FileSource = null, + main_module: *Module, version: ?std.builtin.Version = null, target: CrossTarget, optimize: std.builtin.Mode, @@ -520,7 +521,7 @@ pub const SharedLibraryOptions = struct { pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *CompileStep { return CompileStep.create(b, .{ .name = options.name, - .root_source_file = options.root_source_file, + .main_module = options.main_module, .kind = .lib, .linkage = .dynamic, .version = options.version, @@ -536,7 +537,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *CompileStep { pub const StaticLibraryOptions = struct { name: []const u8, - root_source_file: ?FileSource = null, + main_module: *Module, target: CrossTarget, optimize: std.builtin.Mode, version: ?std.builtin.Version = null, @@ -550,7 +551,7 @@ pub const StaticLibraryOptions = struct { pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *CompileStep { return CompileStep.create(b, .{ .name = options.name, - .root_source_file = options.root_source_file, + .main_module = options.main_module, .kind = .lib, .linkage = .static, .version = options.version, @@ -566,7 +567,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *CompileStep { pub const TestOptions = struct { name: []const u8 = "test", - root_source_file: FileSource, + main_module: *Module, target: CrossTarget = .{}, optimize: std.builtin.Mode = .Debug, version: ?std.builtin.Version = null, @@ -583,7 +584,7 @@ pub fn addTest(b: *Build, options: TestOptions) *CompileStep { return CompileStep.create(b, .{ .name = options.name, .kind = .@"test", - .root_source_file = options.root_source_file, + .main_module = options.main_module, .target = options.target, .optimize = options.optimize, .max_rss = options.max_rss, @@ -621,18 +622,36 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *CompileStep { /// it available to other packages which depend on this one. /// `createModule` can be used instead to create a private module. pub fn addModule(b: *Build, name: []const u8, options: CreateModuleOptions) *Module { - const module = b.createModule(options); + const module = Module.create(b, name, options); b.modules.put(b.dupe(name), module) catch @panic("OOM"); return module; } +pub const CSourceFiles = struct { + files: []const []const u8, + flags: []const []const u8, +}; + +pub const CSourceFile = struct { + source: FileSource, + args: []const []const u8, + + pub fn dupe(self: CSourceFile, b: *std.Build) CSourceFile { + return .{ + .source = self.source.dupe(b), + .args = b.dupeStrings(self.args), + }; + } +}; + pub const ModuleDependency = struct { name: []const u8, module: *Module, }; pub const CreateModuleOptions = struct { - source_file: FileSource, + source_file: ?FileSource = null, + c_source_files: ?CSourceFiles = null, dependencies: []const ModuleDependency = &.{}, }; @@ -640,21 +659,7 @@ pub const CreateModuleOptions = struct { /// but not exposed to other packages depending on this one. /// `addModule` can be used instead to create a public module. pub fn createModule(b: *Build, options: CreateModuleOptions) *Module { - const module = b.allocator.create(Module) catch @panic("OOM"); - module.* = .{ - .builder = b, - .source_file = options.source_file, - .dependencies = moduleDependenciesToArrayHashMap(b.allocator, options.dependencies), - }; - return module; -} - -fn moduleDependenciesToArrayHashMap(arena: Allocator, deps: []const ModuleDependency) std.StringArrayHashMap(*Module) { - var result = std.StringArrayHashMap(*Module).init(arena); - for (deps) |dep| { - result.put(dep.name, dep.module) catch @panic("OOM"); - } - return result; + return Module.create(b, null, options); } /// Initializes a RunStep with argv, which must at least have the path to the @@ -1548,15 +1553,6 @@ pub fn runBuild(b: *Build, build_zig: anytype) anyerror!void { } } -pub const Module = struct { - builder: *Build, - /// This could either be a generated file, in which case the module - /// contains exactly one file, or it could be a path to the root source - /// file of directory of files which constitute the module. - source_file: FileSource, - dependencies: std.StringArrayHashMap(*Module), -}; - /// A file that is generated by a build step. /// This struct is an interface that is meant to be used with `@fieldParentPtr` to implement the actual path logic. pub const GeneratedFile = struct { diff --git a/lib/std/Build/CompileStep.zig b/lib/std/Build/CompileStep.zig index b71298ce6a81..d599008fffeb 100644 --- a/lib/std/Build/CompileStep.zig +++ b/lib/std/Build/CompileStep.zig @@ -24,7 +24,11 @@ const ObjCopyStep = std.Build.ObjCopyStep; const CheckObjectStep = std.Build.CheckObjectStep; const RunStep = std.Build.RunStep; const OptionsStep = std.Build.OptionsStep; +const InstallConfigHeaderOptions = Module.InstallConfigHeaderOptions; const ConfigHeaderStep = std.Build.ConfigHeaderStep; +const CSourceFile = std.Build.CSourceFile; +const LinkObject = Module.LinkObject; +const FrameworkLinkInfo = Module.FrameworkLinkInfo; const CompileStep = @This(); pub const base_id: Step.Id = .compile; @@ -46,10 +50,6 @@ strip: ?bool, unwind_tables: ?bool, // keep in sync with src/link.zig:CompressDebugSections compress_debug_sections: enum { none, zlib } = .none, -lib_paths: ArrayList(FileSource), -rpaths: ArrayList(FileSource), -framework_dirs: ArrayList(FileSource), -frameworks: StringHashMap(FrameworkLinkInfo), verbose_link: bool, verbose_cc: bool, emit_analysis: EmitOption = .default, @@ -92,20 +92,14 @@ wasi_exec_model: ?std.builtin.WasiExecModel = null, /// Symbols to be exported when compiling to wasm export_symbol_names: []const []const u8 = &.{}, -root_src: ?FileSource, out_h_filename: []const u8, out_lib_filename: []const u8, out_pdb_filename: []const u8, -modules: std.StringArrayHashMap(*Module), - -link_objects: ArrayList(LinkObject), -include_dirs: ArrayList(IncludeDir), -c_macros: ArrayList([]const u8), -installed_headers: ArrayList(*Step), -is_linking_libc: bool, -is_linking_libcpp: bool, + vcpkg_bin_path: ?[]const u8 = null, +main_module: *Module, + /// This may be set in order to override the default install directory override_dest_dir: ?InstallDir, installed_path: ?[]const u8, @@ -202,7 +196,7 @@ entry_symbol_name: ?[]const u8 = null, /// List of symbols forced as undefined in the symbol table /// thus forcing their resolution by the linker. /// Corresponds to `-u ` for ELF/MachO and `/include:` for COFF/PE. -force_undefined_symbols: std.StringHashMap(void), +force_undefined_symbols: StringHashMap(void), /// Overrides the default stack size stack_size: ?u64 = null, @@ -223,63 +217,9 @@ output_h_path_source: GeneratedFile, output_pdb_path_source: GeneratedFile, output_dirname_source: GeneratedFile, -pub const CSourceFiles = struct { - files: []const []const u8, - flags: []const []const u8, -}; - -pub const CSourceFile = struct { - source: FileSource, - args: []const []const u8, - - pub fn dupe(self: CSourceFile, b: *std.Build) CSourceFile { - return .{ - .source = self.source.dupe(b), - .args = b.dupeStrings(self.args), - }; - } -}; - -pub const LinkObject = union(enum) { - static_path: FileSource, - other_step: *CompileStep, - system_lib: SystemLib, - assembly_file: FileSource, - c_source_file: *CSourceFile, - c_source_files: *CSourceFiles, -}; - -pub const SystemLib = struct { - name: []const u8, - needed: bool, - weak: bool, - use_pkg_config: enum { - /// Don't use pkg-config, just pass -lfoo where foo is name. - no, - /// Try to get information on how to link the library from pkg-config. - /// If that fails, fall back to passing -lfoo where foo is name. - yes, - /// Try to get information on how to link the library from pkg-config. - /// If that fails, error out. - force, - }, -}; - -const FrameworkLinkInfo = struct { - needed: bool = false, - weak: bool = false, -}; - -pub const IncludeDir = union(enum) { - raw_path: []const u8, - raw_path_system: []const u8, - other_step: *CompileStep, - config_header_step: *ConfigHeaderStep, -}; - pub const Options = struct { name: []const u8, - root_source_file: ?FileSource = null, + main_module: *Module, target: CrossTarget, optimize: std.builtin.Mode, kind: Kind, @@ -294,6 +234,8 @@ pub const Options = struct { use_lld: ?bool = null, }; +pub const Linkage = enum { dynamic, static }; + pub const Kind = enum { exe, lib, @@ -301,8 +243,6 @@ pub const Kind = enum { @"test", }; -pub const Linkage = enum { dynamic, static }; - pub const EmitOption = union(enum) { default: void, no_emit: void, @@ -321,7 +261,6 @@ pub const EmitOption = union(enum) { pub fn create(owner: *std.Build, options: Options) *CompileStep { const name = owner.dupe(options.name); - const root_src: ?FileSource = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null; if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); } @@ -371,9 +310,8 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { .target = options.target, .linkage = options.linkage, .kind = options.kind, - .root_src = root_src, + .main_module = options.main_module, .name = name, - .frameworks = StringHashMap(FrameworkLinkInfo).init(owner.allocator), .step = Step.init(.{ .id = base_id, .name = step_name, @@ -388,14 +326,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { .out_pdb_filename = owner.fmt("{s}.pdb", .{name}), .major_only_filename = null, .name_only_filename = null, - .modules = std.StringArrayHashMap(*Module).init(owner.allocator), - .include_dirs = ArrayList(IncludeDir).init(owner.allocator), - .link_objects = ArrayList(LinkObject).init(owner.allocator), - .c_macros = ArrayList([]const u8).init(owner.allocator), - .lib_paths = ArrayList(FileSource).init(owner.allocator), - .rpaths = ArrayList(FileSource).init(owner.allocator), - .framework_dirs = ArrayList(FileSource).init(owner.allocator), - .installed_headers = ArrayList(*Step).init(owner.allocator), .c_std = std.Build.CStd.C99, .zig_lib_dir = null, .main_pkg_path = null, @@ -418,8 +348,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { .target_info = target_info, - .is_linking_libc = options.link_libc orelse false, - .is_linking_libcpp = false, .single_threaded = options.single_threaded, .use_llvm = options.use_llvm, .use_lld = options.use_lld, @@ -454,85 +382,11 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { } } - if (root_src) |rs| rs.addStepDependencies(&self.step); + self.step.dependOn(&self.main_module.step); return self; } -pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void { - const b = cs.step.owner; - const install_file = b.addInstallHeaderFile(src_path, dest_rel_path); - b.getInstallStep().dependOn(&install_file.step); - cs.installed_headers.append(&install_file.step) catch @panic("OOM"); -} - -pub const InstallConfigHeaderOptions = struct { - install_dir: InstallDir = .header, - dest_rel_path: ?[]const u8 = null, -}; - -pub fn installConfigHeader( - cs: *CompileStep, - config_header: *ConfigHeaderStep, - options: InstallConfigHeaderOptions, -) void { - const dest_rel_path = options.dest_rel_path orelse config_header.include_path; - const b = cs.step.owner; - const install_file = b.addInstallFileWithDir( - .{ .generated = &config_header.output_file }, - options.install_dir, - dest_rel_path, - ); - install_file.step.dependOn(&config_header.step); - b.getInstallStep().dependOn(&install_file.step); - cs.installed_headers.append(&install_file.step) catch @panic("OOM"); -} - -pub fn installHeadersDirectory( - a: *CompileStep, - src_dir_path: []const u8, - dest_rel_path: []const u8, -) void { - return installHeadersDirectoryOptions(a, .{ - .source_dir = src_dir_path, - .install_dir = .header, - .install_subdir = dest_rel_path, - }); -} - -pub fn installHeadersDirectoryOptions( - cs: *CompileStep, - options: std.Build.InstallDirStep.Options, -) void { - const b = cs.step.owner; - const install_dir = b.addInstallDirectory(options); - b.getInstallStep().dependOn(&install_dir.step); - cs.installed_headers.append(&install_dir.step) catch @panic("OOM"); -} - -pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void { - assert(l.kind == .lib); - const b = cs.step.owner; - const install_step = b.getInstallStep(); - // Copy each element from installed_headers, modifying the builder - // to be the new parent's builder. - for (l.installed_headers.items) |step| { - const step_copy = switch (step.id) { - inline .install_file, .install_dir => |id| blk: { - const T = id.Type(); - const ptr = b.allocator.create(T) catch @panic("OOM"); - ptr.* = step.cast(T).?.*; - ptr.dest_builder = b; - break :blk &ptr.step; - }, - else => unreachable, - }; - cs.installed_headers.append(step_copy) catch @panic("OOM"); - install_step.dependOn(step_copy); - } - cs.installed_headers.appendSlice(l.installed_headers.items) catch @panic("OOM"); -} - pub fn addObjCopy(cs: *CompileStep, options: ObjCopyStep.Options) *ObjCopyStep { const b = cs.step.owner; var copy = options; @@ -569,47 +423,6 @@ pub fn forceUndefinedSymbol(self: *CompileStep, symbol_name: []const u8) void { self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM"); } -pub fn linkFramework(self: *CompileStep, framework_name: []const u8) void { - const b = self.step.owner; - self.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM"); -} - -pub fn linkFrameworkNeeded(self: *CompileStep, framework_name: []const u8) void { - const b = self.step.owner; - self.frameworks.put(b.dupe(framework_name), .{ - .needed = true, - }) catch @panic("OOM"); -} - -pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void { - const b = self.step.owner; - self.frameworks.put(b.dupe(framework_name), .{ - .weak = true, - }) catch @panic("OOM"); -} - -/// Returns whether the library, executable, or object depends on a particular system library. -pub fn dependsOnSystemLibrary(self: CompileStep, name: []const u8) bool { - if (isLibCLibrary(name)) { - return self.is_linking_libc; - } - if (isLibCppLibrary(name)) { - return self.is_linking_libcpp; - } - for (self.link_objects.items) |link_object| { - switch (link_object) { - .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, - else => continue, - } - } - return false; -} - -pub fn linkLibrary(self: *CompileStep, lib: *CompileStep) void { - assert(lib.kind == .lib); - self.linkLibraryOrObject(lib); -} - pub fn isDynamicLibrary(self: *CompileStep) bool { return self.kind == .lib and self.linkage == Linkage.dynamic; } @@ -625,101 +438,9 @@ pub fn producesPdbFile(self: *CompileStep) bool { return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; } -pub fn linkLibC(self: *CompileStep) void { - self.is_linking_libc = true; -} - -pub fn linkLibCpp(self: *CompileStep) void { - self.is_linking_libcpp = true; -} - -/// If the value is omitted, it is set to 1. -/// `name` and `value` need not live longer than the function call. -pub fn defineCMacro(self: *CompileStep, name: []const u8, value: ?[]const u8) void { - const b = self.step.owner; - const macro = std.Build.constructCMacro(b.allocator, name, value); - self.c_macros.append(macro) catch @panic("OOM"); -} - -/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. -pub fn defineCMacroRaw(self: *CompileStep, name_and_value: []const u8) void { - const b = self.step.owner; - self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); -} - -/// This one has no integration with anything, it just puts -lname on the command line. -/// Prefer to use `linkSystemLibrary` instead. -pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void { - const b = self.step.owner; - self.link_objects.append(.{ - .system_lib = .{ - .name = b.dupe(name), - .needed = false, - .weak = false, - .use_pkg_config = .no, - }, - }) catch @panic("OOM"); -} - -/// This one has no integration with anything, it just puts -needed-lname on the command line. -/// Prefer to use `linkSystemLibraryNeeded` instead. -pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void { - const b = self.step.owner; - self.link_objects.append(.{ - .system_lib = .{ - .name = b.dupe(name), - .needed = true, - .weak = false, - .use_pkg_config = .no, - }, - }) catch @panic("OOM"); -} - -/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the -/// command line. Prefer to use `linkSystemLibraryWeak` instead. -pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void { - const b = self.step.owner; - self.link_objects.append(.{ - .system_lib = .{ - .name = b.dupe(name), - .needed = false, - .weak = true, - .use_pkg_config = .no, - }, - }) catch @panic("OOM"); -} - -/// This links against a system library, exclusively using pkg-config to find the library. -/// Prefer to use `linkSystemLibrary` instead. -pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8) void { - const b = self.step.owner; - self.link_objects.append(.{ - .system_lib = .{ - .name = b.dupe(lib_name), - .needed = false, - .weak = false, - .use_pkg_config = .force, - }, - }) catch @panic("OOM"); -} - -/// This links against a system library, exclusively using pkg-config to find the library. -/// Prefer to use `linkSystemLibraryNeeded` instead. -pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []const u8) void { - const b = self.step.owner; - self.link_objects.append(.{ - .system_lib = .{ - .name = b.dupe(lib_name), - .needed = true, - .weak = false, - .use_pkg_config = .force, - }, - }) catch @panic("OOM"); -} - /// Run pkg-config for the given library name and parse the output, returning the arguments /// that should be passed to zig to link the given library. -fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 { +pub fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 { const b = self.step.owner; const pkg_name = match: { // First we have to map the library name to pkg config name. Unfortunately, @@ -813,72 +534,6 @@ fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 { return zig_args.toOwnedSlice(); } -pub fn linkSystemLibrary(self: *CompileStep, name: []const u8) void { - self.linkSystemLibraryInner(name, .{}); -} - -pub fn linkSystemLibraryNeeded(self: *CompileStep, name: []const u8) void { - self.linkSystemLibraryInner(name, .{ .needed = true }); -} - -pub fn linkSystemLibraryWeak(self: *CompileStep, name: []const u8) void { - self.linkSystemLibraryInner(name, .{ .weak = true }); -} - -fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct { - needed: bool = false, - weak: bool = false, -}) void { - const b = self.step.owner; - if (isLibCLibrary(name)) { - self.linkLibC(); - return; - } - if (isLibCppLibrary(name)) { - self.linkLibCpp(); - return; - } - - self.link_objects.append(.{ - .system_lib = .{ - .name = b.dupe(name), - .needed = opts.needed, - .weak = opts.weak, - .use_pkg_config = .yes, - }, - }) catch @panic("OOM"); -} - -/// Handy when you have many C/C++ source files and want them all to have the same flags. -pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void { - const b = self.step.owner; - const c_source_files = b.allocator.create(CSourceFiles) catch @panic("OOM"); - - const files_copy = b.dupeStrings(files); - const flags_copy = b.dupeStrings(flags); - - c_source_files.* = .{ - .files = files_copy, - .flags = flags_copy, - }; - self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM"); -} - -pub fn addCSourceFile(self: *CompileStep, file: []const u8, flags: []const []const u8) void { - self.addCSourceFileSource(.{ - .args = flags, - .source = .{ .path = file }, - }); -} - -pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void { - const b = self.step.owner; - const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM"); - c_source_file.* = source.dupe(b); - self.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM"); - source.source.addStepDependencies(&self.step); -} - pub fn setVerboseLink(self: *CompileStep, value: bool) void { self.verbose_link = value; } @@ -933,180 +588,245 @@ pub fn getOutputPdbSource(self: *CompileStep) FileSource { return .{ .generated = &self.output_pdb_path_source }; } -pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void { +/// If Vcpkg was found on the system, it will be added to include and lib +/// paths for the specified target. +pub fn addVcpkgPaths(self: *CompileStep, linkage: Linkage) !void { const b = self.step.owner; - self.link_objects.append(.{ - .assembly_file = .{ .path = b.dupe(path) }, - }) catch @panic("OOM"); + // Ideally in the Unattempted case we would call the function recursively + // after findVcpkgRoot and have only one switch statement, but the compiler + // cannot resolve the error set. + switch (b.vcpkg_root) { + .unattempted => { + b.vcpkg_root = if (try findVcpkgRoot(b.allocator)) |root| + VcpkgRoot{ .found = root } + else + .not_found; + }, + .not_found => return error.VcpkgNotFound, + .found => {}, + } + + switch (b.vcpkg_root) { + .unattempted => unreachable, + .not_found => return error.VcpkgNotFound, + .found => |root| { + const allocator = b.allocator; + const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic); + defer b.allocator.free(triplet); + + const include_path = b.pathJoin(&.{ root, "installed", triplet, "include" }); + errdefer allocator.free(include_path); + try self.main_module.include_dirs.append(Module.IncludeDir{ .raw_path = include_path }); + + const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); + try self.main_module.lib_paths.append(.{ .path = lib_path }); + + self.vcpkg_bin_path = b.pathJoin(&.{ root, "installed", triplet, "bin" }); + }, + } } -pub fn addAssemblyFileSource(self: *CompileStep, source: FileSource) void { +pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void { const b = self.step.owner; - const source_duped = source.dupe(b); - self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM"); - source_duped.addStepDependencies(&self.step); + assert(self.kind == .@"test"); + const duped_args = b.allocator.alloc(?[]u8, args.len) catch @panic("OOM"); + for (args, 0..) |arg, i| { + duped_args[i] = if (arg) |a| b.dupe(a) else null; + } + self.exec_cmd_args = duped_args; } -pub fn addObjectFile(self: *CompileStep, source_file: []const u8) void { - self.addObjectFileSource(.{ .path = source_file }); +pub fn addOptions(self: *CompileStep, name: []const u8, options: *OptionsStep) void { + self.main_module.addOptions(name, options); } -pub fn addObjectFileSource(self: *CompileStep, source: FileSource) void { - const b = self.step.owner; - self.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM"); - source.addStepDependencies(&self.step); +pub fn linkLibC(self: *CompileStep) void { + self.main_module.linkLibC(); } -pub fn addObject(self: *CompileStep, obj: *CompileStep) void { - assert(obj.kind == .obj); - self.linkLibraryOrObject(obj); +pub fn linkLibCpp(self: *CompileStep) void { + self.main_module.linkLibCpp(); } -pub const addSystemIncludeDir = @compileError("deprecated; use addSystemIncludePath"); -pub const addIncludeDir = @compileError("deprecated; use addIncludePath"); -pub const addLibPath = @compileError("deprecated, use addLibraryPath"); -pub const addFrameworkDir = @compileError("deprecated, use addFrameworkPath"); +/// This one has no integration with anything, it just puts -lname on the command line. +/// Prefer to use `linkSystemLibrary` instead. +pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void { + self.main_module.linkSystemLibraryName(name); +} -pub fn addSystemIncludePath(self: *CompileStep, path: []const u8) void { - const b = self.step.owner; - self.include_dirs.append(IncludeDir{ .raw_path_system = b.dupe(path) }) catch @panic("OOM"); +/// This one has no integration with anything, it just puts -needed-lname on the command line. +/// Prefer to use `linkSystemLibraryNeeded` instead. +pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void { + self.main_module.linkSystemLibraryNeededName(name); } -pub fn addIncludePath(self: *CompileStep, path: []const u8) void { - const b = self.step.owner; - self.include_dirs.append(IncludeDir{ .raw_path = b.dupe(path) }) catch @panic("OOM"); +/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the +/// command line. Prefer to use `linkSystemLibraryWeak` instead. +pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void { + self.main_module.linkSystemLibraryWeakName(name); } -pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) void { - self.step.dependOn(&config_header.step); - self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM"); +/// This links against a system library, exclusively using pkg-config to find the library. +/// Prefer to use `linkSystemLibrary` instead. +pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8) void { + self.main_module.linkSystemLibraryPkgConfigOnly(lib_name); } -pub fn addLibraryPath(self: *CompileStep, path: []const u8) void { - const b = self.step.owner; - self.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM"); +/// This links against a system library, exclusively using pkg-config to find the library. +/// Prefer to use `linkSystemLibraryNeeded` instead. +pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []const u8) void { + self.main_module.linkSystemLibraryNeededPkgConfigOnly(lib_name); } -pub fn addLibraryPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { - self.lib_paths.append(directory_source) catch @panic("OOM"); - directory_source.addStepDependencies(&self.step); +/// Handy when you have many C/C++ source files and want them all to have the same flags. +pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void { + self.main_module.addCSourceFiles(files, flags); } -pub fn addRPath(self: *CompileStep, path: []const u8) void { - const b = self.step.owner; - self.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM"); +pub fn addCSourceFile(self: *CompileStep, file: []const u8, flags: []const []const u8) void { + self.main_module.addCSourceFile(file, flags); } -pub fn addRPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { - self.rpaths.append(directory_source) catch @panic("OOM"); - directory_source.addStepDependencies(&self.step); +pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void { + self.main_module.addCSourceFileSource(source); } -pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void { - const b = self.step.owner; - self.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM"); +pub fn installHeader(self: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void { + self.main_module.installHeader(src_path, dest_rel_path); } -pub fn addFrameworkPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { - self.framework_dirs.append(directory_source) catch @panic("OOM"); - directory_source.addStepDependencies(&self.step); +pub fn installConfigHeader( + self: *CompileStep, + config_header: *ConfigHeaderStep, + options: InstallConfigHeaderOptions, +) void { + self.main_module.installConfigHeader(config_header, options); } -/// Adds a module to be used with `@import` and exposing it in the current -/// package's module table using `name`. -pub fn addModule(cs: *CompileStep, name: []const u8, module: *Module) void { - const b = cs.step.owner; - cs.modules.put(b.dupe(name), module) catch @panic("OOM"); +pub fn installHeadersDirectory( + self: *CompileStep, + src_dir_path: []const u8, + dest_rel_path: []const u8, +) void { + self.main_module.installHeadersDirectory(src_dir_path, dest_rel_path); +} - var done = std.AutoHashMap(*Module, void).init(b.allocator); - defer done.deinit(); - cs.addRecursiveBuildDeps(module, &done) catch @panic("OOM"); +pub fn installHeadersDirectoryOptions( + self: *CompileStep, + options: std.Build.InstallDirStep.Options, +) void { + self.main_module.installHeadersDirectoryOptions(options); } -/// Adds a module to be used with `@import` without exposing it in the current -/// package's module table. -pub fn addAnonymousModule(cs: *CompileStep, name: []const u8, options: std.Build.CreateModuleOptions) void { - const b = cs.step.owner; - const module = b.createModule(options); - return addModule(cs, name, module); +pub fn installLibraryHeaders(self: *CompileStep, l: *CompileStep) void { + self.main_module.installLibraryHeaders(l); } -pub fn addOptions(cs: *CompileStep, module_name: []const u8, options: *OptionsStep) void { - addModule(cs, module_name, options.createModule()); +/// If the value is omitted, it is set to 1. +/// `name` and `value` need not live longer than the function call. +pub fn defineCMacro(self: *CompileStep, name: []const u8, value: ?[]const u8) void { + self.main_module.defineCMacro(name, value); } -fn addRecursiveBuildDeps(cs: *CompileStep, module: *Module, done: *std.AutoHashMap(*Module, void)) !void { - if (done.contains(module)) return; - try done.put(module, {}); - module.source_file.addStepDependencies(&cs.step); - for (module.dependencies.values()) |dep| { - try cs.addRecursiveBuildDeps(dep, done); - } +/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. +pub fn defineCMacroRaw(self: *CompileStep, name_and_value: []const u8) void { + self.main_module.defineCMacroRaw(name_and_value); } -/// If Vcpkg was found on the system, it will be added to include and lib -/// paths for the specified target. -pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void { - const b = self.step.owner; - // Ideally in the Unattempted case we would call the function recursively - // after findVcpkgRoot and have only one switch statement, but the compiler - // cannot resolve the error set. - switch (b.vcpkg_root) { - .unattempted => { - b.vcpkg_root = if (try findVcpkgRoot(b.allocator)) |root| - VcpkgRoot{ .found = root } - else - .not_found; - }, - .not_found => return error.VcpkgNotFound, - .found => {}, - } +pub fn linkLibrary(self: *CompileStep, lib: *CompileStep) void { + self.main_module.linkLibrary(lib); +} - switch (b.vcpkg_root) { - .unattempted => unreachable, - .not_found => return error.VcpkgNotFound, - .found => |root| { - const allocator = b.allocator; - const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic); - defer b.allocator.free(triplet); +pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void { + self.main_module.addAssemblyFile(path); +} - const include_path = b.pathJoin(&.{ root, "installed", triplet, "include" }); - errdefer allocator.free(include_path); - try self.include_dirs.append(IncludeDir{ .raw_path = include_path }); +pub fn addAssemblyFileSource(self: *CompileStep, source: FileSource) void { + self.main_module.addAssemblyFileSource(source); +} - const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); - try self.lib_paths.append(.{ .path = lib_path }); +pub fn addObjectFile(self: *CompileStep, source_file: []const u8) void { + self.main_module.addObjectFile(source_file); +} - self.vcpkg_bin_path = b.pathJoin(&.{ root, "installed", triplet, "bin" }); - }, - } +pub fn addObjectFileSource(self: *CompileStep, source: FileSource) void { + self.main_module.addObjectFileSource(source); } -pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void { - const b = self.step.owner; - assert(self.kind == .@"test"); - const duped_args = b.allocator.alloc(?[]u8, args.len) catch @panic("OOM"); - for (args, 0..) |arg, i| { - duped_args[i] = if (arg) |a| b.dupe(a) else null; - } - self.exec_cmd_args = duped_args; +pub fn addObject(self: *CompileStep, obj: *CompileStep) void { + self.main_module.addObject(obj); } -fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void { - self.step.dependOn(&other.step); - self.link_objects.append(.{ .other_step = other }) catch @panic("OOM"); - self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM"); +pub fn linkSystemLibrary(self: *CompileStep, name: []const u8) void { + self.main_module.linkSystemLibrary(name); +} - for (other.installed_headers.items) |install_step| { - self.step.dependOn(install_step); - } +pub fn linkSystemLibraryNeeded(self: *CompileStep, name: []const u8) void { + self.main_module.linkSystemLibraryNeeded(name); +} + +pub fn linkSystemLibraryWeak(self: *CompileStep, name: []const u8) void { + self.main_module.linkSystemLibraryWeak(name); +} + +/// Returns whether the module depends on a particular system library. +pub fn dependsOnSystemLibrary(self: CompileStep, name: []const u8) bool { + self.main_module.dependsOnSystemLibrary(name); +} + +pub fn linkFramework(self: *CompileStep, framework_name: []const u8) void { + self.main_module.linkFramework(framework_name); +} + +pub fn linkFrameworkNeeded(self: *CompileStep, framework_name: []const u8) void { + self.main_module.linkFrameworkNeeded(framework_name); +} + +pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void { + self.main_module.linkFrameworkWeak(framework_name); +} + +pub fn addSystemIncludePath(self: *CompileStep, path: []const u8) void { + self.main_module.addSystemIncludePath(path); +} + +pub fn addIncludePath(self: *CompileStep, path: []const u8) void { + self.main_module.addIncludePath(path); +} + +pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) void { + self.main_module.addConfigHeader(config_header); +} + +pub fn addLibraryPath(self: *CompileStep, path: []const u8) void { + self.main_module.addLibraryPath(path); +} + +pub fn addLibraryPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { + self.main_module.addLibraryPathDirectorySource(directory_source); +} + +pub fn addRPath(self: *CompileStep, path: []const u8) void { + self.main_module.addRPath(path); } -fn appendModuleArgs( - cs: *CompileStep, +pub fn addRPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { + self.main_module.addRPathDirectorySource(directory_source); +} + +pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void { + self.main_module.addFrameworkPath(dir_path); +} + +pub fn addFrameworkPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { + self.main_module.addFrameworkPathDirectorySource(directory_source); +} + +pub fn appendModuleArgs( + self: *CompileStep, zig_args: *ArrayList([]const u8), -) error{OutOfMemory}!void { - const b = cs.step.owner; +) !void { + const b = self.step.owner; // First, traverse the whole dependency graph and give every module a unique name, ideally one // named after what it's called somewhere in the graph. It will help here to have both a mapping // from module to name and a set of all the currently-used names. @@ -1117,21 +837,15 @@ fn appendModuleArgs( name: []const u8, mod: *Module, }).init(b.allocator); - { - var it = cs.modules.iterator(); - while (it.next()) |kv| { - // While we're traversing the root dependencies, let's make sure that no module names - // have colons in them, since the CLI forbids it. We handle this for transitive - // dependencies further down. - if (std.mem.indexOfScalar(u8, kv.key_ptr.*, ':') != null) { - @panic("Module names cannot contain colons"); - } - try to_name.append(.{ - .name = kv.key_ptr.*, - .mod = kv.value_ptr.*, - }); - } - } + // Make sure that the main module name does not have colons in it, since the CLI forbids it. + // We handle this for transitive dependencies further down. + if (std.mem.indexOfScalar(u8, self.name, ':') != null) { + @panic("Module names cannot contain colons"); + } + try to_name.append(.{ + .name = self.name, + .mod = self.main_module, + }); while (to_name.popOrNull()) |dep| { if (mod_names.contains(dep.mod)) continue; @@ -1164,6 +878,9 @@ fn appendModuleArgs( } } + try zig_args.append("--main-mod"); + try zig_args.append(self.name); + // Since the module names given to the CLI are based off of the exposed names, we already know // that none of the CLI names have colons in them, so there's no need to check that explicitly. @@ -1174,18 +891,27 @@ fn appendModuleArgs( const mod = kv.key_ptr.*; const name = kv.value_ptr.*; - const deps_str = try constructDepString(b.allocator, mod_names, mod.dependencies); - const src = mod.builder.pathFromRoot(mod.source_file.getPath(mod.builder)); try zig_args.append("--mod"); - try zig_args.append(try std.fmt.allocPrint(b.allocator, "{s}:{s}:{s}", .{ name, deps_str, src })); - } - } + try zig_args.append(name); - // Lastly, output the root dependencies - const deps_str = try constructDepString(b.allocator, mod_names, cs.modules); - if (deps_str.len > 0) { - try zig_args.append("--deps"); - try zig_args.append(deps_str); + if (mod.source_file) |rs| { + try zig_args.append("--root-source"); + try zig_args.append(rs.getPath2(b, &self.step)); + } + + const deps_str = try constructDepString(b.allocator, mod_names, mod.dependencies); + if (deps_str.len > 0) { + try zig_args.append("--deps"); + try zig_args.append(deps_str); + } + + const args_str = try mod.constructArgsString(self); + if (args_str.len > 0) { + try zig_args.append("--args"); + try zig_args.appendSlice(args_str); + try zig_args.append("--args-end"); + } + } } } @@ -1193,7 +919,7 @@ fn constructDepString( allocator: std.mem.Allocator, mod_names: std.AutoHashMap(*Module, []const u8), deps: std.StringArrayHashMap(*Module), -) ![]const u8 { +) error{OutOfMemory}![]const u8 { var deps_str = std.ArrayList(u8).init(allocator); var it = deps.iterator(); while (it.next()) |kv| { @@ -1216,10 +942,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { const b = step.owner; const self = @fieldParentPtr(CompileStep, "step", step); - if (self.root_src == null and self.link_objects.items.len == 0) { - return step.fail("the linker needs one or more objects to link", .{}); - } - var zig_args = ArrayList([]const u8).init(b.allocator); defer zig_args.deinit(); @@ -1262,146 +984,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { try zig_args.append(try std.fmt.allocPrint(b.allocator, "{}", .{stack_size})); } - if (self.root_src) |root_src| try zig_args.append(root_src.getPath(b)); - - // We will add link objects from transitive dependencies, but we want to keep - // all link objects in the same order provided. - // This array is used to keep self.link_objects immutable. - var transitive_deps: TransitiveDeps = .{ - .link_objects = ArrayList(LinkObject).init(b.allocator), - .seen_system_libs = StringHashMap(void).init(b.allocator), - .seen_steps = std.AutoHashMap(*const Step, void).init(b.allocator), - .is_linking_libcpp = self.is_linking_libcpp, - .is_linking_libc = self.is_linking_libc, - .frameworks = &self.frameworks, - }; - - try transitive_deps.seen_steps.put(&self.step, {}); - try transitive_deps.add(self.link_objects.items); - - var prev_has_extra_flags = false; - - for (transitive_deps.link_objects.items) |link_object| { - switch (link_object) { - .static_path => |static_path| try zig_args.append(static_path.getPath(b)), - - .other_step => |other| switch (other.kind) { - .exe => @panic("Cannot link with an executable build artifact"), - .@"test" => @panic("Cannot link with a test"), - .obj => { - try zig_args.append(other.getOutputSource().getPath(b)); - }, - .lib => l: { - if (self.isStaticLibrary() and other.isStaticLibrary()) { - // Avoid putting a static library inside a static library. - break :l; - } - - const full_path_lib = other.getOutputLibSource().getPath(b); - try zig_args.append(full_path_lib); - - if (other.linkage == Linkage.dynamic and !self.target.isWindows()) { - if (fs.path.dirname(full_path_lib)) |dirname| { - try zig_args.append("-rpath"); - try zig_args.append(dirname); - } - } - }, - }, - - .system_lib => |system_lib| { - const prefix: []const u8 = prefix: { - if (system_lib.needed) break :prefix "-needed-l"; - if (system_lib.weak) break :prefix "-weak-l"; - break :prefix "-l"; - }; - switch (system_lib.use_pkg_config) { - .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), - .yes, .force => { - if (self.runPkgConfig(system_lib.name)) |args| { - try zig_args.appendSlice(args); - } else |err| switch (err) { - error.PkgConfigInvalidOutput, - error.PkgConfigCrashed, - error.PkgConfigFailed, - error.PkgConfigNotInstalled, - error.PackageNotFound, - => switch (system_lib.use_pkg_config) { - .yes => { - // pkg-config failed, so fall back to linking the library - // by name directly. - try zig_args.append(b.fmt("{s}{s}", .{ - prefix, - system_lib.name, - })); - }, - .force => { - panic("pkg-config failed for library {s}", .{system_lib.name}); - }, - .no => unreachable, - }, - - else => |e| return e, - } - }, - } - }, - - .assembly_file => |asm_file| { - if (prev_has_extra_flags) { - try zig_args.append("-extra-cflags"); - try zig_args.append("--"); - prev_has_extra_flags = false; - } - try zig_args.append(asm_file.getPath(b)); - }, - - .c_source_file => |c_source_file| { - if (c_source_file.args.len == 0) { - if (prev_has_extra_flags) { - try zig_args.append("-cflags"); - try zig_args.append("--"); - prev_has_extra_flags = false; - } - } else { - try zig_args.append("-cflags"); - for (c_source_file.args) |arg| { - try zig_args.append(arg); - } - try zig_args.append("--"); - } - try zig_args.append(c_source_file.source.getPath(b)); - }, - - .c_source_files => |c_source_files| { - if (c_source_files.flags.len == 0) { - if (prev_has_extra_flags) { - try zig_args.append("-cflags"); - try zig_args.append("--"); - prev_has_extra_flags = false; - } - } else { - try zig_args.append("-cflags"); - for (c_source_files.flags) |flag| { - try zig_args.append(flag); - } - try zig_args.append("--"); - } - for (c_source_files.files) |file| { - try zig_args.append(b.pathFromRoot(file)); - } - }, - } - } - - if (transitive_deps.is_linking_libcpp) { - try zig_args.append("-lc++"); - } - - if (transitive_deps.is_linking_libc) { - try zig_args.append("-lc"); - } - if (self.image_base) |image_base| { try zig_args.append("--image-base"); try zig_args.append(b.fmt("0x{x}", .{image_base})); @@ -1521,9 +1103,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { try zig_args.append("--global-cache-dir"); try zig_args.append(b.global_cache_root.path orelse "."); - try zig_args.append("--name"); - try zig_args.append(self.name); - if (self.linkage) |some| switch (some) { .dynamic => try zig_args.append("-dynamic"), .static => try zig_args.append("-static"), @@ -1665,116 +1244,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { try self.appendModuleArgs(&zig_args); - for (self.include_dirs.items) |include_dir| { - switch (include_dir) { - .raw_path => |include_path| { - try zig_args.append("-I"); - try zig_args.append(b.pathFromRoot(include_path)); - }, - .raw_path_system => |include_path| { - if (b.sysroot != null) { - try zig_args.append("-iwithsysroot"); - } else { - try zig_args.append("-isystem"); - } - - const resolved_include_path = b.pathFromRoot(include_path); - - const common_include_path = if (builtin.os.tag == .windows and b.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: { - // We need to check for disk designator and strip it out from dir path so - // that zig/clang can concat resolved_include_path with sysroot. - const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path); - - if (mem.indexOf(u8, resolved_include_path, disk_designator)) |where| { - break :blk resolved_include_path[where + disk_designator.len ..]; - } - - break :blk resolved_include_path; - } else resolved_include_path; - - try zig_args.append(common_include_path); - }, - .other_step => |other| { - if (other.emit_h) { - const h_path = other.getOutputHSource().getPath(b); - try zig_args.append("-isystem"); - try zig_args.append(fs.path.dirname(h_path).?); - } - if (other.installed_headers.items.len > 0) { - try zig_args.append("-I"); - try zig_args.append(b.pathJoin(&.{ - other.step.owner.install_prefix, "include", - })); - } - }, - .config_header_step => |config_header| { - const full_file_path = config_header.output_file.path.?; - const header_dir_path = full_file_path[0 .. full_file_path.len - config_header.include_path.len]; - try zig_args.appendSlice(&.{ "-I", header_dir_path }); - }, - } - } - - for (self.c_macros.items) |c_macro| { - try zig_args.append("-D"); - try zig_args.append(c_macro); - } - - try zig_args.ensureUnusedCapacity(2 * self.lib_paths.items.len); - for (self.lib_paths.items) |lib_path| { - zig_args.appendAssumeCapacity("-L"); - zig_args.appendAssumeCapacity(lib_path.getPath2(b, step)); - } - - try zig_args.ensureUnusedCapacity(2 * self.rpaths.items.len); - for (self.rpaths.items) |rpath| { - zig_args.appendAssumeCapacity("-rpath"); - - if (self.target_info.target.isDarwin()) switch (rpath) { - .path => |path| { - // On Darwin, we should not try to expand special runtime paths such as - // * @executable_path - // * @loader_path - if (mem.startsWith(u8, path, "@executable_path") or - mem.startsWith(u8, path, "@loader_path")) - { - zig_args.appendAssumeCapacity(path); - continue; - } - }, - .generated => {}, - }; - - zig_args.appendAssumeCapacity(rpath.getPath2(b, step)); - } - - for (self.framework_dirs.items) |directory_source| { - if (b.sysroot != null) { - try zig_args.append("-iframeworkwithsysroot"); - } else { - try zig_args.append("-iframework"); - } - try zig_args.append(directory_source.getPath2(b, step)); - try zig_args.append("-F"); - try zig_args.append(directory_source.getPath2(b, step)); - } - - { - var it = self.frameworks.iterator(); - while (it.next()) |entry| { - const name = entry.key_ptr.*; - const info = entry.value_ptr.*; - if (info.needed) { - try zig_args.append("-needed_framework"); - } else if (info.weak) { - try zig_args.append("-weak_framework"); - } else { - try zig_args.append("-framework"); - } - try zig_args.append(name); - } - } - if (b.sysroot) |sysroot| { try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot }); } @@ -1957,24 +1426,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { } } -fn isLibCLibrary(name: []const u8) bool { - const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" }; - for (libc_libraries) |libc_lib_name| { - if (mem.eql(u8, name, libc_lib_name)) - return true; - } - return false; -} - -fn isLibCppLibrary(name: []const u8) bool { - const libcpp_libraries = [_][]const u8{ "c++", "stdc++" }; - for (libcpp_libraries) |libcpp_lib_name| { - if (mem.eql(u8, name, libcpp_lib_name)) - return true; - } - return false; -} - /// Returned slice must be freed by the caller. fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); @@ -2068,66 +1519,6 @@ fn addFlag(args: *ArrayList([]const u8), comptime name: []const u8, opt: ?bool) } } -const TransitiveDeps = struct { - link_objects: ArrayList(LinkObject), - seen_system_libs: StringHashMap(void), - seen_steps: std.AutoHashMap(*const Step, void), - is_linking_libcpp: bool, - is_linking_libc: bool, - frameworks: *StringHashMap(FrameworkLinkInfo), - - fn add(td: *TransitiveDeps, link_objects: []const LinkObject) !void { - try td.link_objects.ensureUnusedCapacity(link_objects.len); - - for (link_objects) |link_object| { - try td.link_objects.append(link_object); - switch (link_object) { - .other_step => |other| try addInner(td, other, other.isDynamicLibrary()), - else => {}, - } - } - } - - fn addInner(td: *TransitiveDeps, other: *CompileStep, dyn: bool) !void { - // Inherit dependency on libc and libc++ - td.is_linking_libcpp = td.is_linking_libcpp or other.is_linking_libcpp; - td.is_linking_libc = td.is_linking_libc or other.is_linking_libc; - - // Inherit dependencies on darwin frameworks - if (!dyn) { - var it = other.frameworks.iterator(); - while (it.next()) |framework| { - try td.frameworks.put(framework.key_ptr.*, framework.value_ptr.*); - } - } - - // Inherit dependencies on system libraries and static libraries. - for (other.link_objects.items) |other_link_object| { - switch (other_link_object) { - .system_lib => |system_lib| { - if ((try td.seen_system_libs.fetchPut(system_lib.name, {})) != null) - continue; - - if (dyn) - continue; - - try td.link_objects.append(other_link_object); - }, - .other_step => |inner_other| { - if ((try td.seen_steps.fetchPut(&inner_other.step, {})) != null) - continue; - - if (!dyn) - try td.link_objects.append(other_link_object); - - try addInner(td, inner_other, dyn or inner_other.isDynamicLibrary()); - }, - else => continue, - } - } - } -}; - fn checkCompileErrors(self: *CompileStep) !void { // Clear this field so that it does not get printed by the build runner. const actual_eb = self.step.result_error_bundle; diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig new file mode 100644 index 000000000000..655138339033 --- /dev/null +++ b/lib/std/Build/Module.zig @@ -0,0 +1,872 @@ +const Module = @This(); + +step: Step, +/// This could either be a generated file, in which case the module +/// contains exactly one file, or it could be a path to the root source +/// file of directory of files which constitute the module. +source_file: ?FileSource, +dependencies: StringArrayHashMap(*Module), +link_objects: ArrayList(LinkObject), +installed_headers: ArrayList(*Step), +frameworks: StringHashMap(FrameworkLinkInfo), +include_dirs: ArrayList(IncludeDir), +lib_paths: ArrayList(FileSource), +rpaths: ArrayList(FileSource), +framework_dirs: ArrayList(FileSource), +c_macros: ArrayList([]const u8), + +is_linking_libc: bool, +is_linking_libcpp: bool, + +pub fn create(owner: *Build, name: ?[]const u8, options: CreateModuleOptions) *Module { + const arena = owner.allocator; + const mod = owner.allocator.create(Module) catch @panic("OOM"); + mod.* = .{ + .step = Step.init(.{ + .id = .module, + .makeFn = make, + .name = if (name) |n| + std.fmt.allocPrint(arena, "module {s}", .{n}) catch @panic("OOM") + else + "module", + .owner = owner, + }), + .source_file = options.source_file, + .dependencies = moduleDependenciesToArrayHashMap(arena, options.dependencies), + .link_objects = ArrayList(LinkObject).init(arena), + .installed_headers = ArrayList(*Step).init(arena), + .frameworks = StringHashMap(FrameworkLinkInfo).init(arena), + .include_dirs = ArrayList(IncludeDir).init(arena), + .lib_paths = ArrayList(FileSource).init(arena), + .rpaths = ArrayList(FileSource).init(arena), + .framework_dirs = ArrayList(FileSource).init(arena), + .c_macros = ArrayList([]const u8).init(arena), + .is_linking_libc = false, + .is_linking_libcpp = false, + }; + + if (options.source_file) |rs| { + rs.addStepDependencies(&mod.step); + } + + if (options.c_source_files) |c_files| { + mod.addCSourceFiles(c_files.files, c_files.flags); + } + + for (options.dependencies) |dep| { + mod.step.dependOn(&dep.module.step); + } + + return mod; +} + +pub fn make(step: *Step, prog_node: *std.Progress.Node) !void { + // Make is a no-op, we only check that the module has at least one source file. + const m = @fieldParentPtr(Module, "step", step); + if (m.source_file != null) return; + + for (m.link_objects.items) |obj| { + switch (obj) { + .c_source_file => return, + .c_source_files => |files| { + if (files.files.len > 0) return; + }, + .assembly_file => return, + else => {}, + } + } + + return m.step.fail("{s} must have at least one source file", .{prog_node.name}); +} + +/// Constructs a string containing all module-specific build arguments needed to +/// build for the provided `CompileStep`. The list of arguments does *not* contain +/// arguments needed for dependency modules. +pub fn constructArgsString( + m: *Module, + compile_step: *CompileStep, +) ![]const []const u8 { + const b = m.step.owner; + var zig_args = ArrayList([]const u8).init(b.allocator); + + for (m.c_macros.items) |c_macro| { + try zig_args.append("-D"); + try zig_args.append(c_macro); + } + + try zig_args.ensureUnusedCapacity(2 * m.lib_paths.items.len); + for (m.lib_paths.items) |lib_path| { + zig_args.appendAssumeCapacity("-L"); + zig_args.appendAssumeCapacity(lib_path.getPath2(b, &m.step)); + } + + try zig_args.ensureUnusedCapacity(2 * m.rpaths.items.len); + for (m.rpaths.items) |rpath| { + zig_args.appendAssumeCapacity("-rpath"); + + if (compile_step.target_info.target.isDarwin()) switch (rpath) { + .path => |path| { + // On Darwin, we should not try to expand special runtime paths such as + // * @executable_path + // * @loader_path + if (mem.startsWith(u8, path, "@executable_path") or + mem.startsWith(u8, path, "@loader_path")) + { + zig_args.appendAssumeCapacity(path); + continue; + } + }, + .generated => {}, + }; + + zig_args.appendAssumeCapacity(rpath.getPath2(b, &m.step)); + } + + for (m.framework_dirs.items) |directory_source| { + if (b.sysroot != null) { + try zig_args.append("-iframeworkwithsysroot"); + } else { + try zig_args.append("-iframework"); + } + try zig_args.append(directory_source.getPath2(b, &m.step)); + try zig_args.append("-F"); + try zig_args.append(directory_source.getPath2(b, &m.step)); + } + + { + var it = m.frameworks.iterator(); + while (it.next()) |entry| { + const name = entry.key_ptr.*; + const info = entry.value_ptr.*; + if (info.needed) { + try zig_args.append("-needed_framework"); + } else if (info.weak) { + try zig_args.append("-weak_framework"); + } else { + try zig_args.append("-framework"); + } + try zig_args.append(name); + } + } + + // We will add link objects from transitive dependencies, but we want to keep + // all link objects in the same order provided. + // This array is used to keep m.link_objects immutable. + var transitive_deps: TransitiveDeps = .{ + .link_objects = ArrayList(LinkObject).init(b.allocator), + .seen_system_libs = StringHashMap(void).init(b.allocator), + .seen_steps = std.AutoHashMap(*const Step, void).init(b.allocator), + .is_linking_libcpp = m.is_linking_libcpp, + .is_linking_libc = m.is_linking_libc, + .frameworks = &m.frameworks, + }; + + try transitive_deps.seen_steps.put(&m.step, {}); + try transitive_deps.add(m); + + var prev_has_extra_flags = false; + + for (transitive_deps.link_objects.items) |link_object| { + switch (link_object) { + .static_path => |static_path| try zig_args.append(static_path.getPath(b)), + + .other_step => |other| switch (other.kind) { + .exe => @panic("Cannot link with an executable build artifact"), + .@"test" => @panic("Cannot link with a test"), + .obj => { + try zig_args.append(other.getOutputSource().getPath(b)); + }, + .lib => l: { + if (compile_step.isStaticLibrary() and other.isStaticLibrary()) { + // Avoid putting a static library inside a static library. + break :l; + } + + const full_path_lib = other.getOutputLibSource().getPath(b); + try zig_args.append(full_path_lib); + + if (other.linkage == Linkage.dynamic and !compile_step.target.isWindows()) { + if (fs.path.dirname(full_path_lib)) |dirname| { + try zig_args.append("-rpath"); + try zig_args.append(dirname); + } + } + }, + }, + + .system_lib => |system_lib| { + const prefix: []const u8 = prefix: { + if (system_lib.needed) break :prefix "-needed-l"; + if (system_lib.weak) break :prefix "-weak-l"; + break :prefix "-l"; + }; + switch (system_lib.use_pkg_config) { + .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), + .yes, .force => { + if (compile_step.runPkgConfig(system_lib.name)) |args| { + try zig_args.appendSlice(args); + } else |err| switch (err) { + error.PkgConfigInvalidOutput, + error.PkgConfigCrashed, + error.PkgConfigFailed, + error.PkgConfigNotInstalled, + error.PackageNotFound, + => switch (system_lib.use_pkg_config) { + .yes => { + // pkg-config failed, so fall back to linking the library + // by name directly. + try zig_args.append(b.fmt("{s}{s}", .{ + prefix, + system_lib.name, + })); + }, + .force => { + panic("pkg-config failed for library {s}", .{system_lib.name}); + }, + .no => unreachable, + }, + + else => |e| return e, + } + }, + } + }, + + .assembly_file => |asm_file| { + if (prev_has_extra_flags) { + try zig_args.append("-extra-cflags"); + try zig_args.append("--"); + prev_has_extra_flags = false; + } + try zig_args.append(asm_file.getPath(b)); + }, + + .c_source_file => |c_source_file| { + if (c_source_file.args.len == 0) { + if (prev_has_extra_flags) { + try zig_args.append("-cflags"); + try zig_args.append("--"); + prev_has_extra_flags = false; + } + } else { + try zig_args.append("-cflags"); + for (c_source_file.args) |arg| { + try zig_args.append(arg); + } + try zig_args.append("--"); + } + try zig_args.append(c_source_file.source.getPath(b)); + }, + + .c_source_files => |c_source_files| { + if (c_source_files.flags.len == 0) { + if (prev_has_extra_flags) { + try zig_args.append("-cflags"); + try zig_args.append("--"); + prev_has_extra_flags = false; + } + } else { + try zig_args.append("-cflags"); + for (c_source_files.flags) |flag| { + try zig_args.append(flag); + } + try zig_args.append("--"); + } + for (c_source_files.files) |file| { + try zig_args.append(b.pathFromRoot(file)); + } + }, + } + } + + if (transitive_deps.is_linking_libcpp) { + try zig_args.append("-lc++"); + } + + if (transitive_deps.is_linking_libc) { + try zig_args.append("-lc"); + } + + for (m.include_dirs.items) |include_dir| { + switch (include_dir) { + .raw_path => |include_path| { + try zig_args.append("-I"); + try zig_args.append(b.pathFromRoot(include_path)); + }, + .raw_path_system => |include_path| { + if (b.sysroot != null) { + try zig_args.append("-iwithsysroot"); + } else { + try zig_args.append("-isystem"); + } + + const resolved_include_path = b.pathFromRoot(include_path); + + const common_include_path = if (builtin.os.tag == .windows and b.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: { + // We need to check for disk designator and strip it out from dir path so + // that zig/clang can concat resolved_include_path with sysroot. + const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path); + + if (mem.indexOf(u8, resolved_include_path, disk_designator)) |where| { + break :blk resolved_include_path[where + disk_designator.len ..]; + } + + break :blk resolved_include_path; + } else resolved_include_path; + + try zig_args.append(common_include_path); + }, + .other_step => |other| { + if (other.emit_h) { + const h_path = other.getOutputHSource().getPath(b); + try zig_args.append("-isystem"); + try zig_args.append(fs.path.dirname(h_path).?); + } + if (other.main_module.installed_headers.items.len > 0) { + try zig_args.append("-I"); + try zig_args.append(b.pathJoin(&.{ + other.step.owner.install_prefix, "include", + })); + } + }, + .config_header_step => |config_header| { + const full_file_path = config_header.output_file.path.?; + const header_dir_path = full_file_path[0 .. full_file_path.len - config_header.include_path.len]; + try zig_args.appendSlice(&.{ "-I", header_dir_path }); + }, + } + } + + return zig_args.toOwnedSlice(); +} + +fn moduleDependenciesToArrayHashMap(arena: Allocator, deps: []const ModuleDependency) std.StringArrayHashMap(*Module) { + var result = std.StringArrayHashMap(*Module).init(arena); + for (deps) |dep| { + result.put(dep.name, dep.module) catch @panic("OOM"); + } + return result; +} + +pub fn addOptions(m: *Module, name: []const u8, options: *OptionsStep) void { + m.dependencies.put(m.step.owner.dupe(name), options.addModule(name)) catch @panic("OOM"); + m.step.dependOn(&options.step); +} + +pub const LinkObject = union(enum) { + static_path: FileSource, + other_step: *CompileStep, + system_lib: SystemLib, + assembly_file: FileSource, + c_source_file: *CSourceFile, + c_source_files: *CSourceFiles, +}; + +pub fn linkLibC(m: *Module) void { + m.is_linking_libc = true; +} + +pub fn linkLibCpp(m: *Module) void { + m.is_linking_libcpp = true; +} + +/// This one has no integration with anything, it just puts -lname on the command line. +/// Prefer to use `linkSystemLibrary` instead. +pub fn linkSystemLibraryName(m: *Module, name: []const u8) void { + const b = m.step.owner; + m.link_objects.append(.{ + .system_lib = .{ + .name = b.dupe(name), + .needed = false, + .weak = false, + .use_pkg_config = .no, + }, + }) catch @panic("OOM"); +} + +/// This one has no integration with anything, it just puts -needed-lname on the command line. +/// Prefer to use `linkSystemLibraryNeeded` instead. +pub fn linkSystemLibraryNeededName(m: *Module, name: []const u8) void { + const b = m.step.owner; + m.link_objects.append(.{ + .system_lib = .{ + .name = b.dupe(name), + .needed = true, + .weak = false, + .use_pkg_config = .no, + }, + }) catch @panic("OOM"); +} + +/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the +/// command line. Prefer to use `linkSystemLibraryWeak` instead. +pub fn linkSystemLibraryWeakName(m: *Module, name: []const u8) void { + const b = m.step.owner; + m.link_objects.append(.{ + .system_lib = .{ + .name = b.dupe(name), + .needed = false, + .weak = true, + .use_pkg_config = .no, + }, + }) catch @panic("OOM"); +} + +/// This links against a system library, exclusively using pkg-config to find the library. +/// Prefer to use `linkSystemLibrary` instead. +pub fn linkSystemLibraryPkgConfigOnly(m: *Module, lib_name: []const u8) void { + const b = m.step.owner; + m.link_objects.append(.{ + .system_lib = .{ + .name = b.dupe(lib_name), + .needed = false, + .weak = false, + .use_pkg_config = .force, + }, + }) catch @panic("OOM"); +} + +/// This links against a system library, exclusively using pkg-config to find the library. +/// Prefer to use `linkSystemLibraryNeeded` instead. +pub fn linkSystemLibraryNeededPkgConfigOnly(m: *Module, lib_name: []const u8) void { + const b = m.step.owner; + m.link_objects.append(.{ + .system_lib = .{ + .name = b.dupe(lib_name), + .needed = true, + .weak = false, + .use_pkg_config = .force, + }, + }) catch @panic("OOM"); +} + +/// Handy when you have many C/C++ source files and want them all to have the same flags. +pub fn addCSourceFiles(m: *Module, files: []const []const u8, flags: []const []const u8) void { + const b = m.step.owner; + const c_source_files = b.allocator.create(CSourceFiles) catch @panic("OOM"); + + const files_copy = b.dupeStrings(files); + const flags_copy = b.dupeStrings(flags); + + c_source_files.* = .{ + .files = files_copy, + .flags = flags_copy, + }; + m.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM"); +} + +pub fn addCSourceFile(m: *Module, file: []const u8, flags: []const []const u8) void { + m.addCSourceFileSource(.{ + .args = flags, + .source = .{ .path = file }, + }); +} + +pub fn addCSourceFileSource(m: *Module, source: CSourceFile) void { + const b = m.step.owner; + const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM"); + c_source_file.* = source.dupe(b); + m.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM"); + source.source.addStepDependencies(&m.step); +} + +const InstalledHeader = union(enum) { + header: struct { + source_path: []const u8, + dest_rel_path: []const u8, + }, + header_dir_step: InstallDirStep.Options, + config_header: struct { + step: *ConfigHeaderStep, + options: CompileStep.InstallConfigHeaderOptions, + }, + lib_step: *CompileStep, +}; + +pub fn installHeader(m: *Module, src_path: []const u8, dest_rel_path: []const u8) void { + const b = m.step.owner; + const install_file = b.addInstallHeaderFile(src_path, dest_rel_path); + b.getInstallStep().dependOn(&install_file.step); + m.installed_headers.append(&install_file.step) catch @panic("OOM"); +} + +pub const InstallConfigHeaderOptions = struct { + install_dir: InstallDir = .header, + dest_rel_path: ?[]const u8 = null, +}; + +pub fn installConfigHeader( + m: *Module, + config_header: *ConfigHeaderStep, + options: InstallConfigHeaderOptions, +) void { + const dest_rel_path = options.dest_rel_path orelse config_header.include_path; + const b = m.step.owner; + const install_file = b.addInstallFileWithDir( + .{ .generated = &config_header.output_file }, + options.install_dir, + dest_rel_path, + ); + install_file.step.dependOn(&config_header.step); + b.getInstallStep().dependOn(&install_file.step); + m.installed_headers.append(&install_file.step) catch @panic("OOM"); +} + +pub fn installHeadersDirectory( + m: *Module, + src_dir_path: []const u8, + dest_rel_path: []const u8, +) void { + return installHeadersDirectoryOptions(m, .{ + .source_dir = src_dir_path, + .install_dir = .header, + .install_subdir = dest_rel_path, + }); +} + +pub fn installHeadersDirectoryOptions( + m: *Module, + options: std.Build.InstallDirStep.Options, +) void { + const b = m.step.owner; + const install_dir = b.addInstallDirectory(options); + b.getInstallStep().dependOn(&install_dir.step); + m.installed_headers.append(&install_dir.step) catch @panic("OOM"); +} + +pub fn installLibraryHeaders(m: *Module, l: *CompileStep) void { + assert(l.kind == .lib); + const b = m.step.owner; + const install_step = b.getInstallStep(); + // Copy each element from installed_headers, modifying the builder + // to be the new parent's builder. + for (l.main_module.installed_headers.items) |step| { + const step_copy = switch (step.id) { + inline .install_file, .install_dir => |id| blk: { + const T = id.Type(); + const ptr = b.allocator.create(T) catch @panic("OOM"); + ptr.* = step.cast(T).?.*; + ptr.dest_builder = b; + break :blk &ptr.step; + }, + else => unreachable, + }; + m.installed_headers.append(step_copy) catch @panic("OOM"); + install_step.dependOn(step_copy); + } + m.installed_headers.appendSlice(l.main_module.installed_headers.items) catch @panic("OOM"); +} + +/// If the value is omitted, it is set to 1. +/// `name` and `value` need not live longer than the function call. +pub fn defineCMacro(m: *Module, name: []const u8, value: ?[]const u8) void { + const b = m.step.owner; + const macro = std.Build.constructCMacro(b.allocator, name, value); + m.c_macros.append(macro) catch @panic("OOM"); +} + +/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. +pub fn defineCMacroRaw(m: *Module, name_and_value: []const u8) void { + const b = m.step.owner; + m.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); +} + +pub const SystemLib = struct { + name: []const u8, + needed: bool, + weak: bool, + use_pkg_config: enum { + /// Don't use pkg-config, just pass -lfoo where foo is name. + no, + /// Try to get information on how to link the library from pkg-config. + /// If that fails, fall back to passing -lfoo where foo is name. + yes, + /// Try to get information on how to link the library from pkg-config. + /// If that fails, error out. + force, + }, +}; + +pub fn linkLibrary(m: *Module, lib: *CompileStep) void { + assert(lib.kind == .lib); + m.linkLibraryOrObject(lib); +} + +fn linkLibraryOrObject(m: *Module, other: *CompileStep) void { + m.link_objects.append(.{ .other_step = other }) catch @panic("OOM"); + m.include_dirs.append(.{ .other_step = other }) catch @panic("OOM"); + + for (other.main_module.installed_headers.items) |install_step| { + m.step.dependOn(install_step); + } +} + +pub fn addAssemblyFile(m: *Module, path: []const u8) void { + const b = m.step.owner; + m.link_objects.append(.{ + .assembly_file = .{ .path = b.dupe(path) }, + }) catch @panic("OOM"); +} + +pub fn addAssemblyFileSource(m: *Module, source: FileSource) void { + const b = m.step.owner; + const source_duped = source.dupe(b); + m.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM"); + source_duped.addStepDependencies(&m.step); +} + +pub fn addObjectFile(m: *Module, source_file: []const u8) void { + m.addObjectFileSource(.{ .path = source_file }); +} + +pub fn addObjectFileSource(m: *Module, source: FileSource) void { + const b = m.step.owner; + m.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM"); + source.addStepDependencies(&m.step); +} + +pub fn addObject(m: *Module, obj: *CompileStep) void { + assert(obj.kind == .obj); + m.linkLibraryOrObject(obj); +} + +pub fn linkSystemLibrary(m: *Module, name: []const u8) void { + m.linkSystemLibraryInner(name, .{}); +} + +pub fn linkSystemLibraryNeeded(m: *Module, name: []const u8) void { + m.linkSystemLibraryInner(name, .{ .needed = true }); +} + +pub fn linkSystemLibraryWeak(m: *Module, name: []const u8) void { + m.linkSystemLibraryInner(name, .{ .weak = true }); +} + +fn linkSystemLibraryInner(m: *Module, name: []const u8, opts: struct { + needed: bool = false, + weak: bool = false, +}) void { + const b = m.step.owner; + if (isLibCLibrary(name)) { + m.linkLibC(); + return; + } + if (isLibCppLibrary(name)) { + m.linkLibCpp(); + return; + } + + m.link_objects.append(.{ + .system_lib = .{ + .name = b.dupe(name), + .needed = opts.needed, + .weak = opts.weak, + .use_pkg_config = .yes, + }, + }) catch @panic("OOM"); +} + +fn isLibCLibrary(name: []const u8) bool { + const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" }; + for (libc_libraries) |libc_lib_name| { + if (mem.eql(u8, name, libc_lib_name)) + return true; + } + return false; +} + +fn isLibCppLibrary(name: []const u8) bool { + const libcpp_libraries = [_][]const u8{ "c++", "stdc++" }; + for (libcpp_libraries) |libcpp_lib_name| { + if (mem.eql(u8, name, libcpp_lib_name)) + return true; + } + return false; +} + +/// Returns whether the module depends on a particular system library. +pub fn dependsOnSystemLibrary(m: Module, name: []const u8) bool { + if (isLibCLibrary(name)) { + return m.is_linking_libc; + } + if (isLibCppLibrary(name)) { + return m.is_linking_libcpp; + } + for (m.link_objects.items) |link_object| { + switch (link_object) { + .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, + else => continue, + } + } + return false; +} + +pub const FrameworkLinkInfo = struct { + needed: bool = false, + weak: bool = false, +}; + +pub fn linkFramework(m: *Module, framework_name: []const u8) void { + const b = m.step.owner; + m.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM"); +} + +pub fn linkFrameworkNeeded(m: *Module, framework_name: []const u8) void { + const b = m.step.owner; + m.frameworks.put(b.dupe(framework_name), .{ + .needed = true, + }) catch @panic("OOM"); +} + +pub fn linkFrameworkWeak(m: *Module, framework_name: []const u8) void { + const b = m.step.owner; + m.frameworks.put(b.dupe(framework_name), .{ + .weak = true, + }) catch @panic("OOM"); +} + +pub const IncludeDir = union(enum) { + raw_path: []const u8, + raw_path_system: []const u8, + other_step: *CompileStep, + config_header_step: *ConfigHeaderStep, +}; + +pub fn addSystemIncludePath(m: *Module, path: []const u8) void { + const b = m.step.owner; + m.include_dirs.append(IncludeDir{ .raw_path_system = b.dupe(path) }) catch @panic("OOM"); +} + +pub fn addIncludePath(m: *Module, path: []const u8) void { + const b = m.step.owner; + m.include_dirs.append(IncludeDir{ .raw_path = b.dupe(path) }) catch @panic("OOM"); +} + +pub fn addConfigHeader(m: *Module, config_header: *ConfigHeaderStep) void { + m.step.dependOn(&config_header.step); + m.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM"); +} + +pub fn addLibraryPath(m: *Module, path: []const u8) void { + const b = m.step.owner; + m.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM"); +} + +pub fn addLibraryPathDirectorySource(m: *Module, directory_source: FileSource) void { + m.lib_paths.append(directory_source) catch @panic("OOM"); + directory_source.addStepDependencies(&m.step); +} + +pub fn addRPath(m: *Module, path: []const u8) void { + const b = m.step.owner; + m.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM"); +} + +pub fn addRPathDirectorySource(m: *Module, directory_source: FileSource) void { + m.rpaths.append(directory_source) catch @panic("OOM"); + directory_source.addStepDependencies(&m.step); +} + +pub fn addFrameworkPath(m: *Module, dir_path: []const u8) void { + const b = m.step.owner; + m.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM"); +} + +pub fn addFrameworkPathDirectorySource(m: *Module, directory_source: FileSource) void { + m.framework_dirs.append(directory_source) catch @panic("OOM"); + directory_source.addStepDependencies(&m.step); +} + +const TransitiveDeps = struct { + link_objects: ArrayList(LinkObject), + seen_system_libs: StringHashMap(void), + seen_steps: std.AutoHashMap(*const Step, void), + is_linking_libcpp: bool, + is_linking_libc: bool, + frameworks: *StringHashMap(FrameworkLinkInfo), + + fn add(td: *TransitiveDeps, module: *Module) !void { + td.is_linking_libcpp = td.is_linking_libcpp or module.is_linking_libcpp; + td.is_linking_libc = td.is_linking_libc or module.is_linking_libc; + + try td.link_objects.ensureUnusedCapacity(module.link_objects.items.len); + + for (module.link_objects.items) |link_object| { + try td.link_objects.append(link_object); + switch (link_object) { + .other_step => |other| try td.addInner(other.main_module, other.isDynamicLibrary()), + else => {}, + } + } + } + + fn addInner(td: *TransitiveDeps, other: *Module, dyn: bool) !void { + // Inherit dependency on libc and libc++ + td.is_linking_libcpp = td.is_linking_libcpp or other.is_linking_libcpp; + td.is_linking_libc = td.is_linking_libc or other.is_linking_libc; + + // Inherit dependencies on darwin frameworks + if (!dyn) { + var it = other.frameworks.iterator(); + while (it.next()) |framework| { + try td.frameworks.put(framework.key_ptr.*, framework.value_ptr.*); + } + } + + // Inherit dependencies on system libraries and static libraries. + for (other.link_objects.items) |other_link_object| { + switch (other_link_object) { + .system_lib => |system_lib| { + if ((try td.seen_system_libs.fetchPut(system_lib.name, {})) != null) + continue; + + if (dyn) + continue; + + try td.link_objects.append(other_link_object); + }, + .other_step => |inner_other| { + if ((try td.seen_steps.fetchPut(&inner_other.step, {})) != null) + continue; + + if (!dyn) + try td.link_objects.append(other_link_object); + + try addInner(td, inner_other.main_module, dyn or inner_other.isDynamicLibrary()); + }, + else => continue, + } + } + } +}; + +const std = @import("std"); +const Build = std.Build; +const Step = Build.Step; +const FileSource = Build.FileSource; +const CompileStep = Build.CompileStep; +const ConfigHeaderStep = Build.ConfigHeaderStep; +const OptionsStep = Build.OptionsStep; +const InstallDirStep = Build.InstallDirStep; +const InstallDir = Build.InstallDir; +const CSourceFile = Build.CSourceFile; +const CSourceFiles = Build.CSourceFiles; +const ModuleDependency = Build.ModuleDependency; +const CreateModuleOptions = Build.CreateModuleOptions; +const Linkage = CompileStep.Linkage; + +const ArrayList = std.ArrayList; +const StringHashMap = std.StringHashMap; +const StringArrayHashMap = std.StringArrayHashMap; +const Allocator = std.mem.Allocator; + +const assert = std.debug.assert; +const mem = std.mem; +const fs = std.fs; +const panic = std.debug.panic; +const builtin = @import("builtin"); + +pub const addSystemIncludeDir = @compileError("deprecated; use addSystemIncludePath"); +pub const addIncludeDir = @compileError("deprecated; use addIncludePath"); +pub const addLibPath = @compileError("deprecated, use addLibraryPath"); +pub const addFrameworkDir = @compileError("deprecated, use addFrameworkPath"); diff --git a/lib/std/Build/OptionsStep.zig b/lib/std/Build/OptionsStep.zig index a0e72e3695f9..44ea0f8b662f 100644 --- a/lib/std/Build/OptionsStep.zig +++ b/lib/std/Build/OptionsStep.zig @@ -214,6 +214,13 @@ pub fn createModule(self: *OptionsStep) *std.Build.Module { }); } +pub fn addModule(self: *OptionsStep, name: []const u8) *std.Build.Module { + return self.step.owner.addModule(name, .{ + .source_file = self.getSource(), + .dependencies = &.{}, + }); +} + pub fn getSource(self: *OptionsStep) FileSource { return .{ .generated = &self.generated_file }; } diff --git a/lib/std/Build/RunStep.zig b/lib/std/Build/RunStep.zig index 435c7369d039..c0194090d3a6 100644 --- a/lib/std/Build/RunStep.zig +++ b/lib/std/Build/RunStep.zig @@ -579,10 +579,10 @@ fn runCommand( else => break :interpret, } - const need_cross_glibc = exe.target.isGnuLibC() and exe.is_linking_libc; + const need_cross_glibc = exe.target.isGnuLibC() and exe.main_module.is_linking_libc; switch (b.host.getExternalExecutor(exe.target_info, .{ .qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null, - .link_libc = exe.is_linking_libc, + .link_libc = exe.main_module.is_linking_libc, })) { .native, .rosetta => { if (allow_skip) return error.MakeSkipped; @@ -1177,7 +1177,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult { fn addPathForDynLibs(self: *RunStep, artifact: *CompileStep) void { const b = self.step.owner; - for (artifact.link_objects.items) |link_object| { + for (artifact.main_module.link_objects.items) |link_object| { switch (link_object) { .other_step => |other| { if (other.target.isWindows() and other.isDynamicLibrary()) { diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig index 0c05a64b1c67..c5a98137e023 100644 --- a/lib/std/Build/Step.zig +++ b/lib/std/Build/Step.zig @@ -89,6 +89,7 @@ pub const Id = enum { config_header, objcopy, options, + module, custom, pub fn Type(comptime id: Id) type { @@ -108,6 +109,7 @@ pub const Id = enum { .config_header => Build.ConfigHeaderStep, .objcopy => Build.ObjCopyStep, .options => Build.OptionsStep, + .module => Build.Module, .custom => @compileError("no type available for custom step"), }; } diff --git a/lib/std/Build/TranslateCStep.zig b/lib/std/Build/TranslateCStep.zig index f2dc23d95074..81637cd9062c 100644 --- a/lib/std/Build/TranslateCStep.zig +++ b/lib/std/Build/TranslateCStep.zig @@ -57,8 +57,11 @@ pub const AddExecutableOptions = struct { /// Creates a step to build an executable from the translated source. pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *CompileStep { + const output_module = self.step.owner.createModule(.{ + .source_file = .{ .generated = &self.output_file }, + }); return self.step.owner.addExecutable(.{ - .root_source_file = .{ .generated = &self.output_file }, + .main_module = output_module, .name = options.name orelse "translated_c", .version = options.version, .target = options.target orelse self.target, diff --git a/src/main.zig b/src/main.zig index 6a83791ca38f..80558f0541d3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -701,6 +701,186 @@ const ArgsIterator = struct { return it.args[it.i]; } }; +const ModuleArgs = struct { + mod: *Package, + deps_str: []const u8, // still in CLI arg format +}; + +fn parseModuleArgs( + gpa: Allocator, + arena: Allocator, + args_iter: *ArgsIterator, + modules: *std.StringArrayHashMap(ModuleArgs), +) !void { + var root_src_orig: ?[]const u8 = null; + var deps_str: []const u8 = ""; + + var clang_argv = std.ArrayList([]const u8).init(gpa); + defer clang_argv.deinit(); + + var cssan = ClangSearchSanitizer.init(gpa, &clang_argv); + defer cssan.map.deinit(); + + var system_libs = std.StringArrayHashMap(Compilation.SystemLib).init(gpa); + defer system_libs.deinit(); + + var extra_cflags = std.ArrayList([]const u8).init(gpa); + defer extra_cflags.deinit(); + + var lib_dirs = std.ArrayList([]const u8).init(gpa); + defer lib_dirs.deinit(); + + var rpath_list = std.ArrayList([]const u8).init(gpa); + defer rpath_list.deinit(); + + var c_source_files = std.ArrayList(Compilation.CSourceFile).init(gpa); + defer c_source_files.deinit(); + + var link_objects = std.ArrayList(Compilation.LinkObject).init(gpa); + defer link_objects.deinit(); + + var framework_dirs = std.ArrayList([]const u8).init(gpa); + defer framework_dirs.deinit(); + + var frameworks: std.StringArrayHashMapUnmanaged(Compilation.SystemLib) = .{}; + + const mod_name = args_iter.nextOrFatal(); + + var file_ext: ?Compilation.FileExt = null; + while (args_iter.next()) |mod_arg| { + if (std.mem.eql(u8, mod_arg, "--root-source")) { + root_src_orig = args_iter.nextOrFatal(); + } else if (std.mem.eql(u8, mod_arg, "--args")) { + while (args_iter.next()) |arg| { + if (mem.startsWith(u8, arg, "-")) { + if (mem.eql(u8, arg, "-cflags")) { + extra_cflags.shrinkRetainingCapacity(0); + while (true) { + const next_arg = args_iter.next() orelse { + fatal("expected -- after -cflags", .{}); + }; + if (mem.eql(u8, next_arg, "--")) break; + try extra_cflags.append(next_arg); + } + } else if (mem.eql(u8, arg, "-rpath")) { + try rpath_list.append(args_iter.nextOrFatal()); + } else if (mem.eql(u8, arg, "--library-directory") or mem.eql(u8, arg, "-L")) { + try lib_dirs.append(args_iter.nextOrFatal()); + } else if (mem.eql(u8, arg, "-F")) { + try framework_dirs.append(args_iter.nextOrFatal()); + } else if (mem.eql(u8, arg, "-framework")) { + try frameworks.put(gpa, args_iter.nextOrFatal(), .{}); + } else if (mem.eql(u8, arg, "-weak_framework")) { + try frameworks.put(gpa, args_iter.nextOrFatal(), .{ .weak = true }); + } else if (mem.eql(u8, arg, "-needed_framework")) { + try frameworks.put(gpa, args_iter.nextOrFatal(), .{ .needed = true }); + } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) { + // We don't know whether this library is part of libc or libc++ until + // we resolve the target, so we simply append to the list for now. + try system_libs.put(args_iter.nextOrFatal(), .{}); + } else if (mem.eql(u8, arg, "--needed-library") or + mem.eql(u8, arg, "-needed-l") or + mem.eql(u8, arg, "-needed_library")) + { + const next_arg = args_iter.nextOrFatal(); + try system_libs.put(next_arg, .{ .needed = true }); + } else if (mem.eql(u8, arg, "-weak_library") or mem.eql(u8, arg, "-weak-l")) { + try system_libs.put(args_iter.nextOrFatal(), .{ .weak = true }); + } else if (mem.eql(u8, arg, "-D")) { + try clang_argv.append(arg); + try clang_argv.append(args_iter.nextOrFatal()); + } else if (mem.eql(u8, arg, "-I")) { + try cssan.addIncludePath(.I, arg, args_iter.nextOrFatal(), false); + } else if (mem.eql(u8, arg, "-isystem") or mem.eql(u8, arg, "-iwithsysroot")) { + try cssan.addIncludePath(.isystem, arg, args_iter.nextOrFatal(), false); + } else if (mem.eql(u8, arg, "-idirafter")) { + try cssan.addIncludePath(.idirafter, arg, args_iter.nextOrFatal(), false); + } else if (mem.eql(u8, arg, "-iframework") or mem.eql(u8, arg, "-iframeworkwithsysroot")) { + try cssan.addIncludePath(.iframework, arg, args_iter.nextOrFatal(), false); + } else if (mem.startsWith(u8, arg, "-L")) { + try lib_dirs.append(arg[2..]); + } else if (mem.startsWith(u8, arg, "-F")) { + try framework_dirs.append(arg[2..]); + } else if (mem.startsWith(u8, arg, "-l")) { + // We don't know whether this library is part of libc or libc++ until + // we resolve the target, so we simply append to the list for now. + try system_libs.put(arg["-l".len..], .{}); + } else if (mem.startsWith(u8, arg, "-needed-l")) { + try system_libs.put(arg["-needed-l".len..], .{ .needed = true }); + } else if (mem.startsWith(u8, arg, "-weak-l")) { + try system_libs.put(arg["-weak-l".len..], .{ .weak = true }); + } else if (mem.startsWith(u8, arg, "-D")) { + try clang_argv.append(arg); + } else if (mem.startsWith(u8, arg, "-I")) { + try cssan.addIncludePath(.I, arg, arg[2..], true); + } else if (mem.eql(u8, arg, "-x")) { + const lang = args_iter.nextOrFatal(); + if (mem.eql(u8, lang, "none")) { + file_ext = null; + } else if (Compilation.LangToExt.get(lang)) |got_ext| { + file_ext = got_ext; + } else { + fatal("language not recognized: '{s}'", .{lang}); + } + } else if (mem.eql(u8, arg, "--args-end")) { + break; + } else { + fatal("unrecognized parameter: '{s}'", .{arg}); + } + } else switch (file_ext orelse + Compilation.classifyFileExt(arg)) { + .object, .static_library, .shared_library => try link_objects.append(.{ .path = arg }), + .assembly, .assembly_with_cpp, .c, .cpp, .h, .ll, .bc, .m, .mm, .cu => { + try c_source_files.append(.{ + .src_path = arg, + .extra_flags = try arena.dupe([]const u8, extra_cflags.items), + // duped when parsing the args. + .ext = file_ext, + }); + }, + .zig => { + fatal("zig root source file should be specified as --root-source {s}", .{arg}); + }, + .def, .unknown => { + fatal("unrecognized file extension of parameter '{s}'", .{arg}); + }, + } + } + } else if (std.mem.eql(u8, mod_arg, "--deps")) { + deps_str = args_iter.nextOrFatal(); + } + } + + const root_src = if (root_src_orig) |rs| + try introspect.resolvePath(arena, rs) + else + // TODO: Is this the right path to choose here? + try introspect.resolvePath(arena, "."); + + for ([_][]const u8{ "std", "root", "builtin" }) |name| { + if (mem.eql(u8, mod_name, name)) { + fatal("unable to add module '{s}' -> '{s}': conflicts with builtin module", .{ mod_name, root_src }); + } + } + + var mod_it = modules.iterator(); + while (mod_it.next()) |kv| { + if (std.mem.eql(u8, mod_name, kv.key_ptr.*)) { + fatal("unable to add module '{s}' -> '{s}': already exists as '{s}'", .{ mod_name, root_src, kv.value_ptr.mod.root_src_path }); + } + } + + try modules.ensureUnusedCapacity(1); + modules.putAssumeCapacity(mod_name, .{ + .mod = try Package.create( + gpa, + fs.path.dirname(root_src), + fs.path.basename(root_src), + // TODO: Add parsed module arguments + ), + .deps_str = deps_str, + }); +} fn buildOutputType( gpa: Allocator, @@ -710,6 +890,7 @@ fn buildOutputType( ) !void { var color: Color = .auto; var optimize_mode: std.builtin.Mode = .Debug; + var main_module: ?[]const u8 = null; var provided_name: ?[]const u8 = null; var link_mode: ?std.builtin.LinkMode = null; var dll_export_fns: ?bool = null; @@ -904,10 +1085,7 @@ fn buildOutputType( // Contains every module specified via --mod. The dependencies are added // after argument parsing is completed. We use a StringArrayHashMap to make // error output consistent. - var modules = std.StringArrayHashMap(struct { - mod: *Package, - deps_str: []const u8, // still in CLI arg format - }).init(gpa); + var modules = std.StringArrayHashMap(ModuleArgs).init(gpa); defer { var it = modules.iterator(); while (it.next()) |kv| kv.value_ptr.mod.destroy(gpa); @@ -949,7 +1127,6 @@ fn buildOutputType( var cssan = ClangSearchSanitizer.init(gpa, &clang_argv); defer cssan.map.deinit(); - var file_ext: ?Compilation.FileExt = null; args_loop: while (args_iter.next()) |arg| { if (mem.startsWith(u8, arg, "@")) { // This is a "compiler response file". We must parse the file and treat its @@ -972,54 +1149,9 @@ fn buildOutputType( fatal("unexpected end-of-parameter mark: --", .{}); } } else if (mem.eql(u8, arg, "--mod")) { - const info = args_iter.nextOrFatal(); - var info_it = mem.split(u8, info, ":"); - const mod_name = info_it.next() orelse fatal("expected non-empty argument after {s}", .{arg}); - const deps_str = info_it.next() orelse fatal("expected 'name:deps:path' after {s}", .{arg}); - const root_src_orig = info_it.rest(); - if (root_src_orig.len == 0) fatal("expected 'name:deps:path' after {s}", .{arg}); - if (mod_name.len == 0) fatal("empty name for module at '{s}'", .{root_src_orig}); - - const root_src = try introspect.resolvePath(arena, root_src_orig); - - for ([_][]const u8{ "std", "root", "builtin" }) |name| { - if (mem.eql(u8, mod_name, name)) { - fatal("unable to add module '{s}' -> '{s}': conflicts with builtin module", .{ mod_name, root_src }); - } - } - - var mod_it = modules.iterator(); - while (mod_it.next()) |kv| { - if (std.mem.eql(u8, mod_name, kv.key_ptr.*)) { - fatal("unable to add module '{s}' -> '{s}': already exists as '{s}'", .{ mod_name, root_src, kv.value_ptr.mod.root_src_path }); - } - } - - try modules.ensureUnusedCapacity(1); - modules.put(mod_name, .{ - .mod = try Package.create( - gpa, - fs.path.dirname(root_src), - fs.path.basename(root_src), - ), - .deps_str = deps_str, - }) catch unreachable; - } else if (mem.eql(u8, arg, "--deps")) { - if (root_deps_str != null) { - fatal("only one --deps argument is allowed", .{}); - } - root_deps_str = args_iter.nextOrFatal(); + try parseModuleArgs(gpa, arena, &args_iter, &modules); } else if (mem.eql(u8, arg, "--main-pkg-path")) { main_pkg_path = args_iter.nextOrFatal(); - } else if (mem.eql(u8, arg, "-cflags")) { - extra_cflags.shrinkRetainingCapacity(0); - while (true) { - const next_arg = args_iter.next() orelse { - fatal("expected -- after -cflags", .{}); - }; - if (mem.eql(u8, next_arg, "--")) break; - try extra_cflags.append(next_arg); - } } else if (mem.eql(u8, arg, "--color")) { const next_arg = args_iter.next() orelse { fatal("expected [auto|on|off] after --color", .{}); @@ -1045,22 +1177,11 @@ fn buildOutputType( image_base_override = std.fmt.parseUnsigned(u64, next_arg, 0) catch |err| { fatal("unable to parse image base override '{s}': {s}", .{ next_arg, @errorName(err) }); }; - } else if (mem.eql(u8, arg, "--name")) { - provided_name = args_iter.nextOrFatal(); - if (!mem.eql(u8, provided_name.?, fs.path.basename(provided_name.?))) - fatal("invalid package name '{s}': cannot contain folder separators", .{provided_name.?}); - } else if (mem.eql(u8, arg, "-rpath")) { - try rpath_list.append(args_iter.nextOrFatal()); - } else if (mem.eql(u8, arg, "--library-directory") or mem.eql(u8, arg, "-L")) { - try lib_dirs.append(args_iter.nextOrFatal()); - } else if (mem.eql(u8, arg, "-F")) { - try framework_dirs.append(args_iter.nextOrFatal()); - } else if (mem.eql(u8, arg, "-framework")) { - try frameworks.put(gpa, args_iter.nextOrFatal(), .{}); - } else if (mem.eql(u8, arg, "-weak_framework")) { - try frameworks.put(gpa, args_iter.nextOrFatal(), .{ .weak = true }); - } else if (mem.eql(u8, arg, "-needed_framework")) { - try frameworks.put(gpa, args_iter.nextOrFatal(), .{ .needed = true }); + } else if (mem.eql(u8, arg, "--main-mod")) { + main_module = args_iter.nextOrFatal(); + provided_name = main_module; + if (!mem.eql(u8, main_module.?, fs.path.basename(main_module.?))) + fatal("invalid module name '{s}': cannot contain folder separators", .{main_module.?}); } else if (mem.eql(u8, arg, "-install_name")) { install_name = args_iter.nextOrFatal(); } else if (mem.startsWith(u8, arg, "--compress-debug-sections=")) { @@ -1094,29 +1215,6 @@ fn buildOutputType( linker_script = args_iter.nextOrFatal(); } else if (mem.eql(u8, arg, "--version-script")) { version_script = args_iter.nextOrFatal(); - } else if (mem.eql(u8, arg, "--library") or mem.eql(u8, arg, "-l")) { - // We don't know whether this library is part of libc or libc++ until - // we resolve the target, so we simply append to the list for now. - try system_libs.put(args_iter.nextOrFatal(), .{}); - } else if (mem.eql(u8, arg, "--needed-library") or - mem.eql(u8, arg, "-needed-l") or - mem.eql(u8, arg, "-needed_library")) - { - const next_arg = args_iter.nextOrFatal(); - try system_libs.put(next_arg, .{ .needed = true }); - } else if (mem.eql(u8, arg, "-weak_library") or mem.eql(u8, arg, "-weak-l")) { - try system_libs.put(args_iter.nextOrFatal(), .{ .weak = true }); - } else if (mem.eql(u8, arg, "-D")) { - try clang_argv.append(arg); - try clang_argv.append(args_iter.nextOrFatal()); - } else if (mem.eql(u8, arg, "-I")) { - try cssan.addIncludePath(.I, arg, args_iter.nextOrFatal(), false); - } else if (mem.eql(u8, arg, "-isystem") or mem.eql(u8, arg, "-iwithsysroot")) { - try cssan.addIncludePath(.isystem, arg, args_iter.nextOrFatal(), false); - } else if (mem.eql(u8, arg, "-idirafter")) { - try cssan.addIncludePath(.idirafter, arg, args_iter.nextOrFatal(), false); - } else if (mem.eql(u8, arg, "-iframework") or mem.eql(u8, arg, "-iframeworkwithsysroot")) { - try cssan.addIncludePath(.iframework, arg, args_iter.nextOrFatal(), false); } else if (mem.eql(u8, arg, "--version")) { const next_arg = args_iter.nextOrFatal(); version = std.builtin.Version.parse(next_arg) catch |err| { @@ -1467,31 +1565,6 @@ fn buildOutputType( verbose_llvm_cpu_features = true; } else if (mem.startsWith(u8, arg, "-T")) { linker_script = arg[2..]; - } else if (mem.startsWith(u8, arg, "-L")) { - try lib_dirs.append(arg[2..]); - } else if (mem.startsWith(u8, arg, "-F")) { - try framework_dirs.append(arg[2..]); - } else if (mem.startsWith(u8, arg, "-l")) { - // We don't know whether this library is part of libc or libc++ until - // we resolve the target, so we simply append to the list for now. - try system_libs.put(arg["-l".len..], .{}); - } else if (mem.startsWith(u8, arg, "-needed-l")) { - try system_libs.put(arg["-needed-l".len..], .{ .needed = true }); - } else if (mem.startsWith(u8, arg, "-weak-l")) { - try system_libs.put(arg["-weak-l".len..], .{ .weak = true }); - } else if (mem.startsWith(u8, arg, "-D")) { - try clang_argv.append(arg); - } else if (mem.startsWith(u8, arg, "-I")) { - try cssan.addIncludePath(.I, arg, arg[2..], true); - } else if (mem.eql(u8, arg, "-x")) { - const lang = args_iter.nextOrFatal(); - if (mem.eql(u8, lang, "none")) { - file_ext = null; - } else if (Compilation.LangToExt.get(lang)) |got_ext| { - file_ext = got_ext; - } else { - fatal("language not recognized: '{s}'", .{lang}); - } } else if (mem.startsWith(u8, arg, "-mexec-model=")) { wasi_exec_model = std.meta.stringToEnum(std.builtin.WasiExecModel, arg["-mexec-model=".len..]) orelse { fatal("expected [command|reactor] for -mexec-mode=[value], found '{s}'", .{arg["-mexec-model=".len..]}); @@ -1499,25 +1572,6 @@ fn buildOutputType( } else { fatal("unrecognized parameter: '{s}'", .{arg}); } - } else switch (file_ext orelse - Compilation.classifyFileExt(arg)) { - .object, .static_library, .shared_library => try link_objects.append(.{ .path = arg }), - .assembly, .assembly_with_cpp, .c, .cpp, .h, .ll, .bc, .m, .mm, .cu => { - try c_source_files.append(.{ - .src_path = arg, - .extra_flags = try arena.dupe([]const u8, extra_cflags.items), - // duped when parsing the args. - .ext = file_ext, - }); - }, - .zig => { - if (root_src_file) |other| { - fatal("found another zig file '{s}' after root source file '{s}'", .{ arg, other }); - } else root_src_file = arg; - }, - .def, .unknown => { - fatal("unrecognized file extension of parameter '{s}'", .{arg}); - }, } } if (optimize_mode_string) |s| { diff --git a/test/cases/compile_errors/add_overflow_in_function_evaluation.zig b/test/cases/compile_errors/add_overflow_in_function_evaluation.zig index 2f8a4678d365..ef1a01671161 100644 --- a/test/cases/compile_errors/add_overflow_in_function_evaluation.zig +++ b/test/cases/compile_errors/add_overflow_in_function_evaluation.zig @@ -3,7 +3,9 @@ fn add(a: u16, b: u16) u16 { return a + b; } -export fn entry() usize { return @sizeOf(@TypeOf(y)); } +export fn entry() usize { + return @sizeOf(@TypeOf(y)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/addition_with_non_numbers.zig b/test/cases/compile_errors/addition_with_non_numbers.zig index 3687df914f25..dd139c171db9 100644 --- a/test/cases/compile_errors/addition_with_non_numbers.zig +++ b/test/cases/compile_errors/addition_with_non_numbers.zig @@ -1,9 +1,11 @@ const Foo = struct { field: i32, }; -const x = Foo {.field = 1} + Foo {.field = 2}; +const x = Foo{ .field = 1 } + Foo{ .field = 2 }; -export fn entry() usize { return @sizeOf(@TypeOf(x)); } +export fn entry() usize { + return @sizeOf(@TypeOf(x)); +} // error // backend=llvm diff --git a/test/cases/compile_errors/address_of_number_literal.zig b/test/cases/compile_errors/address_of_number_literal.zig index c6b41a149558..9d3fe312a749 100644 --- a/test/cases/compile_errors/address_of_number_literal.zig +++ b/test/cases/compile_errors/address_of_number_literal.zig @@ -1,7 +1,11 @@ const x = 3; const y = &x; -fn foo() *const i32 { return y; } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +fn foo() *const i32 { + return y; +} +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/alignment_of_enum_field_specified.zig b/test/cases/compile_errors/alignment_of_enum_field_specified.zig index 14ffa6f499a2..056a64ab35e8 100644 --- a/test/cases/compile_errors/alignment_of_enum_field_specified.zig +++ b/test/cases/compile_errors/alignment_of_enum_field_specified.zig @@ -1,7 +1,4 @@ -const Number = enum { - a, - b align(i32), -}; +const Number = enum { a, b align(i32) }; export fn entry1() void { var x: Number = undefined; _ = x; diff --git a/test/cases/compile_errors/array_access_of_non_array.zig b/test/cases/compile_errors/array_access_of_non_array.zig index 06fa1569e660..9f9155c45a33 100644 --- a/test/cases/compile_errors/array_access_of_non_array.zig +++ b/test/cases/compile_errors/array_access_of_non_array.zig @@ -1,9 +1,9 @@ export fn f() void { - var bad : bool = undefined; + var bad: bool = undefined; bad[0] = bad[0]; } export fn g() void { - var bad : bool = undefined; + var bad: bool = undefined; _ = bad[0]; } diff --git a/test/cases/compile_errors/array_concatenation_with_wrong_type.zig b/test/cases/compile_errors/array_concatenation_with_wrong_type.zig index 6f2648f74b2e..5c634eceb098 100644 --- a/test/cases/compile_errors/array_concatenation_with_wrong_type.zig +++ b/test/cases/compile_errors/array_concatenation_with_wrong_type.zig @@ -2,7 +2,9 @@ const src = "aoeu"; const derp: usize = 1234; const a = derp ++ "foo"; -export fn entry() usize { return @sizeOf(@TypeOf(a)); } +export fn entry() usize { + return @sizeOf(@TypeOf(a)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/array_mult_with_number_type.zig b/test/cases/compile_errors/array_mult_with_number_type.zig index d3ec870f4e86..bd47c3b56f7b 100644 --- a/test/cases/compile_errors/array_mult_with_number_type.zig +++ b/test/cases/compile_errors/array_mult_with_number_type.zig @@ -7,4 +7,4 @@ export fn entry(base: f32, exponent: f32) f32 { // target=native // // :2:12: error: expected indexable; found 'f32' -// :2:17: note: this operator multiplies arrays; use std.math.pow for exponentiation \ No newline at end of file +// :2:17: note: this operator multiplies arrays; use std.math.pow for exponentiation diff --git a/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig b/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig index 857123eae55d..b16cb8f66e63 100644 --- a/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig +++ b/test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig @@ -2,7 +2,7 @@ export fn entry() void { var a = &b; _ = a; } -fn b() callconv(.Inline) void { } +inline fn b() void {} // error // backend=stage2 diff --git a/test/cases/compile_errors/assign_null_to_non-optional_pointer.zig b/test/cases/compile_errors/assign_null_to_non-optional_pointer.zig index ca36dbfbfbdf..cc410e62289a 100644 --- a/test/cases/compile_errors/assign_null_to_non-optional_pointer.zig +++ b/test/cases/compile_errors/assign_null_to_non-optional_pointer.zig @@ -1,6 +1,8 @@ const a: *u8 = null; -export fn entry() usize { return @sizeOf(@TypeOf(a)); } +export fn entry() usize { + return @sizeOf(@TypeOf(a)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/assign_through_constant_pointer.zig b/test/cases/compile_errors/assign_through_constant_pointer.zig index 674d0875aa6a..3e8f72d5eea6 100644 --- a/test/cases/compile_errors/assign_through_constant_pointer.zig +++ b/test/cases/compile_errors/assign_through_constant_pointer.zig @@ -1,6 +1,6 @@ export fn f() void { - var cstr = "Hat"; - cstr[0] = 'W'; + var cstr = "Hat"; + cstr[0] = 'W'; } // error diff --git a/test/cases/compile_errors/assign_through_constant_slice.zig b/test/cases/compile_errors/assign_through_constant_slice.zig index 08910b624838..83102d302d42 100644 --- a/test/cases/compile_errors/assign_through_constant_slice.zig +++ b/test/cases/compile_errors/assign_through_constant_slice.zig @@ -1,6 +1,6 @@ export fn f() void { - var cstr: []const u8 = "Hat"; - cstr[0] = 'W'; + var cstr: []const u8 = "Hat"; + cstr[0] = 'W'; } // error diff --git a/test/cases/compile_errors/assign_to_constant_field.zig b/test/cases/compile_errors/assign_to_constant_field.zig index 33f08344c4ca..c64ee9ad291e 100644 --- a/test/cases/compile_errors/assign_to_constant_field.zig +++ b/test/cases/compile_errors/assign_to_constant_field.zig @@ -2,7 +2,9 @@ const Foo = struct { field: i32, }; export fn derp() void { - const f = Foo {.field = 1234,}; + const f = Foo{ + .field = 1234, + }; f.field = 0; } diff --git a/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig b/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig index d8ab4087e0a3..82cbb4469aaf 100644 --- a/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig +++ b/test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig @@ -3,7 +3,7 @@ export fn entry() void { var bytes: [100]u8 align(16) = undefined; _ = @asyncCall(&bytes, {}, ptr, .{}); } -fn afunc() void { } +fn afunc() void {} // error // backend=stage1 diff --git a/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig b/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig index 066bf1c10787..bdf7bec45816 100644 --- a/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig +++ b/test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig @@ -21,4 +21,4 @@ fn func() void {} // // :3:28: error: expected type 'anyframe->i32', found 'anyframe' // :8:28: error: expected type 'anyframe->i32', found 'i32' -// tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)' \ No newline at end of file +// tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)' diff --git a/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig b/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig index c66d0f9cbb55..bfc22cca255d 100644 --- a/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig +++ b/test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig @@ -3,7 +3,7 @@ export fn entry() void { _ = async ptr(); } -fn afunc() callconv(.Async) void { } +fn afunc() callconv(.Async) void {} // error // backend=stage1 diff --git a/test/cases/compile_errors/bad_import.zig b/test/cases/compile_errors/bad_import.zig index e624d7104c68..521331e345e5 100644 --- a/test/cases/compile_errors/bad_import.zig +++ b/test/cases/compile_errors/bad_import.zig @@ -1,4 +1,6 @@ -const bogus = @import("bogus-does-not-exist.zig",); +const bogus = @import( + "bogus-does-not-exist.zig", +); // error // backend=stage2 diff --git a/test/cases/compile_errors/bad_usage_of_call.zig b/test/cases/compile_errors/bad_usage_of_call.zig index c0b632bef660..2350b19ce353 100644 --- a/test/cases/compile_errors/bad_usage_of_call.zig +++ b/test/cases/compile_errors/bad_usage_of_call.zig @@ -19,7 +19,7 @@ pub export fn entry() void { @call(.always_inline, call_me, .{}); } fn foo() void {} -fn bar() callconv(.Inline) void {} +inline fn bar() void {} fn baz1() void {} fn baz2() void {} @@ -33,4 +33,3 @@ fn baz2() void {} // :11:5: error: no-inline call of inline function // :15:26: error: modifier 'compile_time' requires a comptime-known function // :19:27: error: modifier 'always_inline' requires a comptime-known function - diff --git a/test/cases/compile_errors/binary_not_on_number_literal.zig b/test/cases/compile_errors/binary_not_on_number_literal.zig index cb57ca9ee151..455b79130a59 100644 --- a/test/cases/compile_errors/binary_not_on_number_literal.zig +++ b/test/cases/compile_errors/binary_not_on_number_literal.zig @@ -2,7 +2,9 @@ const TINY_QUANTUM_SHIFT = 4; const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); -export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); } +export fn entry() usize { + return @sizeOf(@TypeOf(block_aligned_stuff)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/bogus_compile_var.zig b/test/cases/compile_errors/bogus_compile_var.zig index be222e539349..4780423caecf 100644 --- a/test/cases/compile_errors/bogus_compile_var.zig +++ b/test/cases/compile_errors/bogus_compile_var.zig @@ -1,5 +1,7 @@ const x = @import("builtin").bogus; -export fn entry() usize { return @sizeOf(@TypeOf(x)); } +export fn entry() usize { + return @sizeOf(@TypeOf(x)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/bogus_method_call_on_slice.zig b/test/cases/compile_errors/bogus_method_call_on_slice.zig index ed18f43f48bf..76d0d90644f0 100644 --- a/test/cases/compile_errors/bogus_method_call_on_slice.zig +++ b/test/cases/compile_errors/bogus_method_call_on_slice.zig @@ -2,7 +2,9 @@ var self = "aoeu"; fn f(m: []const u8) void { m.copy(u8, self[0..], m); } -export fn entry() usize { return @sizeOf(@TypeOf(&f)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&f)); +} pub export fn entry1() void { .{}.bar(); } diff --git a/test/cases/compile_errors/branch_on_undefined_value.zig b/test/cases/compile_errors/branch_on_undefined_value.zig index a0a3be83cfa4..fc30fe7d3c93 100644 --- a/test/cases/compile_errors/branch_on_undefined_value.zig +++ b/test/cases/compile_errors/branch_on_undefined_value.zig @@ -1,6 +1,8 @@ const x = if (undefined) true else false; -export fn entry() usize { return @sizeOf(@TypeOf(x)); } +export fn entry() usize { + return @sizeOf(@TypeOf(x)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig b/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig index 54bf58542542..2bd0364d4f8e 100644 --- a/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig +++ b/test/cases/compile_errors/calling_function_with_naked_calling_convention.zig @@ -1,7 +1,7 @@ export fn entry() void { foo(); } -fn foo() callconv(.Naked) void { } +fn foo() callconv(.Naked) void {} // error // backend=llvm diff --git a/test/cases/compile_errors/calling_var_args_extern_function_passing_array_instead_of_pointer.zig b/test/cases/compile_errors/calling_var_args_extern_function_passing_array_instead_of_pointer.zig index c9e2e2e5eb82..3b9e1ca8eb64 100644 --- a/test/cases/compile_errors/calling_var_args_extern_function_passing_array_instead_of_pointer.zig +++ b/test/cases/compile_errors/calling_var_args_extern_function_passing_array_instead_of_pointer.zig @@ -1,5 +1,7 @@ export fn entry() void { - foo("hello".*,); + foo( + "hello".*, + ); } pub extern fn foo(format: *const u8, ...) void; diff --git a/test/cases/compile_errors/cast_unreachable.zig b/test/cases/compile_errors/cast_unreachable.zig index cf2331ff7e5f..39da655d7fe1 100644 --- a/test/cases/compile_errors/cast_unreachable.zig +++ b/test/cases/compile_errors/cast_unreachable.zig @@ -1,7 +1,9 @@ fn f() i32 { return @as(i32, return 1); } -export fn entry() void { _ = f(); } +export fn entry() void { + _ = f(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/casting_bit_offset_pointer_to_regular_pointer.zig b/test/cases/compile_errors/casting_bit_offset_pointer_to_regular_pointer.zig index f9df19802ade..8cf62c8ec0d8 100644 --- a/test/cases/compile_errors/casting_bit_offset_pointer_to_regular_pointer.zig +++ b/test/cases/compile_errors/casting_bit_offset_pointer_to_regular_pointer.zig @@ -12,7 +12,9 @@ fn bar(x: *const u3) u3 { return x.*; } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/colliding_invalid_top_level_functions.zig b/test/cases/compile_errors/colliding_invalid_top_level_functions.zig index ee0711088d92..8a2adb2f0778 100644 --- a/test/cases/compile_errors/colliding_invalid_top_level_functions.zig +++ b/test/cases/compile_errors/colliding_invalid_top_level_functions.zig @@ -1,6 +1,8 @@ fn func() bogus {} fn func() bogus {} -export fn entry() usize { return @sizeOf(@TypeOf(func)); } +export fn entry() usize { + return @sizeOf(@TypeOf(func)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/compileError_shows_traceback_of_references_that_caused_it.zig b/test/cases/compile_errors/compileError_shows_traceback_of_references_that_caused_it.zig index 092cbbd40034..d5206671fba8 100644 --- a/test/cases/compile_errors/compileError_shows_traceback_of_references_that_caused_it.zig +++ b/test/cases/compile_errors/compileError_shows_traceback_of_references_that_caused_it.zig @@ -1,4 +1,6 @@ -const foo = @compileError("aoeu",); +const foo = @compileError( + "aoeu", +); const bar = baz + foo; const baz = 1; diff --git a/test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig b/test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig index 55676f923064..9f4515d9b44c 100644 --- a/test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig +++ b/test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig @@ -1,13 +1,11 @@ -const Bar = union(enum(u32)) { - X: i32 = 1 -}; +const Bar = union(enum(u32)) { X: i32 = 1 }; fn testCompileLog(x: Bar) void { @compileLog(x); } pub export fn entry() void { - comptime testCompileLog(Bar{.X = 123}); + comptime testCompileLog(Bar{ .X = 123 }); } // error diff --git a/test/cases/compile_errors/compile_log.zig b/test/cases/compile_errors/compile_log.zig index e1ea460dc352..35e0639cede0 100644 --- a/test/cases/compile_errors/compile_log.zig +++ b/test/cases/compile_errors/compile_log.zig @@ -1,10 +1,17 @@ export fn foo() void { - comptime bar(12, "hi",); + comptime bar( + 12, + "hi", + ); } fn bar(a: i32, b: []const u8) void { - @compileLog("begin",); + @compileLog( + "begin", + ); @compileLog("a", a, "b", b); - @compileLog("end",); + @compileLog( + "end", + ); } export fn baz() void { const S = struct { a: u32 }; diff --git a/test/cases/compile_errors/compile_log_statement_warning_deduplication_in_generic_fn.zig b/test/cases/compile_errors/compile_log_statement_warning_deduplication_in_generic_fn.zig index 4b31d9924a5c..6f1ebcf889b7 100644 --- a/test/cases/compile_errors/compile_log_statement_warning_deduplication_in_generic_fn.zig +++ b/test/cases/compile_errors/compile_log_statement_warning_deduplication_in_generic_fn.zig @@ -4,7 +4,9 @@ export fn entry() void { } fn inner(comptime n: usize) void { comptime var i = 0; - inline while (i < n) : (i += 1) { @compileLog("!@#$"); } + inline while (i < n) : (i += 1) { + @compileLog("!@#$"); + } } // error diff --git a/test/cases/compile_errors/compile_time_division_by_zero.zig b/test/cases/compile_errors/compile_time_division_by_zero.zig index 281ccf28a1d4..8954ace9ab1e 100644 --- a/test/cases/compile_errors/compile_time_division_by_zero.zig +++ b/test/cases/compile_errors/compile_time_division_by_zero.zig @@ -3,7 +3,9 @@ fn foo(x: u32) u32 { return 1 / x; } -export fn entry() usize { return @sizeOf(@TypeOf(y)); } +export fn entry() usize { + return @sizeOf(@TypeOf(y)); +} // error // backend=llvm diff --git a/test/cases/compile_errors/comptime_if_inside_runtime_for.zig b/test/cases/compile_errors/comptime_if_inside_runtime_for.zig index 6200776d1892..1902058fc525 100644 --- a/test/cases/compile_errors/comptime_if_inside_runtime_for.zig +++ b/test/cases/compile_errors/comptime_if_inside_runtime_for.zig @@ -1,9 +1,9 @@ export fn entry() void { - var x: u32 = 0; - for(0..1, 1..2) |_, _| { - var y = x + if(x == 0) 1 else 0; - _ = y; - } + var x: u32 = 0; + for (0..1, 1..2) |_, _| { + var y = x + if (x == 0) 1 else 0; + _ = y; + } } // error diff --git a/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig b/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig index 2b67390b05b2..1ce744d6d7e0 100644 --- a/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig +++ b/test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig @@ -1,7 +1,9 @@ const ContextAllocator = MemoryPool(usize); pub fn MemoryPool(comptime T: type) type { - const free_list_t = @compileError("aoeu",); + const free_list_t = @compileError( + "aoeu", + ); _ = T; return struct { diff --git a/test/cases/compile_errors/container_init_with_non-type.zig b/test/cases/compile_errors/container_init_with_non-type.zig index aa62be6dc5a0..7bdf07a1cefe 100644 --- a/test/cases/compile_errors/container_init_with_non-type.zig +++ b/test/cases/compile_errors/container_init_with_non-type.zig @@ -1,7 +1,9 @@ const zero: i32 = 0; const a = zero{1}; -export fn entry() usize { return @sizeOf(@TypeOf(a)); } +export fn entry() usize { + return @sizeOf(@TypeOf(a)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/control_flow_uses_comptime_var_at_runtime.zig b/test/cases/compile_errors/control_flow_uses_comptime_var_at_runtime.zig index a8058e8c758d..5283239af6a7 100644 --- a/test/cases/compile_errors/control_flow_uses_comptime_var_at_runtime.zig +++ b/test/cases/compile_errors/control_flow_uses_comptime_var_at_runtime.zig @@ -5,7 +5,7 @@ export fn foo() void { } } -fn bar() void { } +fn bar() void {} export fn baz() void { comptime var idx: u32 = 0; while (idx < 1) { diff --git a/test/cases/compile_errors/dereference_an_array.zig b/test/cases/compile_errors/dereference_an_array.zig index f5aabf081c5a..27e4d81e5550 100644 --- a/test/cases/compile_errors/dereference_an_array.zig +++ b/test/cases/compile_errors/dereference_an_array.zig @@ -5,7 +5,9 @@ pub fn pass(in: []u8) []u8 { return out.*[0..1]; } -export fn entry() usize { return @sizeOf(@TypeOf(&pass)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&pass)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/direct_struct_loop.zig b/test/cases/compile_errors/direct_struct_loop.zig index 0abc1a4f73b0..6009471fc011 100644 --- a/test/cases/compile_errors/direct_struct_loop.zig +++ b/test/cases/compile_errors/direct_struct_loop.zig @@ -1,5 +1,9 @@ -const A = struct { a : A, }; -export fn entry() usize { return @sizeOf(A); } +const A = struct { + a: A, +}; +export fn entry() usize { + return @sizeOf(A); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig b/test/cases/compile_errors/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig index 3670def4eec8..45fa4c14f5e8 100644 --- a/test/cases/compile_errors/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig +++ b/test/cases/compile_errors/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig @@ -1,6 +1,6 @@ extern fn puts(s: [*:0]const u8) c_int; pub export fn entry() void { - const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; + const no_zero_array = [_]u8{ 'h', 'e', 'l', 'l', 'o' }; const no_zero_ptr: [*]const u8 = &no_zero_array; _ = puts(no_zero_ptr); } diff --git a/test/cases/compile_errors/division_by_zero.zig b/test/cases/compile_errors/division_by_zero.zig index 2e2f7e2be2a7..3019554fb83a 100644 --- a/test/cases/compile_errors/division_by_zero.zig +++ b/test/cases/compile_errors/division_by_zero.zig @@ -3,10 +3,18 @@ const lit_float_x = 1.0 / 0.0; const int_x = @as(u32, 1) / @as(u32, 0); const float_x = @as(f32, 1.0) / @as(f32, 0.0); -export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } -export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } -export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } -export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } // no error on purpose +export fn entry1() usize { + return @sizeOf(@TypeOf(lit_int_x)); +} +export fn entry2() usize { + return @sizeOf(@TypeOf(lit_float_x)); +} +export fn entry3() usize { + return @sizeOf(@TypeOf(int_x)); +} +export fn entry4() usize { + return @sizeOf(@TypeOf(float_x)); +} // no error on purpose // error // backend=stage2 diff --git a/test/cases/compile_errors/duplicate-unused_labels.zig b/test/cases/compile_errors/duplicate-unused_labels.zig index 4bfc6c596012..8fd220b4bc17 100644 --- a/test/cases/compile_errors/duplicate-unused_labels.zig +++ b/test/cases/compile_errors/duplicate-unused_labels.zig @@ -1,20 +1,26 @@ comptime { - blk: { blk: while (false) {} } + blk: { + blk: while (false) {} + } } comptime { - blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } + blk: while (false) { + blk: for (@as([0]void, undefined)) |_| {} + } } comptime { - blk: for (@as([0]void, undefined)) |_| { blk: {} } + blk: for (@as([0]void, undefined)) |_| { + blk: {} + } } comptime { blk: {} } comptime { - blk: while(false) {} + blk: while (false) {} } comptime { - blk: for(@as([0]void, undefined)) |_| {} + blk: for (@as([0]void, undefined)) |_| {} } // error diff --git a/test/cases/compile_errors/duplicate_error_value_in_error_set.zig b/test/cases/compile_errors/duplicate_error_value_in_error_set.zig index 5e9cddb975d8..927537d952ce 100644 --- a/test/cases/compile_errors/duplicate_error_value_in_error_set.zig +++ b/test/cases/compile_errors/duplicate_error_value_in_error_set.zig @@ -1,4 +1,4 @@ -const Foo = error { +const Foo = error{ Bar, Bar, }; diff --git a/test/cases/compile_errors/duplicate_field_in_struct_value_expression.zig b/test/cases/compile_errors/duplicate_field_in_struct_value_expression.zig index fa5bc6fb4e31..eda001c086cb 100644 --- a/test/cases/compile_errors/duplicate_field_in_struct_value_expression.zig +++ b/test/cases/compile_errors/duplicate_field_in_struct_value_expression.zig @@ -1,10 +1,10 @@ const A = struct { - x : i32, - y : i32, - z : i32, + x: i32, + y: i32, + z: i32, }; export fn f() void { - const a = A { + const a = A{ .z = 1, .y = 2, .x = 3, diff --git a/test/cases/compile_errors/embedFile_with_bogus_file.zig b/test/cases/compile_errors/embedFile_with_bogus_file.zig index fa05d1ed4909..232f9721cc83 100644 --- a/test/cases/compile_errors/embedFile_with_bogus_file.zig +++ b/test/cases/compile_errors/embedFile_with_bogus_file.zig @@ -1,6 +1,10 @@ -const resource = @embedFile("bogus.txt",); +const resource = @embedFile( + "bogus.txt", +); -export fn entry() usize { return @sizeOf(@TypeOf(resource)); } +export fn entry() usize { + return @sizeOf(@TypeOf(resource)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/empty_switch_on_an_integer.zig b/test/cases/compile_errors/empty_switch_on_an_integer.zig index de4d7e9c652d..6ba69f8d3e87 100644 --- a/test/cases/compile_errors/empty_switch_on_an_integer.zig +++ b/test/cases/compile_errors/empty_switch_on_an_integer.zig @@ -1,6 +1,6 @@ export fn entry() void { var x: u32 = 0; - switch(x) {} + switch (x) {} } // error diff --git a/test/cases/compile_errors/enum_with_declarations_unavailable_for_reify_type.zig b/test/cases/compile_errors/enum_with_declarations_unavailable_for_reify_type.zig index f23718c2ca57..fb55a733e522 100644 --- a/test/cases/compile_errors/enum_with_declarations_unavailable_for_reify_type.zig +++ b/test/cases/compile_errors/enum_with_declarations_unavailable_for_reify_type.zig @@ -1,5 +1,8 @@ export fn entry() void { - _ = @Type(@typeInfo(enum { foo, const bar = 1; })); + _ = @Type(@typeInfo(enum { + foo, + const bar = 1; + })); } // error diff --git a/test/cases/compile_errors/error_not_handled_in_switch.zig b/test/cases/compile_errors/error_not_handled_in_switch.zig index 8f0d26a4a92b..04f122b11d24 100644 --- a/test/cases/compile_errors/error_not_handled_in_switch.zig +++ b/test/cases/compile_errors/error_not_handled_in_switch.zig @@ -5,9 +5,9 @@ export fn entry() void { } fn foo(x: i32) !void { switch (x) { - 0 ... 10 => return error.Foo, - 11 ... 20 => return error.Bar, - 21 ... 30 => return error.Baz, + 0...10 => return error.Foo, + 11...20 => return error.Bar, + 21...30 => return error.Baz, else => {}, } } diff --git a/test/cases/compile_errors/error_note_for_function_parameter_incompatibility.zig b/test/cases/compile_errors/error_note_for_function_parameter_incompatibility.zig index 76543697a42d..3fb9cc61bdf9 100644 --- a/test/cases/compile_errors/error_note_for_function_parameter_incompatibility.zig +++ b/test/cases/compile_errors/error_note_for_function_parameter_incompatibility.zig @@ -1,5 +1,9 @@ -fn do_the_thing(func: *const fn (arg: i32) void) void { _ = func; } -fn bar(arg: bool) void { _ = arg; } +fn do_the_thing(func: *const fn (arg: i32) void) void { + _ = func; +} +fn bar(arg: bool) void { + _ = arg; +} export fn entry() void { do_the_thing(bar); } diff --git a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig index 22fc965769e5..1d029f09dbe2 100644 --- a/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig +++ b/test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig @@ -1,5 +1,5 @@ -const Set1 = error {A, B}; -const Set2 = error {A, C}; +const Set1 = error{ A, B }; +const Set2 = error{ A, C }; comptime { var x = Set1.B; var y = @errSetCast(Set2, x); diff --git a/test/cases/compile_errors/export_function_with_comptime_parameter.zig b/test/cases/compile_errors/export_function_with_comptime_parameter.zig index 4491a98e9cb0..8d5dbef1c36c 100644 --- a/test/cases/compile_errors/export_function_with_comptime_parameter.zig +++ b/test/cases/compile_errors/export_function_with_comptime_parameter.zig @@ -1,4 +1,4 @@ -export fn foo(comptime x: anytype, y: i32) i32{ +export fn foo(comptime x: anytype, y: i32) i32 { return x + y; } diff --git a/test/cases/compile_errors/export_with_empty_name_string.zig b/test/cases/compile_errors/export_with_empty_name_string.zig index f199c2632c05..9f3b215bc216 100644 --- a/test/cases/compile_errors/export_with_empty_name_string.zig +++ b/test/cases/compile_errors/export_with_empty_name_string.zig @@ -1,4 +1,4 @@ -pub export fn entry() void { } +pub export fn entry() void {} comptime { @export(entry, .{ .name = "" }); } diff --git a/test/cases/compile_errors/extern_function_pointer_mismatch.zig b/test/cases/compile_errors/extern_function_pointer_mismatch.zig index f10a3dbdb3b9..383784f8f294 100644 --- a/test/cases/compile_errors/extern_function_pointer_mismatch.zig +++ b/test/cases/compile_errors/extern_function_pointer_mismatch.zig @@ -1,9 +1,17 @@ -const fns = [_](fn(i32)i32) { a, b, c }; -pub fn a(x: i32) i32 {return x + 0;} -pub fn b(x: i32) i32 {return x + 1;} -export fn c(x: i32) i32 {return x + 2;} +const fns = [_](fn (i32) i32){ a, b, c }; +pub fn a(x: i32) i32 { + return x + 0; +} +pub fn b(x: i32) i32 { + return x + 1; +} +export fn c(x: i32) i32 { + return x + 2; +} -export fn entry() usize { return @sizeOf(@TypeOf(fns)); } +export fn entry() usize { + return @sizeOf(@TypeOf(fns)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/extern_function_with_comptime_parameter.zig b/test/cases/compile_errors/extern_function_with_comptime_parameter.zig index 58f15f7fab53..2b27082503f5 100644 --- a/test/cases/compile_errors/extern_function_with_comptime_parameter.zig +++ b/test/cases/compile_errors/extern_function_with_comptime_parameter.zig @@ -4,9 +4,15 @@ fn f() i32 { } pub extern fn entry1(b: u32, comptime a: [2]u8, c: i32) void; pub extern fn entry2(b: u32, noalias a: anytype, i43) void; -comptime { _ = f; } -comptime { _ = entry1; } -comptime { _ = entry2; } +comptime { + _ = f; +} +comptime { + _ = entry1; +} +comptime { + _ = entry2; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig b/test/cases/compile_errors/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig index 6484e301a9cc..897d226c4d08 100644 --- a/test/cases/compile_errors/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig +++ b/test/cases/compile_errors/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig @@ -1,32 +1,4 @@ -pub const E = enum { -@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", -@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", -@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34", -@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45", -@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56", -@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67", -@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78", -@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89", -@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100", -@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109", -@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118", -@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127", -@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136", -@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145", -@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154", -@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163", -@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172", -@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181", -@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190", -@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199", -@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208", -@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217", -@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226", -@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235", -@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244", -@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253", -@"254",@"255", @"256" -}; +pub const E = enum { @"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30", @"31", @"32", @"33", @"34", @"35", @"36", @"37", @"38", @"39", @"40", @"41", @"42", @"43", @"44", @"45", @"46", @"47", @"48", @"49", @"50", @"51", @"52", @"53", @"54", @"55", @"56", @"57", @"58", @"59", @"60", @"61", @"62", @"63", @"64", @"65", @"66", @"67", @"68", @"69", @"70", @"71", @"72", @"73", @"74", @"75", @"76", @"77", @"78", @"79", @"80", @"81", @"82", @"83", @"84", @"85", @"86", @"87", @"88", @"89", @"90", @"91", @"92", @"93", @"94", @"95", @"96", @"97", @"98", @"99", @"100", @"101", @"102", @"103", @"104", @"105", @"106", @"107", @"108", @"109", @"110", @"111", @"112", @"113", @"114", @"115", @"116", @"117", @"118", @"119", @"120", @"121", @"122", @"123", @"124", @"125", @"126", @"127", @"128", @"129", @"130", @"131", @"132", @"133", @"134", @"135", @"136", @"137", @"138", @"139", @"140", @"141", @"142", @"143", @"144", @"145", @"146", @"147", @"148", @"149", @"150", @"151", @"152", @"153", @"154", @"155", @"156", @"157", @"158", @"159", @"160", @"161", @"162", @"163", @"164", @"165", @"166", @"167", @"168", @"169", @"170", @"171", @"172", @"173", @"174", @"175", @"176", @"177", @"178", @"179", @"180", @"181", @"182", @"183", @"184", @"185", @"186", @"187", @"188", @"189", @"190", @"191", @"192", @"193", @"194", @"195", @"196", @"197", @"198", @"199", @"200", @"201", @"202", @"203", @"204", @"205", @"206", @"207", @"208", @"209", @"210", @"211", @"212", @"213", @"214", @"215", @"216", @"217", @"218", @"219", @"220", @"221", @"222", @"223", @"224", @"225", @"226", @"227", @"228", @"229", @"230", @"231", @"232", @"233", @"234", @"235", @"236", @"237", @"238", @"239", @"240", @"241", @"242", @"243", @"244", @"245", @"246", @"247", @"248", @"249", @"250", @"251", @"252", @"253", @"254", @"255", @"256" }; pub const S = extern struct { e: E, }; diff --git a/test/cases/compile_errors/extern_union_field_missing_type.zig b/test/cases/compile_errors/extern_union_field_missing_type.zig index 6890e65714c4..fde58f69e5e2 100644 --- a/test/cases/compile_errors/extern_union_field_missing_type.zig +++ b/test/cases/compile_errors/extern_union_field_missing_type.zig @@ -2,7 +2,7 @@ const Letter = extern union { A, }; export fn entry() void { - var a = Letter { .A = {} }; + var a = Letter{ .A = {} }; _ = a; } diff --git a/test/cases/compile_errors/extern_union_given_enum_tag_type.zig b/test/cases/compile_errors/extern_union_given_enum_tag_type.zig index 6a691eb2e2f5..4aa0e623c796 100644 --- a/test/cases/compile_errors/extern_union_given_enum_tag_type.zig +++ b/test/cases/compile_errors/extern_union_given_enum_tag_type.zig @@ -9,7 +9,7 @@ const Payload = extern union(Letter) { C: bool, }; export fn entry() void { - var a = Payload { .A = 1234 }; + var a = Payload{ .A = 1234 }; _ = a; } diff --git a/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig b/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig index 7f57268f0645..ea21ad6095d7 100644 --- a/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig +++ b/test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig @@ -2,7 +2,10 @@ const Foo = struct { a: i32, b: i32, }; -const foo = Foo { .a = 1, .b = 2, }; +const foo = Foo{ + .a = 1, + .b = 2, +}; comptime { const field_ptr = @intToPtr(*i32, 0x1234); diff --git a/test/cases/compile_errors/fieldParentPtr-comptime_wrong_field_index.zig b/test/cases/compile_errors/fieldParentPtr-comptime_wrong_field_index.zig index a73409aea336..d912ed99436c 100644 --- a/test/cases/compile_errors/fieldParentPtr-comptime_wrong_field_index.zig +++ b/test/cases/compile_errors/fieldParentPtr-comptime_wrong_field_index.zig @@ -2,7 +2,10 @@ const Foo = struct { a: i32, b: i32, }; -const foo = Foo { .a = 1, .b = 2, }; +const foo = Foo{ + .a = 1, + .b = 2, +}; comptime { const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); diff --git a/test/cases/compile_errors/for.zig b/test/cases/compile_errors/for.zig index 5bd3aa0c646f..c9f995487802 100644 --- a/test/cases/compile_errors/for.zig +++ b/test/cases/compile_errors/for.zig @@ -1,13 +1,15 @@ export fn a() void { for (0..10, 10..21) |i, j| { - _ = i; _ = j; + _ = i; + _ = j; } } export fn b() void { const s1 = "hello"; const s2 = true; for (s1, s2) |i, j| { - _ = i; _ = j; + _ = i; + _ = j; } } export fn c() void { @@ -20,7 +22,9 @@ export fn d() void { const x: [*]const u8 = "hello"; const y: [*]const u8 = "world"; for (x, 0.., y) |x1, x2, x3| { - _ = x1; _ = x2; _ = x3; + _ = x1; + _ = x2; + _ = x3; } } diff --git a/test/cases/compile_errors/for_extra_capture.zig b/test/cases/compile_errors/for_extra_capture.zig index a137b57d5152..33267d4c4b9a 100644 --- a/test/cases/compile_errors/for_extra_capture.zig +++ b/test/cases/compile_errors/for_extra_capture.zig @@ -1,6 +1,7 @@ export fn b() void { - for (0..10) |i, j| { - _ = i; _ = j; + for (0..10, 0..) |i, j| { + _ = i; + _ = j; } } diff --git a/test/cases/compile_errors/function_alignment_non_power_of_2.zig b/test/cases/compile_errors/function_alignment_non_power_of_2.zig index 11d6768dfd0c..e40ca022d2c1 100644 --- a/test/cases/compile_errors/function_alignment_non_power_of_2.zig +++ b/test/cases/compile_errors/function_alignment_non_power_of_2.zig @@ -1,5 +1,7 @@ extern fn foo() align(3) void; -export fn entry() void { return foo(); } +export fn entry() void { + return foo(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/function_call_assigned_to_incorrect_type.zig b/test/cases/compile_errors/function_call_assigned_to_incorrect_type.zig index fcbfabe2978a..1060987b9a19 100644 --- a/test/cases/compile_errors/function_call_assigned_to_incorrect_type.zig +++ b/test/cases/compile_errors/function_call_assigned_to_incorrect_type.zig @@ -3,7 +3,7 @@ export fn entry() void { arr = concat(); } fn concat() [16]f32 { - return [1]f32{0}**16; + return [1]f32{0} ** 16; } // error diff --git a/test/cases/compile_errors/function_parameter_is_opaque.zig b/test/cases/compile_errors/function_parameter_is_opaque.zig index 57c89bd7f47f..4f5d7f94fc29 100644 --- a/test/cases/compile_errors/function_parameter_is_opaque.zig +++ b/test/cases/compile_errors/function_parameter_is_opaque.zig @@ -9,12 +9,16 @@ export fn entry2() void { _ = someFuncPtr; } -fn foo(p: FooType) void {_ = p;} +fn foo(p: FooType) void { + _ = p; +} export fn entry3() void { _ = foo; } -fn bar(p: @TypeOf(null)) void {_ = p;} +fn bar(p: @TypeOf(null)) void { + _ = p; +} export fn entry4() void { _ = bar; } diff --git a/test/cases/compile_errors/function_with_non-extern_non-packed_enum_parameter.zig b/test/cases/compile_errors/function_with_non-extern_non-packed_enum_parameter.zig index 572378d09322..3945c5b0f01f 100644 --- a/test/cases/compile_errors/function_with_non-extern_non-packed_enum_parameter.zig +++ b/test/cases/compile_errors/function_with_non-extern_non-packed_enum_parameter.zig @@ -1,5 +1,7 @@ const Foo = enum { A, B, C }; -export fn entry(foo: Foo) void { _ = foo; } +export fn entry(foo: Foo) void { + _ = foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/function_with_non-extern_non-packed_struct_parameter.zig b/test/cases/compile_errors/function_with_non-extern_non-packed_struct_parameter.zig index 55ee27764112..137037f9e747 100644 --- a/test/cases/compile_errors/function_with_non-extern_non-packed_struct_parameter.zig +++ b/test/cases/compile_errors/function_with_non-extern_non-packed_struct_parameter.zig @@ -3,7 +3,9 @@ const Foo = struct { B: f32, C: bool, }; -export fn entry(foo: Foo) void { _ = foo; } +export fn entry(foo: Foo) void { + _ = foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/function_with_non-extern_non-packed_union_parameter.zig b/test/cases/compile_errors/function_with_non-extern_non-packed_union_parameter.zig index f848392c9092..d651329f72f8 100644 --- a/test/cases/compile_errors/function_with_non-extern_non-packed_union_parameter.zig +++ b/test/cases/compile_errors/function_with_non-extern_non-packed_union_parameter.zig @@ -3,7 +3,9 @@ const Foo = union { B: f32, C: bool, }; -export fn entry(foo: Foo) void { _ = foo; } +export fn entry(foo: Foo) void { + _ = foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/generic_function_call_assigned_to_incorrect_type.zig b/test/cases/compile_errors/generic_function_call_assigned_to_incorrect_type.zig index a2e303670d6d..4ff284128284 100644 --- a/test/cases/compile_errors/generic_function_call_assigned_to_incorrect_type.zig +++ b/test/cases/compile_errors/generic_function_call_assigned_to_incorrect_type.zig @@ -2,7 +2,7 @@ pub export fn entry() void { var res: []i32 = undefined; res = myAlloc(i32); } -fn myAlloc(comptime arg: type) anyerror!arg{ +fn myAlloc(comptime arg: type) anyerror!arg { unreachable; } diff --git a/test/cases/compile_errors/generic_function_instance_with_non-constant_expression.zig b/test/cases/compile_errors/generic_function_instance_with_non-constant_expression.zig index 1317c4376a83..7ec82ee46daa 100644 --- a/test/cases/compile_errors/generic_function_instance_with_non-constant_expression.zig +++ b/test/cases/compile_errors/generic_function_instance_with_non-constant_expression.zig @@ -1,9 +1,13 @@ -fn foo(comptime x: i32, y: i32) i32 { return x + y; } +fn foo(comptime x: i32, y: i32) i32 { + return x + y; +} fn test1(a: i32, b: i32) i32 { return foo(a, b); } -export fn entry() usize { return @sizeOf(@TypeOf(&test1)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&test1)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig b/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig index 3146c3860403..c730f80e6f42 100644 --- a/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig +++ b/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig @@ -6,7 +6,6 @@ pub export fn entry() void { } fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {} - // error // backend=llvm // target=native diff --git a/test/cases/compile_errors/global_variable_alignment_non_power_of_2.zig b/test/cases/compile_errors/global_variable_alignment_non_power_of_2.zig index b88d8aaf701c..5110e41334b8 100644 --- a/test/cases/compile_errors/global_variable_alignment_non_power_of_2.zig +++ b/test/cases/compile_errors/global_variable_alignment_non_power_of_2.zig @@ -1,5 +1,7 @@ const some_data: [100]u8 align(3) = undefined; -export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } +export fn entry() usize { + return @sizeOf(@TypeOf(some_data)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/global_variable_initializer_must_be_constant_expression.zig b/test/cases/compile_errors/global_variable_initializer_must_be_constant_expression.zig index e2694343e825..a87f62839660 100644 --- a/test/cases/compile_errors/global_variable_initializer_must_be_constant_expression.zig +++ b/test/cases/compile_errors/global_variable_initializer_must_be_constant_expression.zig @@ -1,6 +1,8 @@ extern fn foo() i32; const x = foo(); -export fn entry() i32 { return x; } +export fn entry() i32 { + return x; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/ignored_assert-err-ok_return_value.zig b/test/cases/compile_errors/ignored_assert-err-ok_return_value.zig index 39657badd479..1257636622da 100644 --- a/test/cases/compile_errors/ignored_assert-err-ok_return_value.zig +++ b/test/cases/compile_errors/ignored_assert-err-ok_return_value.zig @@ -1,7 +1,9 @@ export fn foo() void { bar() catch unreachable; } -fn bar() anyerror!i32 { return 0; } +fn bar() anyerror!i32 { + return 0; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/ignored_comptime_statement_value.zig b/test/cases/compile_errors/ignored_comptime_statement_value.zig index fc6cdfdd28fe..99b43dea0016 100644 --- a/test/cases/compile_errors/ignored_comptime_statement_value.zig +++ b/test/cases/compile_errors/ignored_comptime_statement_value.zig @@ -1,5 +1,7 @@ export fn foo() void { - comptime {1;} + comptime { + 1; + } } // error diff --git a/test/cases/compile_errors/ignored_deferred_function_call.zig b/test/cases/compile_errors/ignored_deferred_function_call.zig index b318baa16cb5..9537255d3304 100644 --- a/test/cases/compile_errors/ignored_deferred_function_call.zig +++ b/test/cases/compile_errors/ignored_deferred_function_call.zig @@ -1,7 +1,9 @@ export fn foo() void { defer bar(); } -fn bar() anyerror!i32 { return 0; } +fn bar() anyerror!i32 { + return 0; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/ignored_deferred_statement_value.zig b/test/cases/compile_errors/ignored_deferred_statement_value.zig index 9a270497afc9..1319414e5974 100644 --- a/test/cases/compile_errors/ignored_deferred_statement_value.zig +++ b/test/cases/compile_errors/ignored_deferred_statement_value.zig @@ -1,5 +1,7 @@ export fn foo() void { - defer {1;} + defer { + 1; + } } // error diff --git a/test/cases/compile_errors/ignored_return_value.zig b/test/cases/compile_errors/ignored_return_value.zig index 57f859e3d375..08424c4fe9fc 100644 --- a/test/cases/compile_errors/ignored_return_value.zig +++ b/test/cases/compile_errors/ignored_return_value.zig @@ -1,7 +1,9 @@ export fn foo() void { bar(); } -fn bar() i32 { return 0; } +fn bar() i32 { + return 0; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/illegal_comparison_of_types.zig b/test/cases/compile_errors/illegal_comparison_of_types.zig index 69d7a28fa44f..5720aa05cc87 100644 --- a/test/cases/compile_errors/illegal_comparison_of_types.zig +++ b/test/cases/compile_errors/illegal_comparison_of_types.zig @@ -9,8 +9,12 @@ fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool { return a.* == b.*; } -export fn entry1() usize { return @sizeOf(@TypeOf(&bad_eql_1)); } -export fn entry2() usize { return @sizeOf(@TypeOf(&bad_eql_2)); } +export fn entry1() usize { + return @sizeOf(@TypeOf(&bad_eql_1)); +} +export fn entry2() usize { + return @sizeOf(@TypeOf(&bad_eql_2)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/implicit_cast_from_array_to_mutable_slice.zig b/test/cases/compile_errors/implicit_cast_from_array_to_mutable_slice.zig index e7ae5d72770a..74e52f7a0b03 100644 --- a/test/cases/compile_errors/implicit_cast_from_array_to_mutable_slice.zig +++ b/test/cases/compile_errors/implicit_cast_from_array_to_mutable_slice.zig @@ -1,5 +1,7 @@ var global_array: [10]i32 = undefined; -fn foo(param: []i32) void {_ = param;} +fn foo(param: []i32) void { + _ = param; +} export fn entry() void { foo(global_array); } diff --git a/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig b/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig index 0a182343b99a..2874fdf1d19d 100644 --- a/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig +++ b/test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig @@ -1,5 +1,5 @@ -const Set1 = error{A, B}; -const Set2 = error{A, C}; +const Set1 = error{ A, B }; +const Set2 = error{ A, C }; export fn entry() void { foo(Set1.B); } diff --git a/test/cases/compile_errors/implicitly_increasing_pointer_alignment.zig b/test/cases/compile_errors/implicitly_increasing_pointer_alignment.zig index 13adba1b9140..fcecfa861117 100644 --- a/test/cases/compile_errors/implicitly_increasing_pointer_alignment.zig +++ b/test/cases/compile_errors/implicitly_increasing_pointer_alignment.zig @@ -4,7 +4,7 @@ const Foo = packed struct { }; export fn entry() void { - var foo = Foo { .a = 1, .b = 10 }; + var foo = Foo{ .a = 1, .b = 10 }; bar(&foo.b); } diff --git a/test/cases/compile_errors/implicitly_increasing_slice_alignment.zig b/test/cases/compile_errors/implicitly_increasing_slice_alignment.zig index 84ec6464f4ad..171936097dc9 100644 --- a/test/cases/compile_errors/implicitly_increasing_slice_alignment.zig +++ b/test/cases/compile_errors/implicitly_increasing_slice_alignment.zig @@ -4,7 +4,7 @@ const Foo = packed struct { }; export fn entry() void { - var foo = Foo { .a = 1, .b = 10 }; + var foo = Foo{ .a = 1, .b = 10 }; foo.b += 1; bar(@as(*[1]u32, &foo.b)[0..]); } diff --git a/test/cases/compile_errors/import_outside_package_path.zig b/test/cases/compile_errors/import_outside_package_path.zig index 0c0df594193e..34044e3b0fba 100644 --- a/test/cases/compile_errors/import_outside_package_path.zig +++ b/test/cases/compile_errors/import_outside_package_path.zig @@ -1,4 +1,4 @@ -comptime{ +comptime { _ = @import("../a.zig"); } diff --git a/test/cases/compile_errors/incorrect_return_type.zig b/test/cases/compile_errors/incorrect_return_type.zig index 57cf54a02347..f0fafed4c705 100644 --- a/test/cases/compile_errors/incorrect_return_type.zig +++ b/test/cases/compile_errors/incorrect_return_type.zig @@ -1,18 +1,18 @@ - pub export fn entry() void{ - _ = foo(); - } - const A = struct { - a: u32, - }; - fn foo() A { - return bar(); - } - const B = struct { - a: u32, - }; - fn bar() B { - unreachable; - } +pub export fn entry() void { + _ = foo(); +} +const A = struct { + a: u32, +}; +fn foo() A { + return bar(); +} +const B = struct { + a: u32, +}; +fn bar() B { + unreachable; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig b/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig index 242454e859c7..8d7e14acae89 100644 --- a/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig +++ b/test/cases/compile_errors/increase_pointer_alignment_in_ptrCast.zig @@ -1,5 +1,5 @@ export fn entry() u32 { - var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; + var bytes: [4]u8 = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; const ptr = @ptrCast(*u32, &bytes[0]); return ptr.*; } diff --git a/test/cases/compile_errors/indirect_struct_loop.zig b/test/cases/compile_errors/indirect_struct_loop.zig index dca2b9c3f65b..a1bb6ee41b4b 100644 --- a/test/cases/compile_errors/indirect_struct_loop.zig +++ b/test/cases/compile_errors/indirect_struct_loop.zig @@ -1,7 +1,15 @@ -const A = struct { b : B, }; -const B = struct { c : C, }; -const C = struct { a : A, }; -export fn entry() usize { return @sizeOf(A); } +const A = struct { + b: B, +}; +const B = struct { + c: C, +}; +const C = struct { + a: A, +}; +export fn entry() usize { + return @sizeOf(A); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/inferred_array_size_invalid_here.zig b/test/cases/compile_errors/inferred_array_size_invalid_here.zig index 084057dc8e6d..0791540ed2d5 100644 --- a/test/cases/compile_errors/inferred_array_size_invalid_here.zig +++ b/test/cases/compile_errors/inferred_array_size_invalid_here.zig @@ -4,7 +4,7 @@ export fn entry() void { } export fn entry2() void { const S = struct { a: *const [_]u8 }; - var a = .{ S{} }; + var a = .{S{}}; _ = a; } diff --git a/test/cases/compile_errors/inferring_error_set_of_function_pointer.zig b/test/cases/compile_errors/inferring_error_set_of_function_pointer.zig index 862e33906a6b..396ca9e834fb 100644 --- a/test/cases/compile_errors/inferring_error_set_of_function_pointer.zig +++ b/test/cases/compile_errors/inferring_error_set_of_function_pointer.zig @@ -1,5 +1,5 @@ comptime { - const z: ?fn()!void = null; + const z: ?fn () !void = null; } // error diff --git a/test/cases/compile_errors/integer_overflow_error.zig b/test/cases/compile_errors/integer_overflow_error.zig index aa4725b7e7ad..0720ede7c601 100644 --- a/test/cases/compile_errors/integer_overflow_error.zig +++ b/test/cases/compile_errors/integer_overflow_error.zig @@ -1,5 +1,7 @@ -const x : u8 = 300; -export fn entry() usize { return @sizeOf(@TypeOf(x)); } +const x: u8 = 300; +export fn entry() usize { + return @sizeOf(@TypeOf(x)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_builtin_fn.zig b/test/cases/compile_errors/invalid_builtin_fn.zig index 5b7b832177bf..3297525fd981 100644 --- a/test/cases/compile_errors/invalid_builtin_fn.zig +++ b/test/cases/compile_errors/invalid_builtin_fn.zig @@ -1,6 +1,7 @@ -fn f() @bogus(foo) { +fn f() @bogus(foo) {} +export fn entry() void { + _ = f(); } -export fn entry() void { _ = f(); } // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_capture_type.zig b/test/cases/compile_errors/invalid_capture_type.zig index 3813021c951b..fc97f3420952 100644 --- a/test/cases/compile_errors/invalid_capture_type.zig +++ b/test/cases/compile_errors/invalid_capture_type.zig @@ -1,5 +1,7 @@ export fn f1() void { - if (true) |x| { _ = x; } + if (true) |x| { + _ = x; + } } export fn f2() void { if (@as(usize, 5)) |_| {} diff --git a/test/cases/compile_errors/invalid_comparison_for_function_pointers.zig b/test/cases/compile_errors/invalid_comparison_for_function_pointers.zig index cd63c70259b3..3c76da2e38c0 100644 --- a/test/cases/compile_errors/invalid_comparison_for_function_pointers.zig +++ b/test/cases/compile_errors/invalid_comparison_for_function_pointers.zig @@ -1,7 +1,9 @@ fn foo() void {} const invalid = foo > foo; -export fn entry() usize { return @sizeOf(@TypeOf(invalid)); } +export fn entry() usize { + return @sizeOf(@TypeOf(invalid)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_field_access_in_comptime.zig b/test/cases/compile_errors/invalid_field_access_in_comptime.zig index 672c2b74c90b..ebcc525b2a13 100644 --- a/test/cases/compile_errors/invalid_field_access_in_comptime.zig +++ b/test/cases/compile_errors/invalid_field_access_in_comptime.zig @@ -1,4 +1,7 @@ -comptime { var x = doesnt_exist.whatever; _ = x; } +comptime { + var x = doesnt_exist.whatever; + _ = x; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig b/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig index 97f440da3b3f..f1cd96d8e7cc 100644 --- a/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig +++ b/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig @@ -1,10 +1,10 @@ const A = struct { - x : i32, - y : i32, - z : i32, + x: i32, + y: i32, + z: i32, }; export fn f() void { - const a = A { + const a = A{ .z = 4, .y = 2, .foo = 42, @@ -21,7 +21,6 @@ pub export fn entry() void { dump(.{ .field_1 = 123, .field_3 = 456 }); } - // error // backend=stage2 // target=native diff --git a/test/cases/compile_errors/invalid_optional_type_in_extern_struct.zig b/test/cases/compile_errors/invalid_optional_type_in_extern_struct.zig index 10e140d881ff..c7d7b4233abe 100644 --- a/test/cases/compile_errors/invalid_optional_type_in_extern_struct.zig +++ b/test/cases/compile_errors/invalid_optional_type_in_extern_struct.zig @@ -1,7 +1,9 @@ const stroo = extern struct { moo: ?[*c]u8, }; -export fn testf(fluff: *stroo) void { _ = fluff; } +export fn testf(fluff: *stroo) void { + _ = fluff; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_pointer_with_reify_type.zig b/test/cases/compile_errors/invalid_pointer_with_reify_type.zig index cac9e3289440..dce09234d459 100644 --- a/test/cases/compile_errors/invalid_pointer_with_reify_type.zig +++ b/test/cases/compile_errors/invalid_pointer_with_reify_type.zig @@ -8,7 +8,7 @@ export fn entry() void { .child = u8, .is_allowzero = false, .sentinel = &@as(u8, 0), - }}); + } }); } // error diff --git a/test/cases/compile_errors/invalid_shift_amount_error.zig b/test/cases/compile_errors/invalid_shift_amount_error.zig index 49852b5b7d03..9ea4c55d2981 100644 --- a/test/cases/compile_errors/invalid_shift_amount_error.zig +++ b/test/cases/compile_errors/invalid_shift_amount_error.zig @@ -1,8 +1,10 @@ -const x : u8 = 2; +const x: u8 = 2; fn f() u16 { return x << 8; } -export fn entry() u16 { return f(); } +export fn entry() u16 { + return f(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_type.zig b/test/cases/compile_errors/invalid_type.zig index 902d3652e7a3..a7c7d8109422 100644 --- a/test/cases/compile_errors/invalid_type.zig +++ b/test/cases/compile_errors/invalid_type.zig @@ -1,5 +1,7 @@ fn a() bogus {} -export fn entry() void { _ = a(); } +export fn entry() void { + _ = a(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/invalid_variadic_function.zig b/test/cases/compile_errors/invalid_variadic_function.zig index 997db9fee8fa..7652cb329a08 100644 --- a/test/cases/compile_errors/invalid_variadic_function.zig +++ b/test/cases/compile_errors/invalid_variadic_function.zig @@ -1,8 +1,12 @@ fn foo(...) void {} fn bar(a: anytype, ...) callconv(a) void {} -comptime { _ = foo; } -comptime { _ = bar; } +comptime { + _ = foo; +} +comptime { + _ = bar; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig index 874f015ffb93..92cd406d1c94 100644 --- a/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig +++ b/test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig @@ -1,10 +1,10 @@ export fn foo1() void { - var bytes = [_]u8{1, 2}; + var bytes = [_]u8{ 1, 2 }; const word: u16 = @bitCast(u16, bytes[0..]); _ = word; } export fn foo2() void { - var bytes: []const u8 = &[_]u8{1, 2}; + var bytes: []const u8 = &[_]u8{ 1, 2 }; const word: u16 = @bitCast(u16, bytes); _ = word; } diff --git a/test/cases/compile_errors/local_variable_redeclaration.zig b/test/cases/compile_errors/local_variable_redeclaration.zig index a0861ada490d..5b81cd5fbc20 100644 --- a/test/cases/compile_errors/local_variable_redeclaration.zig +++ b/test/cases/compile_errors/local_variable_redeclaration.zig @@ -1,5 +1,5 @@ export fn f() void { - const a : i32 = 0; + const a: i32 = 0; var a = 0; } diff --git a/test/cases/compile_errors/local_variable_redeclares_parameter.zig b/test/cases/compile_errors/local_variable_redeclares_parameter.zig index 6e523c2c8f6d..f49b7f137e8d 100644 --- a/test/cases/compile_errors/local_variable_redeclares_parameter.zig +++ b/test/cases/compile_errors/local_variable_redeclares_parameter.zig @@ -1,7 +1,9 @@ -fn f(a : i32) void { +fn f(a: i32) void { const a = 0; } -export fn entry() void { f(1); } +export fn entry() void { + f(1); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/local_variable_shadowing_global.zig b/test/cases/compile_errors/local_variable_shadowing_global.zig index 91df6a7c3d81..e3f221d0c560 100644 --- a/test/cases/compile_errors/local_variable_shadowing_global.zig +++ b/test/cases/compile_errors/local_variable_shadowing_global.zig @@ -2,7 +2,7 @@ const Foo = struct {}; const Bar = struct {}; export fn entry() void { - var Bar : i32 = undefined; + var Bar: i32 = undefined; _ = Bar; } diff --git a/test/cases/compile_errors/main_function_with_bogus_args_type.zig b/test/cases/compile_errors/main_function_with_bogus_args_type.zig index dd02e1af34ac..f0322e0484f8 100644 --- a/test/cases/compile_errors/main_function_with_bogus_args_type.zig +++ b/test/cases/compile_errors/main_function_with_bogus_args_type.zig @@ -1,4 +1,6 @@ -pub fn main(args: [][]bogus) !void {_ = args;} +pub fn main(args: [][]bogus) !void { + _ = args; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig b/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig index 1ef986935b73..2f596db1ed7e 100644 --- a/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig +++ b/test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig @@ -2,7 +2,7 @@ const Geo3DTex2D = struct { vertices: [][2]f32 }; pub fn getGeo3DTex2D() Geo3DTex2D { return Geo3DTex2D{ .vertices = [_][2]f32{ - [_]f32{ -0.5, -0.5}, + [_]f32{ -0.5, -0.5 }, }, }; } diff --git a/test/cases/compile_errors/missing_else_clause.zig b/test/cases/compile_errors/missing_else_clause.zig index e96363b9cdc4..508a06ab585b 100644 --- a/test/cases/compile_errors/missing_else_clause.zig +++ b/test/cases/compile_errors/missing_else_clause.zig @@ -1,9 +1,13 @@ fn f(b: bool) void { - const x : i32 = if (b) h: { break :h 1; }; + const x: i32 = if (b) h: { + break :h 1; + }; _ = x; } fn g(b: bool) void { - const y = if (b) h: { break :h @as(i32, 1); }; + const y = if (b) h: { + break :h @as(i32, 1); + }; _ = y; } fn h() void { diff --git a/test/cases/compile_errors/missing_field_in_struct_value_expression.zig b/test/cases/compile_errors/missing_field_in_struct_value_expression.zig index 600540d1e043..3d19cb9db155 100644 --- a/test/cases/compile_errors/missing_field_in_struct_value_expression.zig +++ b/test/cases/compile_errors/missing_field_in_struct_value_expression.zig @@ -1,12 +1,12 @@ const A = struct { - x : i32, - y : i32, - z : i32, + x: i32, + y: i32, + z: i32, }; export fn f() void { // we want the error on the '{' not the 'A' because // the A could be a complicated expression - const a = A { + const a = A{ .z = 4, .y = 2, }; diff --git a/test/cases/compile_errors/missing_main_fn_in_executable.zig b/test/cases/compile_errors/missing_main_fn_in_executable.zig index 3c1ae631ac40..9f243356b779 100644 --- a/test/cases/compile_errors/missing_main_fn_in_executable.zig +++ b/test/cases/compile_errors/missing_main_fn_in_executable.zig @@ -1,5 +1,3 @@ - - // error // backend=llvm // target=x86_64-linux diff --git a/test/cases/compile_errors/missing_param_name.zig b/test/cases/compile_errors/missing_param_name.zig index 88da902ea2d2..1f679ea1d825 100644 --- a/test/cases/compile_errors/missing_param_name.zig +++ b/test/cases/compile_errors/missing_param_name.zig @@ -1,5 +1,7 @@ fn f(i32) void {} -export fn entry() usize { return @sizeOf(@TypeOf(f)); } +export fn entry() usize { + return @sizeOf(@TypeOf(f)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig b/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig index ef8fce6c8086..ca8adade0198 100644 --- a/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig +++ b/test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig @@ -24,11 +24,13 @@ pub const JsonNode = struct { fn foo() void { var jll: JasonList = undefined; jll.init(1234); - var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; + var jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} }; _ = jd; } -export fn entry() usize { return @sizeOf(@TypeOf(foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/mul_overflow_in_function_evaluation.zig b/test/cases/compile_errors/mul_overflow_in_function_evaluation.zig index 6be57f770eb8..c484df754083 100644 --- a/test/cases/compile_errors/mul_overflow_in_function_evaluation.zig +++ b/test/cases/compile_errors/mul_overflow_in_function_evaluation.zig @@ -3,7 +3,9 @@ fn mul(a: u16, b: u16) u16 { return a * b; } -export fn entry() usize { return @sizeOf(@TypeOf(&y)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&y)); +} // error // backend=stage2 @@ -11,4 +13,3 @@ export fn entry() usize { return @sizeOf(@TypeOf(&y)); } // // :3:14: error: overflow of integer type 'u16' with value '1800000' // :1:14: note: called from here - diff --git a/test/cases/compile_errors/multiple_function_definitions.zig b/test/cases/compile_errors/multiple_function_definitions.zig index d07eaee257e1..134daaeaa4f6 100644 --- a/test/cases/compile_errors/multiple_function_definitions.zig +++ b/test/cases/compile_errors/multiple_function_definitions.zig @@ -1,6 +1,8 @@ fn a() void {} fn a() void {} -export fn entry() void { a(); } +export fn entry() void { + a(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/negation_overflow_in_function_evaluation.zig b/test/cases/compile_errors/negation_overflow_in_function_evaluation.zig index abd8549fd20d..208f76100519 100644 --- a/test/cases/compile_errors/negation_overflow_in_function_evaluation.zig +++ b/test/cases/compile_errors/negation_overflow_in_function_evaluation.zig @@ -3,7 +3,9 @@ fn neg(x: i8) i8 { return -x; } -export fn entry() usize { return @sizeOf(@TypeOf(&y)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&y)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/nested_vectors.zig b/test/cases/compile_errors/nested_vectors.zig index 9482c2300522..5a9b3756583e 100644 --- a/test/cases/compile_errors/nested_vectors.zig +++ b/test/cases/compile_errors/nested_vectors.zig @@ -10,4 +10,3 @@ export fn entry() void { // target=native // // :3:16: error: expected integer, float, bool, or pointer for the vector element type; found '@Vector(4, u8)' - diff --git a/test/cases/compile_errors/noalias_on_non_pointer_param.zig b/test/cases/compile_errors/noalias_on_non_pointer_param.zig index 806808820f4c..e58170e2434c 100644 --- a/test/cases/compile_errors/noalias_on_non_pointer_param.zig +++ b/test/cases/compile_errors/noalias_on_non_pointer_param.zig @@ -1,11 +1,19 @@ -fn f(noalias x: i32) void { _ = x; } -export fn entry() void { f(1234); } +fn f(noalias x: i32) void { + _ = x; +} +export fn entry() void { + f(1234); +} -fn generic(comptime T: type, noalias _: [*]T, noalias _: [*]const T, _: usize) void {} -comptime { _ = generic; } +fn generic(comptime T: type, noalias _: [*]T, noalias _: [*]const T, _: usize) void {} +comptime { + _ = generic; +} -fn slice(noalias _: []u8) void {} -comptime { _ = slice; } +fn slice(noalias _: []u8) void {} +comptime { + _ = slice; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig b/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig index de5a3830ebc5..f5eba9ee62a0 100644 --- a/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig +++ b/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig @@ -5,8 +5,7 @@ export fn entry() void { _ = llamas2; } -fn makeLlamas(count: usize) [count]u8 { -} +fn makeLlamas(count: usize) [count]u8 {} // error // target=native diff --git a/test/cases/compile_errors/non-const_expression_function_call_with_struct_return_value_outside_function.zig b/test/cases/compile_errors/non-const_expression_function_call_with_struct_return_value_outside_function.zig index 4acd0afb815a..d9bd0dd2b223 100644 --- a/test/cases/compile_errors/non-const_expression_function_call_with_struct_return_value_outside_function.zig +++ b/test/cases/compile_errors/non-const_expression_function_call_with_struct_return_value_outside_function.zig @@ -4,11 +4,13 @@ const Foo = struct { const a = get_it(); fn get_it() Foo { global_side_effect = true; - return Foo {.x = 13}; + return Foo{ .x = 13 }; } var global_side_effect = false; -export fn entry() usize { return @sizeOf(@TypeOf(a)); } +export fn entry() usize { + return @sizeOf(@TypeOf(a)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/non-const_expression_in_struct_literal_outside_function.zig b/test/cases/compile_errors/non-const_expression_in_struct_literal_outside_function.zig index 2e0043c5ecec..c6d4e04fc1f7 100644 --- a/test/cases/compile_errors/non-const_expression_in_struct_literal_outside_function.zig +++ b/test/cases/compile_errors/non-const_expression_in_struct_literal_outside_function.zig @@ -1,10 +1,12 @@ const Foo = struct { x: i32, }; -const a = Foo {.x = get_it()}; +const a = Foo{ .x = get_it() }; extern fn get_it() i32; -export fn entry() usize { return @sizeOf(@TypeOf(a)); } +export fn entry() usize { + return @sizeOf(@TypeOf(a)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig index cf65131a1f1e..0b2e8585d9ef 100644 --- a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig +++ b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig @@ -1,30 +1,30 @@ export fn entry1() void { - var m2 = &2; - _ = m2; + var m2 = &2; + _ = m2; } export fn entry2() void { - var a = undefined; - _ = a; + var a = undefined; + _ = a; } export fn entry3() void { - var b = 1; - _ = b; + var b = 1; + _ = b; } export fn entry4() void { - var c = 1.0; - _ = c; + var c = 1.0; + _ = c; } export fn entry5() void { - var d = null; - _ = d; + var d = null; + _ = d; } export fn entry6(opaque_: *Opaque) void { - var e = opaque_.*; - _ = e; + var e = opaque_.*; + _ = e; } export fn entry7() void { - var f = i32; - _ = f; + var f = i32; + _ = f; } const Opaque = opaque {}; diff --git a/test/cases/compile_errors/non-exhaustive_enum_marker_assigned_a_value.zig b/test/cases/compile_errors/non-exhaustive_enum_marker_assigned_a_value.zig index c9ebb6af7142..831845722bfd 100644 --- a/test/cases/compile_errors/non-exhaustive_enum_marker_assigned_a_value.zig +++ b/test/cases/compile_errors/non-exhaustive_enum_marker_assigned_a_value.zig @@ -8,7 +8,10 @@ const B = enum { b, _, }; -comptime { _ = A; _ = B; } +comptime { + _ = A; + _ = B; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/non-inline_for_loop_on_a_type_that_requires_comptime.zig b/test/cases/compile_errors/non-inline_for_loop_on_a_type_that_requires_comptime.zig index ce72f912b87e..2bb3f84cb9d2 100644 --- a/test/cases/compile_errors/non-inline_for_loop_on_a_type_that_requires_comptime.zig +++ b/test/cases/compile_errors/non-inline_for_loop_on_a_type_that_requires_comptime.zig @@ -4,7 +4,9 @@ const Foo = struct { }; export fn entry() void { const xx: [2]Foo = .{ .{ .name = "", .T = u8 }, .{ .name = "", .T = u8 } }; - for (xx) |f| { _ = f;} + for (xx) |f| { + _ = f; + } } // error diff --git a/test/cases/compile_errors/non_constant_expression_in_array_size.zig b/test/cases/compile_errors/non_constant_expression_in_array_size.zig index 07facfa0f2c8..74d60ad3944d 100644 --- a/test/cases/compile_errors/non_constant_expression_in_array_size.zig +++ b/test/cases/compile_errors/non_constant_expression_in_array_size.zig @@ -2,9 +2,13 @@ const Foo = struct { y: [get()]u8, }; var global_var: usize = 1; -fn get() usize { return global_var; } +fn get() usize { + return global_var; +} -export fn entry() usize { return @offsetOf(Foo, "y"); } +export fn entry() usize { + return @offsetOf(Foo, "y"); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/offsetOf-bad_field_name.zig b/test/cases/compile_errors/offsetOf-bad_field_name.zig index eb04da3c6816..2c0fbe08b4ce 100644 --- a/test/cases/compile_errors/offsetOf-bad_field_name.zig +++ b/test/cases/compile_errors/offsetOf-bad_field_name.zig @@ -2,7 +2,10 @@ const Foo = struct { derp: i32, }; export fn foo() usize { - return @offsetOf(Foo, "a",); + return @offsetOf( + Foo, + "a", + ); } // error diff --git a/test/cases/compile_errors/offsetOf-non_struct.zig b/test/cases/compile_errors/offsetOf-non_struct.zig index 45e9cf9518fb..2a2705f15df3 100644 --- a/test/cases/compile_errors/offsetOf-non_struct.zig +++ b/test/cases/compile_errors/offsetOf-non_struct.zig @@ -1,6 +1,9 @@ const Foo = i32; export fn foo() usize { - return @offsetOf(Foo, "a",); + return @offsetOf( + Foo, + "a", + ); } // error diff --git a/test/cases/compile_errors/old_fn_ptr_in_extern_context.zig b/test/cases/compile_errors/old_fn_ptr_in_extern_context.zig index 4f957a827cc7..7983ed8ec88b 100644 --- a/test/cases/compile_errors/old_fn_ptr_in_extern_context.zig +++ b/test/cases/compile_errors/old_fn_ptr_in_extern_context.zig @@ -5,7 +5,7 @@ comptime { _ = @sizeOf(S) == 1; } comptime { - _ = [*c][4]fn() callconv(.C) void; + _ = [*c][4]fn () callconv(.C) void; } // error diff --git a/test/cases/compile_errors/overflow_in_enum_value_allocation.zig b/test/cases/compile_errors/overflow_in_enum_value_allocation.zig index 2a5b55e86da1..821ac6c2563e 100644 --- a/test/cases/compile_errors/overflow_in_enum_value_allocation.zig +++ b/test/cases/compile_errors/overflow_in_enum_value_allocation.zig @@ -3,8 +3,8 @@ const Moo = enum(u8) { Over, }; pub export fn entry() void { - var y = Moo.Last; - _ = y; + var y = Moo.Last; + _ = y; } // error diff --git a/test/cases/compile_errors/packed_union_given_enum_tag_type.zig b/test/cases/compile_errors/packed_union_given_enum_tag_type.zig index 03aaef0d8cd5..2e69afd0a9ec 100644 --- a/test/cases/compile_errors/packed_union_given_enum_tag_type.zig +++ b/test/cases/compile_errors/packed_union_given_enum_tag_type.zig @@ -9,7 +9,7 @@ const Payload = packed union(Letter) { C: bool, }; export fn entry() void { - var a = Payload { .A = 1234 }; + var a = Payload{ .A = 1234 }; _ = a; } diff --git a/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig b/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig index 0db9d83dfbc7..26d224de8594 100644 --- a/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig +++ b/test/cases/compile_errors/packed_union_with_automatic_layout_field.zig @@ -7,7 +7,7 @@ const Payload = packed union { B: bool, }; export fn entry() void { - var a = Payload { .B = true }; + var a = Payload{ .B = true }; _ = a; } diff --git a/test/cases/compile_errors/panic_called_at_compile_time.zig b/test/cases/compile_errors/panic_called_at_compile_time.zig index 220161930bc4..8198cd8e5d31 100644 --- a/test/cases/compile_errors/panic_called_at_compile_time.zig +++ b/test/cases/compile_errors/panic_called_at_compile_time.zig @@ -1,6 +1,8 @@ export fn entry() void { comptime { - @panic("aoeu",); + @panic( + "aoeu", + ); } } diff --git a/test/cases/compile_errors/parameter_redeclaration.zig b/test/cases/compile_errors/parameter_redeclaration.zig index 89c7c4bd2aa8..1c6ec1a4393e 100644 --- a/test/cases/compile_errors/parameter_redeclaration.zig +++ b/test/cases/compile_errors/parameter_redeclaration.zig @@ -1,6 +1,7 @@ -fn f(a : i32, a : i32) void { +fn f(a: i32, a: i32) void {} +export fn entry() void { + f(1, 2); } -export fn entry() void { f(1, 2); } // error // backend=stage2 diff --git a/test/cases/compile_errors/pass_const_ptr_to_mutable_ptr_fn.zig b/test/cases/compile_errors/pass_const_ptr_to_mutable_ptr_fn.zig index fd24b58f5563..ce39eba4f34a 100644 --- a/test/cases/compile_errors/pass_const_ptr_to_mutable_ptr_fn.zig +++ b/test/cases/compile_errors/pass_const_ptr_to_mutable_ptr_fn.zig @@ -1,14 +1,20 @@ fn foo() bool { - const a = @as([]const u8, "a",); + const a = @as( + []const u8, + "a", + ); const b = &a; return ptrEql(b, b); } fn ptrEql(a: *[]const u8, b: *[]const u8) bool { - _ = a; _ = b; + _ = a; + _ = b; return true; } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/passing_an_under-aligned_function_pointer.zig b/test/cases/compile_errors/passing_an_under-aligned_function_pointer.zig index 3e3500e71fc7..6d3e2e871d14 100644 --- a/test/cases/compile_errors/passing_an_under-aligned_function_pointer.zig +++ b/test/cases/compile_errors/passing_an_under-aligned_function_pointer.zig @@ -4,7 +4,9 @@ export fn entry() void { fn testImplicitlyDecreaseFnAlign(ptr: *const fn () align(8) i32, answer: i32) void { if (ptr() != answer) unreachable; } -fn alignedSmall() align(4) i32 { return 1234; } +fn alignedSmall() align(4) i32 { + return 1234; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/pointer_to_noreturn.zig b/test/cases/compile_errors/pointer_to_noreturn.zig index 0891fd36997f..5d757f631b46 100644 --- a/test/cases/compile_errors/pointer_to_noreturn.zig +++ b/test/cases/compile_errors/pointer_to_noreturn.zig @@ -1,5 +1,7 @@ fn a() *noreturn {} -export fn entry() void { _ = a(); } +export fn entry() void { + _ = a(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/range_operator_in_switch_used_on_error_set.zig b/test/cases/compile_errors/range_operator_in_switch_used_on_error_set.zig index 859197929c6f..697582228fe4 100644 --- a/test/cases/compile_errors/range_operator_in_switch_used_on_error_set.zig +++ b/test/cases/compile_errors/range_operator_in_switch_used_on_error_set.zig @@ -1,13 +1,13 @@ export fn entry() void { foo(452) catch |err| switch (err) { - error.Foo ... error.Bar => {}, + error.Foo...error.Bar => {}, else => {}, }; } fn foo(x: i32) !void { switch (x) { - 0 ... 10 => return error.Foo, - 11 ... 20 => return error.Bar, + 0...10 => return error.Foo, + 11...20 => return error.Bar, else => {}, } } diff --git a/test/cases/compile_errors/reassign_to_array_parameter.zig b/test/cases/compile_errors/reassign_to_array_parameter.zig index 492732997065..380fd6215436 100644 --- a/test/cases/compile_errors/reassign_to_array_parameter.zig +++ b/test/cases/compile_errors/reassign_to_array_parameter.zig @@ -1,8 +1,8 @@ fn reassign(a: [3]f32) void { - a = [3]f32{4, 5, 6}; + a = [3]f32{ 4, 5, 6 }; } export fn entry() void { - reassign(.{1, 2, 3}); + reassign(.{ 1, 2, 3 }); } // error diff --git a/test/cases/compile_errors/reassign_to_struct_parameter.zig b/test/cases/compile_errors/reassign_to_struct_parameter.zig index 963448f8fe0e..560de215b532 100644 --- a/test/cases/compile_errors/reassign_to_struct_parameter.zig +++ b/test/cases/compile_errors/reassign_to_struct_parameter.zig @@ -2,10 +2,10 @@ const S = struct { x: u32, }; fn reassign(s: S) void { - s = S{.x = 2}; + s = S{ .x = 2 }; } export fn entry() void { - reassign(S{.x = 3}); + reassign(S{ .x = 3 }); } // error diff --git a/test/cases/compile_errors/redefinition_of_enums.zig b/test/cases/compile_errors/redefinition_of_enums.zig index 641211872e12..34d5efe8df86 100644 --- a/test/cases/compile_errors/redefinition_of_enums.zig +++ b/test/cases/compile_errors/redefinition_of_enums.zig @@ -1,5 +1,5 @@ -const A = enum {x}; -const A = enum {x}; +const A = enum { x }; +const A = enum { x }; // error // backend=stage2 diff --git a/test/cases/compile_errors/redefinition_of_global_variables.zig b/test/cases/compile_errors/redefinition_of_global_variables.zig index ed0d6f3ed95b..6f4ed225f791 100644 --- a/test/cases/compile_errors/redefinition_of_global_variables.zig +++ b/test/cases/compile_errors/redefinition_of_global_variables.zig @@ -1,5 +1,5 @@ -var a : i32 = 1; -var a : i32 = 2; +var a: i32 = 1; +var a: i32 = 2; // error // backend=stage2 diff --git a/test/cases/compile_errors/redefinition_of_struct.zig b/test/cases/compile_errors/redefinition_of_struct.zig index dc6d4abeebea..fa541d6ec9b2 100644 --- a/test/cases/compile_errors/redefinition_of_struct.zig +++ b/test/cases/compile_errors/redefinition_of_struct.zig @@ -1,5 +1,9 @@ -const A = struct { x : i32, }; -const A = struct { y : i32, }; +const A = struct { + x: i32, +}; +const A = struct { + y: i32, +}; // error // backend=stage2 diff --git a/test/cases/compile_errors/reference_to_const_data.zig b/test/cases/compile_errors/reference_to_const_data.zig index cbc0fe131cfa..e773cdb4a088 100644 --- a/test/cases/compile_errors/reference_to_const_data.zig +++ b/test/cases/compile_errors/reference_to_const_data.zig @@ -1,5 +1,5 @@ export fn foo() void { - var ptr = &[_]u8{0,0,0,0}; + var ptr = &[_]u8{ 0, 0, 0, 0 }; ptr[1] = 2; } export fn bar() void { @@ -11,11 +11,11 @@ export fn baz() void { ptr.* = false; } export fn qux() void { - const S = struct{ + const S = struct { x: usize, y: usize, }; - var ptr = &S{.x=1,.y=2}; + var ptr = &S{ .x = 1, .y = 2 }; ptr.x = 2; } export fn quux() void { diff --git a/test/cases/compile_errors/reify_type.Fn_with_is_generic_true.zig b/test/cases/compile_errors/reify_type.Fn_with_is_generic_true.zig index abdccdf36df6..bb2c4bbe6282 100644 --- a/test/cases/compile_errors/reify_type.Fn_with_is_generic_true.zig +++ b/test/cases/compile_errors/reify_type.Fn_with_is_generic_true.zig @@ -8,7 +8,9 @@ const Foo = @Type(.{ .params = &.{}, }, }); -comptime { _ = Foo; } +comptime { + _ = Foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig b/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig index f3542d583a13..a341435b36ba 100644 --- a/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig +++ b/test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig @@ -8,7 +8,9 @@ const Foo = @Type(.{ .params = &.{}, }, }); -comptime { _ = Foo; } +comptime { + _ = Foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/reify_type.Fn_with_return_type_null.zig b/test/cases/compile_errors/reify_type.Fn_with_return_type_null.zig index 49335ab69336..d348a0c908a0 100644 --- a/test/cases/compile_errors/reify_type.Fn_with_return_type_null.zig +++ b/test/cases/compile_errors/reify_type.Fn_with_return_type_null.zig @@ -8,7 +8,9 @@ const Foo = @Type(.{ .params = &.{}, }, }); -comptime { _ = Foo; } +comptime { + _ = Foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/reify_type_union_payload_is_undefined.zig b/test/cases/compile_errors/reify_type_union_payload_is_undefined.zig index 410bb9265811..886d443a00c0 100644 --- a/test/cases/compile_errors/reify_type_union_payload_is_undefined.zig +++ b/test/cases/compile_errors/reify_type_union_payload_is_undefined.zig @@ -1,7 +1,9 @@ const Foo = @Type(.{ .Struct = undefined, }); -comptime { _ = Foo; } +comptime { + _ = Foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/return_from_defer_expression.zig b/test/cases/compile_errors/return_from_defer_expression.zig index 12aa08a11cdc..28d1b0c6c6c4 100644 --- a/test/cases/compile_errors/return_from_defer_expression.zig +++ b/test/cases/compile_errors/return_from_defer_expression.zig @@ -6,13 +6,15 @@ pub fn testTrickyDefer() !void { const a = maybeInt() orelse return; } -fn canFail() anyerror!void { } +fn canFail() anyerror!void {} pub fn maybeInt() ?i32 { return 0; } -export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } +export fn entry() usize { + return @sizeOf(@TypeOf(testTrickyDefer)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/return_invalid_type_from_test.zig b/test/cases/compile_errors/return_invalid_type_from_test.zig index a954bd7ee569..d70bab390a0c 100644 --- a/test/cases/compile_errors/return_invalid_type_from_test.zig +++ b/test/cases/compile_errors/return_invalid_type_from_test.zig @@ -1,8 +1,10 @@ -test "example" { return 1; } +test "example" { + return 1; +} // error // backend=stage2 // target=native // is_test=1 // -// :1:25: error: expected type '@typeInfo(@typeInfo(@TypeOf(tmp.test.example)).Fn.return_type.?).ErrorUnion.error_set!void', found 'comptime_int' \ No newline at end of file +// :1:25: error: expected type '@typeInfo(@typeInfo(@TypeOf(tmp.test.example)).Fn.return_type.?).ErrorUnion.error_set!void', found 'comptime_int' diff --git a/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig b/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig index 5949031fb926..67a46a7226a0 100644 --- a/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig +++ b/test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig @@ -4,7 +4,7 @@ const Foo = struct { }; export fn f() void { var x: u8 = 0; - const foo = Foo { .Bar = x, .Baz = u8 }; + const foo = Foo{ .Bar = x, .Baz = u8 }; _ = foo; } diff --git a/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig b/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig index 04e2a97e7aa0..940b1e0e8d08 100644 --- a/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig +++ b/test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig @@ -4,7 +4,7 @@ const Foo = union { }; export fn f() void { var x: u8 = 0; - const foo = Foo { .Bar = x }; + const foo = Foo{ .Bar = x }; _ = foo; } diff --git a/test/cases/compile_errors/runtime_to_comptime_num.zig b/test/cases/compile_errors/runtime_to_comptime_num.zig index 972adb59bb40..8d4a3fb999f5 100644 --- a/test/cases/compile_errors/runtime_to_comptime_num.zig +++ b/test/cases/compile_errors/runtime_to_comptime_num.zig @@ -2,16 +2,16 @@ pub export fn entry() void { var a: u32 = 0; _ = @as(comptime_int, a); } -pub export fn entry2() void{ +pub export fn entry2() void { var a: u32 = 0; _ = @as(comptime_float, a); } -pub export fn entry3() void{ +pub export fn entry3() void { comptime var aa: comptime_float = 0.0; var a: f32 = 4; aa = a; } -pub export fn entry4() void{ +pub export fn entry4() void { comptime var aa: comptime_int = 0.0; var a: f32 = 4; aa = a; diff --git a/test/cases/compile_errors/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig b/test/cases/compile_errors/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig index c8e95e3969e5..8bf071d75b52 100644 --- a/test/cases/compile_errors/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig +++ b/test/cases/compile_errors/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig @@ -1,8 +1,8 @@ export fn a() void { comptime { - var x = @as(i32, 1); - x <<|= @as(i32, -2); - } + var x = @as(i32, 1); + x <<|= @as(i32, -2); + } } // error diff --git a/test/cases/compile_errors/self_referential_struct_requires_comptime.zig b/test/cases/compile_errors/self_referential_struct_requires_comptime.zig index 3ce75710267c..661a12df97c8 100644 --- a/test/cases/compile_errors/self_referential_struct_requires_comptime.zig +++ b/test/cases/compile_errors/self_referential_struct_requires_comptime.zig @@ -7,7 +7,6 @@ pub export fn entry() void { _ = s; } - // error // backend=stage2 // target=native diff --git a/test/cases/compile_errors/setAlignStack_in_inline_function.zig b/test/cases/compile_errors/setAlignStack_in_inline_function.zig index 62bbb3865c9c..a84424e368c0 100644 --- a/test/cases/compile_errors/setAlignStack_in_inline_function.zig +++ b/test/cases/compile_errors/setAlignStack_in_inline_function.zig @@ -1,7 +1,7 @@ export fn entry() void { foo(); } -fn foo() callconv(.Inline) void { +inline fn foo() void { @setAlignStack(16); } @@ -12,7 +12,6 @@ fn bar() void { @setAlignStack(16); } - // error // backend=stage2 // target=native diff --git a/test/cases/compile_errors/slice_passed_as_array_init_type_with_elems.zig b/test/cases/compile_errors/slice_passed_as_array_init_type_with_elems.zig index 7af505e20d34..91dc5f512899 100644 --- a/test/cases/compile_errors/slice_passed_as_array_init_type_with_elems.zig +++ b/test/cases/compile_errors/slice_passed_as_array_init_type_with_elems.zig @@ -1,5 +1,5 @@ export fn entry() void { - const x = []u8{1, 2}; + const x = []u8{ 1, 2 }; _ = x; } diff --git a/test/cases/compile_errors/slice_sentinel_mismatch-2.zig b/test/cases/compile_errors/slice_sentinel_mismatch-2.zig index 3cc5ac4c3914..424cd8936359 100644 --- a/test/cases/compile_errors/slice_sentinel_mismatch-2.zig +++ b/test/cases/compile_errors/slice_sentinel_mismatch-2.zig @@ -2,7 +2,9 @@ fn foo() [:0]u8 { var x: []u8 = undefined; return x; } -comptime { _ = foo; } +comptime { + _ = foo; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/slice_used_as_extern_fn_param.zig b/test/cases/compile_errors/slice_used_as_extern_fn_param.zig index 8391c3e21bfa..e6b065cd623f 100644 --- a/test/cases/compile_errors/slice_used_as_extern_fn_param.zig +++ b/test/cases/compile_errors/slice_used_as_extern_fn_param.zig @@ -1,4 +1,4 @@ -extern fn Text(str: []const u8, num: i32) callconv(.C) void; +extern fn Text(str: []const u8, num: i32) callconv(.C) void; export fn entry() void { _ = Text; } diff --git a/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig b/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig index d878bec18b0d..3024f1dee841 100644 --- a/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig +++ b/test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig @@ -1,4 +1,4 @@ -const Small = enum (u2) { +const Small = enum(u2) { One, Two, Three, diff --git a/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig b/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig index f2ff3e2cd142..0bd2839e08fe 100644 --- a/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig +++ b/test/cases/compile_errors/specify_non-integer_enum_tag_type.zig @@ -1,4 +1,4 @@ -const Small = enum (f32) { +const Small = enum(f32) { One, Two, Three, diff --git a/test/cases/compile_errors/src_fields_runtime.zig b/test/cases/compile_errors/src_fields_runtime.zig index 0bdb5af81cbe..a9828311233a 100644 --- a/test/cases/compile_errors/src_fields_runtime.zig +++ b/test/cases/compile_errors/src_fields_runtime.zig @@ -4,7 +4,10 @@ pub export fn entry1() void { comptime var b: []const u8 = s.fn_name; comptime var c: u32 = s.column; comptime var d: u32 = s.line; - _ = a; _ = b; _ = c; _ = d; + _ = a; + _ = b; + _ = c; + _ = d; } // error diff --git a/test/cases/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig b/test/cases/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig index c8d31ec8dfac..75f43ed914b9 100644 --- a/test/cases/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig +++ b/test/cases/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig @@ -1,10 +1,8 @@ fn Foo(comptime T: type) Foo(T) { - return struct{ x: T }; + return struct { x: T }; } export fn entry() void { - const t = Foo(u32) { - .x = 1 - }; + const t = Foo(u32){ .x = 1 }; _ = t; } diff --git a/test/cases/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig b/test/cases/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig index 7c70fc509528..5bcf30547b5f 100644 --- a/test/cases/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig +++ b/test/cases/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig @@ -1,6 +1,10 @@ export fn foo() void { var bar: u32 = 3; - asm volatile ("" : [baz]"+r"(bar) : : ""); + asm volatile ("" + : [baz] "+r" (bar), + : + : "" + ); } // error diff --git a/test/cases/compile_errors/std.fmt_error_for_unused_arguments.zig b/test/cases/compile_errors/std.fmt_error_for_unused_arguments.zig index a20f2798bc8d..6661fe54eba8 100644 --- a/test/cases/compile_errors/std.fmt_error_for_unused_arguments.zig +++ b/test/cases/compile_errors/std.fmt_error_for_unused_arguments.zig @@ -1,5 +1,5 @@ export fn entry() void { - @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); + @import("std").debug.print("{d} {d} {d} {d} {d}", .{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); } // error diff --git a/test/cases/compile_errors/struct_type_mismatch_in_arg.zig b/test/cases/compile_errors/struct_type_mismatch_in_arg.zig index d051966c523d..fe5a764e81be 100644 --- a/test/cases/compile_errors/struct_type_mismatch_in_arg.zig +++ b/test/cases/compile_errors/struct_type_mismatch_in_arg.zig @@ -1,11 +1,11 @@ const Foo = struct { i: i32 }; const Bar = struct { j: i32 }; -pub fn helper(_: Foo, _: Bar) void { } +pub fn helper(_: Foo, _: Bar) void {} comptime { - helper(Bar { .j = 10 }, Bar { .j = 10 }); - helper(Bar { .i = 10 }, Bar { .j = 10 }); + helper(Bar{ .j = 10 }, Bar{ .j = 10 }); + helper(Bar{ .i = 10 }, Bar{ .j = 10 }); } // error diff --git a/test/cases/compile_errors/struct_with_declarations_unavailable_for_reify_type.zig b/test/cases/compile_errors/struct_with_declarations_unavailable_for_reify_type.zig index 81864160dcc1..f0a24632283e 100644 --- a/test/cases/compile_errors/struct_with_declarations_unavailable_for_reify_type.zig +++ b/test/cases/compile_errors/struct_with_declarations_unavailable_for_reify_type.zig @@ -1,5 +1,7 @@ export fn entry() void { - _ = @Type(@typeInfo(struct { const foo = 1; })); + _ = @Type(@typeInfo(struct { + const foo = 1; + })); } // error diff --git a/test/cases/compile_errors/struct_with_invalid_field.zig b/test/cases/compile_errors/struct_with_invalid_field.zig index aa24b029bb73..479eeeac8fd0 100644 --- a/test/cases/compile_errors/struct_with_invalid_field.zig +++ b/test/cases/compile_errors/struct_with_invalid_field.zig @@ -1,9 +1,16 @@ -const std = @import("std",); +const std = @import( + "std", +); const Allocator = std.mem.Allocator; const ArrayList = std.ArrayList; const HeaderWeight = enum { - H1, H2, H3, H4, H5, H6, + H1, + H2, + H3, + H4, + H5, + H6, }; const MdText = ArrayList(u8); @@ -16,7 +23,7 @@ const MdNode = union(enum) { }; export fn entry() void { - const a = MdNode.Header { + const a = MdNode.Header{ .text = MdText.init(std.testing.allocator), .weight = HeaderWeight.H1, }; diff --git a/test/cases/compile_errors/sub_overflow_in_function_evaluation.zig b/test/cases/compile_errors/sub_overflow_in_function_evaluation.zig index c87f99837309..651ef34bdcd6 100644 --- a/test/cases/compile_errors/sub_overflow_in_function_evaluation.zig +++ b/test/cases/compile_errors/sub_overflow_in_function_evaluation.zig @@ -3,7 +3,9 @@ fn sub(a: u16, b: u16) u16 { return a - b; } -export fn entry() usize { return @sizeOf(@TypeOf(&y)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&y)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/suspend_inside_suspend_block.zig b/test/cases/compile_errors/suspend_inside_suspend_block.zig index 80436bd07f7f..29a7968e0baa 100644 --- a/test/cases/compile_errors/suspend_inside_suspend_block.zig +++ b/test/cases/compile_errors/suspend_inside_suspend_block.zig @@ -3,8 +3,7 @@ export fn entry() void { } fn foo() void { suspend { - suspend { - } + suspend {} } } diff --git a/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong.zig b/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong.zig index 7011f0a2d5a0..58f98a55f57c 100644 --- a/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong.zig +++ b/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong.zig @@ -14,7 +14,9 @@ fn f(n: Number) i32 { } } -export fn entry() usize { return @sizeOf(@TypeOf(&f)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&f)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong_when_else_present.zig b/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong_when_else_present.zig index 89f195937576..045760e287c2 100644 --- a/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong_when_else_present.zig +++ b/test/cases/compile_errors/switch_expression-duplicate_enumeration_prong_when_else_present.zig @@ -15,7 +15,9 @@ fn f(n: Number) i32 { } } -export fn entry() usize { return @sizeOf(@TypeOf(&f)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&f)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-duplicate_or_overlapping_integer_value.zig b/test/cases/compile_errors/switch_expression-duplicate_or_overlapping_integer_value.zig index 60e361a47afe..7d9980d53e1c 100644 --- a/test/cases/compile_errors/switch_expression-duplicate_or_overlapping_integer_value.zig +++ b/test/cases/compile_errors/switch_expression-duplicate_or_overlapping_integer_value.zig @@ -1,12 +1,14 @@ fn foo(x: u8) u8 { return switch (x) { - 0 ... 100 => @as(u8, 0), - 101 ... 200 => 1, - 201, 203 ... 207 => 2, - 206 ... 255 => 3, + 0...100 => @as(u8, 0), + 101...200 => 1, + 201, 203...207 => 2, + 206...255 => 3, }; } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-duplicate_type.zig b/test/cases/compile_errors/switch_expression-duplicate_type.zig index 59c9b0657a26..44f745364c39 100644 --- a/test/cases/compile_errors/switch_expression-duplicate_type.zig +++ b/test/cases/compile_errors/switch_expression-duplicate_type.zig @@ -7,7 +7,9 @@ fn foo(comptime T: type, x: T) u8 { else => 3, }; } -export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } +export fn entry() usize { + return @sizeOf(@TypeOf(foo(u32, 0))); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-duplicate_type_struct_alias.zig b/test/cases/compile_errors/switch_expression-duplicate_type_struct_alias.zig index 797d2bd50d30..4420e575c95f 100644 --- a/test/cases/compile_errors/switch_expression-duplicate_type_struct_alias.zig +++ b/test/cases/compile_errors/switch_expression-duplicate_type_struct_alias.zig @@ -11,7 +11,9 @@ fn foo(comptime T: type, x: T) u8 { else => 3, }; } -export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } +export fn entry() usize { + return @sizeOf(@TypeOf(foo(u32, 0))); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-missing_enumeration_prong.zig b/test/cases/compile_errors/switch_expression-missing_enumeration_prong.zig index 1075b837de7f..ca80d420ff93 100644 --- a/test/cases/compile_errors/switch_expression-missing_enumeration_prong.zig +++ b/test/cases/compile_errors/switch_expression-missing_enumeration_prong.zig @@ -12,7 +12,9 @@ fn f(n: Number) i32 { } } -export fn entry() usize { return @sizeOf(@TypeOf(&f)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&f)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-non_exhaustive_integer_prongs.zig b/test/cases/compile_errors/switch_expression-non_exhaustive_integer_prongs.zig index 6770b5a0555c..83097f273391 100644 --- a/test/cases/compile_errors/switch_expression-non_exhaustive_integer_prongs.zig +++ b/test/cases/compile_errors/switch_expression-non_exhaustive_integer_prongs.zig @@ -3,7 +3,9 @@ fn foo(x: u8) void { 0 => {}, } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-switch_on_pointer_type_with_no_else.zig b/test/cases/compile_errors/switch_expression-switch_on_pointer_type_with_no_else.zig index bbad58c74c84..32491170ebbd 100644 --- a/test/cases/compile_errors/switch_expression-switch_on_pointer_type_with_no_else.zig +++ b/test/cases/compile_errors/switch_expression-switch_on_pointer_type_with_no_else.zig @@ -4,7 +4,9 @@ fn foo(x: *u8) void { } } var y: u8 = 100; -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-unreachable_else_prong_bool.zig b/test/cases/compile_errors/switch_expression-unreachable_else_prong_bool.zig index 5dfc839c13f6..859f97fa8af5 100644 --- a/test/cases/compile_errors/switch_expression-unreachable_else_prong_bool.zig +++ b/test/cases/compile_errors/switch_expression-unreachable_else_prong_bool.zig @@ -5,7 +5,9 @@ fn foo(x: bool) void { else => {}, } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-unreachable_else_prong_enum.zig b/test/cases/compile_errors/switch_expression-unreachable_else_prong_enum.zig index cc837b8b5e1f..e7bb8d392f0d 100644 --- a/test/cases/compile_errors/switch_expression-unreachable_else_prong_enum.zig +++ b/test/cases/compile_errors/switch_expression-unreachable_else_prong_enum.zig @@ -1,4 +1,4 @@ -const TestEnum = enum{ T1, T2 }; +const TestEnum = enum { T1, T2 }; fn err(x: u8) TestEnum { switch (x) { @@ -15,7 +15,9 @@ fn foo(x: u8) void { } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=llvm diff --git a/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_i8.zig b/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_i8.zig index bcb84eed122d..861b0ceaeece 100644 --- a/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_i8.zig +++ b/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_i8.zig @@ -8,7 +8,9 @@ fn foo(x: i8) void { else => {}, } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_u8.zig b/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_u8.zig index 2230434ea065..16fdea91ea17 100644 --- a/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_u8.zig +++ b/test/cases/compile_errors/switch_expression-unreachable_else_prong_range_u8.zig @@ -8,7 +8,9 @@ fn foo(x: u8) void { else => {}, } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-unreachable_else_prong_u1.zig b/test/cases/compile_errors/switch_expression-unreachable_else_prong_u1.zig index 58458474a4fc..3d7988454e27 100644 --- a/test/cases/compile_errors/switch_expression-unreachable_else_prong_u1.zig +++ b/test/cases/compile_errors/switch_expression-unreachable_else_prong_u1.zig @@ -5,7 +5,9 @@ fn foo(x: u1) void { else => {}, } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_expression-unreachable_else_prong_u2.zig b/test/cases/compile_errors/switch_expression-unreachable_else_prong_u2.zig index 9e337cb2007c..dd8f315dcdb1 100644 --- a/test/cases/compile_errors/switch_expression-unreachable_else_prong_u2.zig +++ b/test/cases/compile_errors/switch_expression-unreachable_else_prong_u2.zig @@ -7,7 +7,9 @@ fn foo(x: u2) void { else => {}, } } -export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&foo)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig b/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig index 4d8742d32e1a..bf5c97eaa61c 100644 --- a/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig +++ b/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig @@ -4,7 +4,7 @@ const Payload = union { C: bool, }; export fn entry() void { - const a = Payload { .A = 1234 }; + const a = Payload{ .A = 1234 }; foo(&a); } fn foo(a: *const Payload) void { diff --git a/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig b/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig index 3dad0be9df20..e3d09bc13333 100644 --- a/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig +++ b/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig @@ -1,4 +1,4 @@ -const E = enum{ +const E = enum { a, b, }; diff --git a/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig b/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig index 435d409dd48e..5678102fc6c5 100644 --- a/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig +++ b/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig @@ -22,7 +22,7 @@ pub export fn entry2() void { } } pub export fn entry3() void { - var u = U{.a = 2}; + var u = U{ .a = 2 }; switch (u) { // error: `_` prong not allowed when switching on tagged union .a => {}, .b => {}, diff --git a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig index 1de0d1c14501..1abd36accfd6 100644 --- a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig +++ b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig @@ -1,5 +1,5 @@ test "enum" { - const E = enum(u8) {A, B, _}; + const E = enum(u8) { A, B, _ }; _ = @tagName(@intToEnum(E, 5)); } diff --git a/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig b/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig index cbe0f642a5fb..28eaa9bad815 100644 --- a/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig +++ b/test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig @@ -3,7 +3,7 @@ const FloatInt = extern union { Int: i32, }; export fn entry() void { - var fi = FloatInt{.Float = 123.45}; + var fi = FloatInt{ .Float = 123.45 }; var tagName = @tagName(fi); _ = tagName; } diff --git a/test/cases/compile_errors/top_level_decl_dependency_loop.zig b/test/cases/compile_errors/top_level_decl_dependency_loop.zig index 8ba3d98ea28f..5657ca52fe3c 100644 --- a/test/cases/compile_errors/top_level_decl_dependency_loop.zig +++ b/test/cases/compile_errors/top_level_decl_dependency_loop.zig @@ -1,5 +1,5 @@ -const a : @TypeOf(b) = 0; -const b : @TypeOf(a) = 0; +const a: @TypeOf(b) = 0; +const b: @TypeOf(a) = 0; export fn entry() void { const c = a + b; _ = c; diff --git a/test/cases/compile_errors/try_in_function_with_non_error_return_type.zig b/test/cases/compile_errors/try_in_function_with_non_error_return_type.zig index 44d8b9ee56ee..96b098237034 100644 --- a/test/cases/compile_errors/try_in_function_with_non_error_return_type.zig +++ b/test/cases/compile_errors/try_in_function_with_non_error_return_type.zig @@ -1,7 +1,7 @@ export fn f() void { try something(); } -fn something() anyerror!void { } +fn something() anyerror!void {} // error // backend=stage2 diff --git a/test/cases/compile_errors/tuple_init_edge_cases.zig b/test/cases/compile_errors/tuple_init_edge_cases.zig index 32b52cdc1f0f..fe6f5c926131 100644 --- a/test/cases/compile_errors/tuple_init_edge_cases.zig +++ b/test/cases/compile_errors/tuple_init_edge_cases.zig @@ -1,37 +1,49 @@ pub export fn entry1() void { const T = @TypeOf(.{ 123, 3 }); - var b = T{ .@"1" = 3 }; _ = b; - var c = T{ 123, 3 }; _ = c; - var d = T{}; _ = d; + var b = T{ .@"1" = 3 }; + _ = b; + var c = T{ 123, 3 }; + _ = c; + var d = T{}; + _ = d; } pub export fn entry2() void { var a: u32 = 2; const T = @TypeOf(.{ 123, a }); - var b = T{ .@"1" = 3 }; _ = b; - var c = T{ 123, 3 }; _ = c; - var d = T{}; _ = d; + var b = T{ .@"1" = 3 }; + _ = b; + var c = T{ 123, 3 }; + _ = c; + var d = T{}; + _ = d; } pub export fn entry3() void { var a: u32 = 2; const T = @TypeOf(.{ 123, a }); - var b = T{ .@"0" = 123 }; _ = b; + var b = T{ .@"0" = 123 }; + _ = b; } comptime { var a: u32 = 2; const T = @TypeOf(.{ 123, a }); - var b = T{ .@"0" = 123 }; _ = b; - var c = T{ 123, 2 }; _ = c; - var d = T{}; _ = d; + var b = T{ .@"0" = 123 }; + _ = b; + var c = T{ 123, 2 }; + _ = c; + var d = T{}; + _ = d; } pub export fn entry4() void { var a: u32 = 2; const T = @TypeOf(.{ 123, a }); - var b = T{ 123, 4, 5 }; _ = b; + var b = T{ 123, 4, 5 }; + _ = b; } pub export fn entry5() void { var a: u32 = 2; const T = @TypeOf(.{ 123, a }); - var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 }; _ = b; + var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 }; + _ = b; } // error diff --git a/test/cases/compile_errors/type_checking_function_pointers.zig b/test/cases/compile_errors/type_checking_function_pointers.zig index f11330917061..dd980558a8be 100644 --- a/test/cases/compile_errors/type_checking_function_pointers.zig +++ b/test/cases/compile_errors/type_checking_function_pointers.zig @@ -1,7 +1,9 @@ fn a(b: *const fn (*const u8) void) void { _ = b; } -fn c(d: u8) void {_ = d;} +fn c(d: u8) void { + _ = d; +} export fn entry() void { a(c); } diff --git a/test/cases/compile_errors/undeclared_identifier.zig b/test/cases/compile_errors/undeclared_identifier.zig index 7edc0d2896bf..c7eb94e370d7 100644 --- a/test/cases/compile_errors/undeclared_identifier.zig +++ b/test/cases/compile_errors/undeclared_identifier.zig @@ -1,7 +1,6 @@ export fn a() void { - return - b + - c; + return b + + c; } // error diff --git a/test/cases/compile_errors/union_auto-enum_value_already_taken.zig b/test/cases/compile_errors/union_auto-enum_value_already_taken.zig index 36b52c96b9bd..da2fefbad5a3 100644 --- a/test/cases/compile_errors/union_auto-enum_value_already_taken.zig +++ b/test/cases/compile_errors/union_auto-enum_value_already_taken.zig @@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) { E = 60, }; export fn entry() void { - var x = MultipleChoice { .C = {} }; + var x = MultipleChoice{ .C = {} }; _ = x; } diff --git a/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig b/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig index 3c1e2d53ef7a..6b70c0eaf4b4 100644 --- a/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig +++ b/test/cases/compile_errors/union_enum_field_does_not_match_enum.zig @@ -10,7 +10,7 @@ const Payload = union(Letter) { D: bool, }; export fn entry() void { - var a = Payload {.A = 1234}; + var a = Payload{ .A = 1234 }; _ = a; } diff --git a/test/cases/compile_errors/unreachable_parameter.zig b/test/cases/compile_errors/unreachable_parameter.zig index 31649744321b..f00b24e07acf 100644 --- a/test/cases/compile_errors/unreachable_parameter.zig +++ b/test/cases/compile_errors/unreachable_parameter.zig @@ -1,5 +1,9 @@ -fn f(a: noreturn) void { _ = a; } -export fn entry() void { f(); } +fn f(a: noreturn) void { + _ = a; +} +export fn entry() void { + f(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/unreachable_with_return.zig b/test/cases/compile_errors/unreachable_with_return.zig index 5293734c8200..10b5e56ce78c 100644 --- a/test/cases/compile_errors/unreachable_with_return.zig +++ b/test/cases/compile_errors/unreachable_with_return.zig @@ -1,5 +1,9 @@ -fn a() noreturn {return;} -export fn entry() void { a(); } +fn a() noreturn { + return; +} +export fn entry() void { + a(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/while_expected_bool_got_error_union.zig b/test/cases/compile_errors/while_expected_bool_got_error_union.zig index ecf3dd0736fa..07b441188371 100644 --- a/test/cases/compile_errors/while_expected_bool_got_error_union.zig +++ b/test/cases/compile_errors/while_expected_bool_got_error_union.zig @@ -1,7 +1,9 @@ export fn foo() void { while (bar()) {} } -fn bar() anyerror!i32 { return 1; } +fn bar() anyerror!i32 { + return 1; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/while_expected_bool_got_optional.zig b/test/cases/compile_errors/while_expected_bool_got_optional.zig index 3db4b7ae74e4..2a2af57ef328 100644 --- a/test/cases/compile_errors/while_expected_bool_got_optional.zig +++ b/test/cases/compile_errors/while_expected_bool_got_optional.zig @@ -1,7 +1,9 @@ export fn foo() void { while (bar()) {} } -fn bar() ?i32 { return 1; } +fn bar() ?i32 { + return 1; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/while_expected_error_union_got_bool.zig b/test/cases/compile_errors/while_expected_error_union_got_bool.zig index f7960437ec55..6d31d2055baa 100644 --- a/test/cases/compile_errors/while_expected_error_union_got_bool.zig +++ b/test/cases/compile_errors/while_expected_error_union_got_bool.zig @@ -1,7 +1,13 @@ export fn foo() void { - while (bar()) |x| {_ = x;} else |err| {_ = err;} + while (bar()) |x| { + _ = x; + } else |err| { + _ = err; + } +} +fn bar() bool { + return true; } -fn bar() bool { return true; } // error // backend=stage2 diff --git a/test/cases/compile_errors/while_expected_error_union_got_optional.zig b/test/cases/compile_errors/while_expected_error_union_got_optional.zig index 5cabd76fce3f..6ebf96dc4c7f 100644 --- a/test/cases/compile_errors/while_expected_error_union_got_optional.zig +++ b/test/cases/compile_errors/while_expected_error_union_got_optional.zig @@ -1,7 +1,13 @@ export fn foo() void { - while (bar()) |x| {_ = x;} else |err| {_ = err;} + while (bar()) |x| { + _ = x; + } else |err| { + _ = err; + } +} +fn bar() ?i32 { + return 1; } -fn bar() ?i32 { return 1; } // error // backend=stage2 diff --git a/test/cases/compile_errors/while_expected_optional_got_bool.zig b/test/cases/compile_errors/while_expected_optional_got_bool.zig index 22b8c1e58c73..5ced72b49266 100644 --- a/test/cases/compile_errors/while_expected_optional_got_bool.zig +++ b/test/cases/compile_errors/while_expected_optional_got_bool.zig @@ -1,7 +1,11 @@ export fn foo() void { - while (bar()) |x| {_ = x;} + while (bar()) |x| { + _ = x; + } +} +fn bar() bool { + return true; } -fn bar() bool { return true; } // error // backend=stage2 diff --git a/test/cases/compile_errors/while_expected_optional_got_error_union.zig b/test/cases/compile_errors/while_expected_optional_got_error_union.zig index 38a8a0dd2038..7bde2c866d29 100644 --- a/test/cases/compile_errors/while_expected_optional_got_error_union.zig +++ b/test/cases/compile_errors/while_expected_optional_got_error_union.zig @@ -1,7 +1,11 @@ export fn foo() void { - while (bar()) |x| {_ = x;} + while (bar()) |x| { + _ = x; + } +} +fn bar() anyerror!i32 { + return 1; } -fn bar() anyerror!i32 { return 1; } // error // backend=stage2 diff --git a/test/cases/compile_errors/write_to_const_global_variable.zig b/test/cases/compile_errors/write_to_const_global_variable.zig index 5ffd3a305d06..075854c45462 100644 --- a/test/cases/compile_errors/write_to_const_global_variable.zig +++ b/test/cases/compile_errors/write_to_const_global_variable.zig @@ -1,8 +1,10 @@ -const x : i32 = 99; +const x: i32 = 99; fn f() void { x = 1; } -export fn entry() void { f(); } +export fn entry() void { + f(); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/wrong_function_type.zig b/test/cases/compile_errors/wrong_function_type.zig index 867bdccc1a6e..6dfa9bd70232 100644 --- a/test/cases/compile_errors/wrong_function_type.zig +++ b/test/cases/compile_errors/wrong_function_type.zig @@ -1,8 +1,16 @@ -const fns = [_]fn() void { a, b, c }; -fn a() i32 {return 0;} -fn b() i32 {return 1;} -fn c() i32 {return 2;} -export fn entry() usize { return @sizeOf(@TypeOf(fns)); } +const fns = [_]fn () void{ a, b, c }; +fn a() i32 { + return 0; +} +fn b() i32 { + return 1; +} +fn c() i32 { + return 2; +} +export fn entry() usize { + return @sizeOf(@TypeOf(fns)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/wrong_number_of_arguments.zig b/test/cases/compile_errors/wrong_number_of_arguments.zig index 05d761de18ca..b83a7a4a3706 100644 --- a/test/cases/compile_errors/wrong_number_of_arguments.zig +++ b/test/cases/compile_errors/wrong_number_of_arguments.zig @@ -1,7 +1,11 @@ export fn a() void { c(1); } -fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; } +fn c(d: i32, e: i32, f: i32) void { + _ = d; + _ = e; + _ = f; +} // error // backend=stage2 diff --git a/test/cases/compile_errors/wrong_number_of_arguments_for_method_fn_call.zig b/test/cases/compile_errors/wrong_number_of_arguments_for_method_fn_call.zig index da6a7be4fa45..ecbd2d02e36a 100644 --- a/test/cases/compile_errors/wrong_number_of_arguments_for_method_fn_call.zig +++ b/test/cases/compile_errors/wrong_number_of_arguments_for_method_fn_call.zig @@ -1,11 +1,15 @@ const Foo = struct { - fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} + fn method(self: *const Foo, a: i32) void { + _ = self; + _ = a; + } }; fn f(foo: *const Foo) void { - foo.method(1, 2); } -export fn entry() usize { return @sizeOf(@TypeOf(&f)); } +export fn entry() usize { + return @sizeOf(@TypeOf(&f)); +} // error // backend=stage2 diff --git a/test/cases/compile_errors/wrong_size_to_an_array_literal.zig b/test/cases/compile_errors/wrong_size_to_an_array_literal.zig index a38d8d4d8587..a58d6d984605 100644 --- a/test/cases/compile_errors/wrong_size_to_an_array_literal.zig +++ b/test/cases/compile_errors/wrong_size_to_an_array_literal.zig @@ -1,5 +1,5 @@ comptime { - const array = [2]u8{1, 2, 3}; + const array = [2]u8{ 1, 2, 3 }; _ = array; } diff --git a/test/cases/compile_errors/wrong_types_given_to_export.zig b/test/cases/compile_errors/wrong_types_given_to_export.zig index 2ae55b4a6317..a5618ebb29b3 100644 --- a/test/cases/compile_errors/wrong_types_given_to_export.zig +++ b/test/cases/compile_errors/wrong_types_given_to_export.zig @@ -1,6 +1,6 @@ -fn entry() callconv(.C) void { } +fn entry() callconv(.C) void {} comptime { - @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); + @export(entry, .{ .name = "entry", .linkage = @as(u32, 1234) }); } // error diff --git a/test/cases/error_in_nested_declaration.zig b/test/cases/error_in_nested_declaration.zig index 3fff746909a5..710b821e6552 100644 --- a/test/cases/error_in_nested_declaration.zig +++ b/test/cases/error_in_nested_declaration.zig @@ -5,7 +5,7 @@ const S = struct { pub fn str(_: @This(), extra: []u32) []i32 { return @bitCast([]i32, extra); } - }, + }, }; pub export fn entry() void { diff --git a/test/cases/safety/@alignCast misaligned.zig b/test/cases/safety/@alignCast misaligned.zig index aed805cf66bf..538e0ecdf69a 100644 --- a/test/cases/safety/@alignCast misaligned.zig +++ b/test/cases/safety/@alignCast misaligned.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { - var array align(4) = [_]u32{0x11111111, 0x11111111}; + var array align(4) = [_]u32{ 0x11111111, 0x11111111 }; const bytes = std.mem.sliceAsBytes(array[0..]); if (foo(bytes) != 0x11111111) return error.Wrong; return error.TestFailed; diff --git a/test/cases/safety/@errSetCast error not present in destination.zig b/test/cases/safety/@errSetCast error not present in destination.zig index 2fd0a912e660..372bd80aa59a 100644 --- a/test/cases/safety/@errSetCast error not present in destination.zig +++ b/test/cases/safety/@errSetCast error not present in destination.zig @@ -7,8 +7,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } std.process.exit(1); } -const Set1 = error{A, B}; -const Set2 = error{A, C}; +const Set1 = error{ A, B }; +const Set2 = error{ A, C }; pub fn main() !void { foo(Set1.B) catch {}; return error.TestFailed; diff --git a/test/cases/safety/@floatToInt cannot fit - negative out of range.zig b/test/cases/safety/@floatToInt cannot fit - negative out of range.zig index fa7e628f4a02..691acd34c298 100644 --- a/test/cases/safety/@floatToInt cannot fit - negative out of range.zig +++ b/test/cases/safety/@floatToInt cannot fit - negative out of range.zig @@ -14,7 +14,7 @@ pub fn main() !void { fn bar(a: f32) i8 { return @floatToInt(i8, a); } -fn baz(_: i8) void { } +fn baz(_: i8) void {} // run // backend=llvm // target=native diff --git a/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig b/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig index 5bab7710b13a..f74dedb87c9d 100644 --- a/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig +++ b/test/cases/safety/@floatToInt cannot fit - negative to unsigned.zig @@ -14,7 +14,7 @@ pub fn main() !void { fn bar(a: f32) u8 { return @floatToInt(u8, a); } -fn baz(_: u8) void { } +fn baz(_: u8) void {} // run // backend=llvm // target=native diff --git a/test/cases/safety/@floatToInt cannot fit - positive out of range.zig b/test/cases/safety/@floatToInt cannot fit - positive out of range.zig index fe931e875153..d4cc7cd2a769 100644 --- a/test/cases/safety/@floatToInt cannot fit - positive out of range.zig +++ b/test/cases/safety/@floatToInt cannot fit - positive out of range.zig @@ -14,7 +14,7 @@ pub fn main() !void { fn bar(a: f32) u8 { return @floatToInt(u8, a); } -fn baz(_: u8) void { } +fn baz(_: u8) void {} // run // backend=llvm // target=native diff --git a/test/cases/safety/bad union field access.zig b/test/cases/safety/bad union field access.zig index fbe7718c6658..c6706d41764d 100644 --- a/test/cases/safety/bad union field access.zig +++ b/test/cases/safety/bad union field access.zig @@ -14,7 +14,7 @@ const Foo = union { }; pub fn main() !void { - var f = Foo { .int = 42 }; + var f = Foo{ .int = 42 }; bar(&f); return error.TestFailed; } diff --git a/test/cases/safety/cast []u8 to bigger slice of wrong size.zig b/test/cases/safety/cast []u8 to bigger slice of wrong size.zig index 93d18178a84f..a72b2fcca2ca 100644 --- a/test/cases/safety/cast []u8 to bigger slice of wrong size.zig +++ b/test/cases/safety/cast []u8 to bigger slice of wrong size.zig @@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { - const x = widenSlice(&[_]u8{1, 2, 3, 4, 5}); + const x = widenSlice(&[_]u8{ 1, 2, 3, 4, 5 }); if (x.len == 0) return error.Whatever; return error.TestFailed; } diff --git a/test/cases/safety/error return trace across suspend points.zig b/test/cases/safety/error return trace across suspend points.zig index 28c53cb6d144..2c31aacc9d2f 100644 --- a/test/cases/safety/error return trace across suspend points.zig +++ b/test/cases/safety/error return trace across suspend points.zig @@ -1,6 +1,5 @@ const std = @import("std"); - pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { _ = message; _ = stack_trace; @@ -36,4 +35,4 @@ fn printTrace(p: anyframe->anyerror!void) void { } // run // backend=stage1 -// target=native \ No newline at end of file +// target=native diff --git a/test/cases/safety/exact division failure - vectors.zig b/test/cases/safety/exact division failure - vectors.zig index 3c515cbdf118..cc8c01db9e3b 100644 --- a/test/cases/safety/exact division failure - vectors.zig +++ b/test/cases/safety/exact division failure - vectors.zig @@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi } pub fn main() !void { - var a: @Vector(4, i32) = [4]i32{111, 222, 333, 444}; - var b: @Vector(4, i32) = [4]i32{111, 222, 333, 441}; + var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; + var b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 }; const x = divExact(a, b); _ = x; return error.TestFailed; diff --git a/test/cases/safety/for_len_mismatch_three.zig b/test/cases/safety/for_len_mismatch_three.zig index 95bc24426994..0cfcddbfeecc 100644 --- a/test/cases/safety/for_len_mismatch_three.zig +++ b/test/cases/safety/for_len_mismatch_three.zig @@ -21,4 +21,3 @@ pub fn main() !void { // run // backend=llvm // target=native - diff --git a/test/cases/safety/integer division by zero - vectors.zig b/test/cases/safety/integer division by zero - vectors.zig index ed7ac7777b4b..a376b66fdb85 100644 --- a/test/cases/safety/integer division by zero - vectors.zig +++ b/test/cases/safety/integer division by zero - vectors.zig @@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi std.process.exit(1); } pub fn main() !void { - var a: @Vector(4, i32) = [4]i32{111, 222, 333, 444}; - var b: @Vector(4, i32) = [4]i32{111, 0, 333, 444}; + var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 }; + var b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 }; const x = div0(a, b); _ = x; return error.TestFailed; diff --git a/test/cases/unused_labels.3.zig b/test/cases/unused_labels.3.zig index e4f3ac05a404..36c9aa2319b0 100644 --- a/test/cases/unused_labels.3.zig +++ b/test/cases/unused_labels.3.zig @@ -1,5 +1,7 @@ comptime { - blk: {blk: {}} + blk: { + blk: {} + } } // error diff --git a/test/cases/variable_shadowing.3.zig b/test/cases/variable_shadowing.3.zig index 3d899e72cc86..af16bccc1478 100644 --- a/test/cases/variable_shadowing.3.zig +++ b/test/cases/variable_shadowing.3.zig @@ -1,7 +1,6 @@ pub fn main() void { var i = 0; - for ("n", 0..) |_, i| { - } + for ("n", 0..) |_, i| {} } // error diff --git a/test/cases/variable_shadowing.4.zig b/test/cases/variable_shadowing.4.zig index ab9f93d17d4a..3653c2457de7 100644 --- a/test/cases/variable_shadowing.4.zig +++ b/test/cases/variable_shadowing.4.zig @@ -1,7 +1,6 @@ pub fn main() void { var i = 0; - for ("n") |i| { - } + for ("n") |i| {} } // error diff --git a/test/cases/variable_shadowing.5.zig b/test/cases/variable_shadowing.5.zig index 1a5676190ada..78247e68feaa 100644 --- a/test/cases/variable_shadowing.5.zig +++ b/test/cases/variable_shadowing.5.zig @@ -1,7 +1,6 @@ pub fn main() void { var i = 0; - while ("n") |i| { - } + while ("n") |i| {} } // error diff --git a/test/cases/variable_shadowing.6.zig b/test/cases/variable_shadowing.6.zig index 894a398b61de..a3ae7bc34687 100644 --- a/test/cases/variable_shadowing.6.zig +++ b/test/cases/variable_shadowing.6.zig @@ -2,9 +2,7 @@ pub fn main() void { var i = 0; while ("n") |bruh| { _ = bruh; - } else |i| { - - } + } else |i| {} } // error diff --git a/test/cases/x86_64-linux/inline_assembly.2.zig b/test/cases/x86_64-linux/inline_assembly.2.zig index 1695265ab4eb..7958d0df71ea 100644 --- a/test/cases/x86_64-linux/inline_assembly.2.zig +++ b/test/cases/x86_64-linux/inline_assembly.2.zig @@ -2,7 +2,7 @@ pub fn main() void { var bruh: u32 = 1; asm ("" : - : [bruh] "{rax}" (4) + : [bruh] "{rax}" (4), : "memory" ); } diff --git a/test/cases/x86_64-linux/inline_assembly.3.zig b/test/cases/x86_64-linux/inline_assembly.3.zig index 765eaeb97eb2..a6f57e832a74 100644 --- a/test/cases/x86_64-linux/inline_assembly.3.zig +++ b/test/cases/x86_64-linux/inline_assembly.3.zig @@ -2,7 +2,7 @@ pub fn main() void {} comptime { asm ("" : - : [bruh] "{rax}" (4) + : [bruh] "{rax}" (4), : "memory" ); } diff --git a/test/link/bss/build.zig b/test/link/bss/build.zig index 3c7964fae1ef..d9cfeda96dd1 100644 --- a/test/link/bss/build.zig +++ b/test/link/bss/build.zig @@ -4,9 +4,12 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test"); b.default_step = test_step; + const mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const exe = b.addExecutable(.{ .name = "bss", - .root_source_file = .{ .path = "main.zig" }, + .main_module = mod, .optimize = .Debug, }); diff --git a/test/link/common_symbols/build.zig b/test/link/common_symbols/build.zig index a2104e1ac27b..9287f864f18f 100644 --- a/test/link/common_symbols/build.zig +++ b/test/link/common_symbols/build.zig @@ -11,15 +11,22 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_a_mod = b.createModule(.{ .c_source_files = .{ + .files = &.{ "c.c", "a.c", "b.c" }, + .flags = &.{"-fcommon"}, + } }); const lib_a = b.addStaticLibrary(.{ .name = "a", + .main_module = lib_a_mod, .optimize = optimize, .target = .{}, }); - lib_a.addCSourceFiles(&.{ "c.c", "a.c", "b.c" }, &.{"-fcommon"}); + const test_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = test_mod, .optimize = optimize, }); test_exe.linkLibrary(lib_a); diff --git a/test/link/common_symbols_alignment/build.zig b/test/link/common_symbols_alignment/build.zig index 4cb253dc05e0..552bdb9ff643 100644 --- a/test/link/common_symbols_alignment/build.zig +++ b/test/link/common_symbols_alignment/build.zig @@ -11,15 +11,24 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_a_module = b.createModule(.{ + .c_source_files = .{ + .files = &.{"a.c"}, + .flags = &.{"-fcommon"}, + }, + }); const lib_a = b.addStaticLibrary(.{ .name = "a", + .main_module = lib_a_module, .optimize = optimize, .target = .{}, }); - lib_a.addCSourceFiles(&.{"a.c"}, &.{"-fcommon"}); + const test_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = test_mod, .optimize = optimize, }); test_exe.linkLibrary(lib_a); diff --git a/test/link/glibc_compat/build.zig b/test/link/glibc_compat/build.zig index 8d850cf350cc..f27f8ac59d6e 100644 --- a/test/link/glibc_compat/build.zig +++ b/test/link/glibc_compat/build.zig @@ -5,9 +5,12 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; inline for (.{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { + const mod = b.createModule(.{ + .source_file = .{ .path = "main.c" }, + }); const exe = b.addExecutable(.{ .name = t, - .root_source_file = .{ .path = "main.c" }, + .main_module = mod, .target = std.zig.CrossTarget.parse( .{ .arch_os_abi = t }, ) catch unreachable, diff --git a/test/link/interdependent_static_c_libs/build.zig b/test/link/interdependent_static_c_libs/build.zig index 2eb8fa27b4e7..5129feabdce4 100644 --- a/test/link/interdependent_static_c_libs/build.zig +++ b/test/link/interdependent_static_c_libs/build.zig @@ -11,24 +11,39 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_a_module = b.createModule(.{ + .c_source_files = .{ + .files = &.{"a.c"}, + .flags = &.{}, + }, + }); const lib_a = b.addStaticLibrary(.{ .name = "a", + .main_module = lib_a_module, .optimize = optimize, .target = .{}, }); - lib_a.addCSourceFile("a.c", &[_][]const u8{}); lib_a.addIncludePath("."); + const lib_b_module = b.createModule(.{ + .c_source_files = .{ + .files = &.{"b.c"}, + .flags = &.{}, + }, + }); const lib_b = b.addStaticLibrary(.{ .name = "b", + .main_module = lib_b_module, .optimize = optimize, .target = .{}, }); - lib_b.addCSourceFile("b.c", &[_][]const u8{}); lib_b.addIncludePath("."); + const test_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = test_mod, .optimize = optimize, }); test_exe.linkLibrary(lib_a); diff --git a/test/link/macho/bugs/13056/build.zig b/test/link/macho/bugs/13056/build.zig index 1ac50a61c62d..10ed56e8d66a 100644 --- a/test/link/macho/bugs/13056/build.zig +++ b/test/link/macho/bugs/13056/build.zig @@ -19,16 +19,22 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const sdk = std.zig.system.darwin.getDarwinSDK(b.allocator, target_info.target) orelse @panic("macOS SDK is required to run the test"); + const exe_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"test.cpp"}, + .flags = &.{ + "-nostdlib++", + "-nostdinc++", + }, + }, + }); const exe = b.addExecutable(.{ .name = "test", + .main_module = exe_mod, .optimize = optimize, }); exe.addSystemIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable); exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable); - exe.addCSourceFile("test.cpp", &.{ - "-nostdlib++", - "-nostdinc++", - }); exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable); const run_cmd = b.addRunArtifact(exe); diff --git a/test/link/macho/bugs/13457/build.zig b/test/link/macho/bugs/13457/build.zig index 89096bba387d..9dc8d3578000 100644 --- a/test/link/macho/bugs/13457/build.zig +++ b/test/link/macho/bugs/13457/build.zig @@ -15,9 +15,12 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "main.zig" }, + .main_module = mod, .optimize = optimize, .target = target, }); diff --git a/test/link/macho/dead_strip/build.zig b/test/link/macho/dead_strip/build.zig index 4c739b3d8c6c..5fe8858e2c23 100644 --- a/test/link/macho/dead_strip/build.zig +++ b/test/link/macho/dead_strip/build.zig @@ -43,12 +43,18 @@ fn createScenario( target: std.zig.CrossTarget, name: []const u8, ) *std.Build.CompileStep { + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = name, + .main_module = mod, .optimize = optimize, .target = target, }); - exe.addCSourceFile("main.c", &[0][]const u8{}); exe.linkLibC(); return exe; } diff --git a/test/link/macho/dead_strip_dylibs/build.zig b/test/link/macho/dead_strip_dylibs/build.zig index 47e53f853e26..b6debe52498a 100644 --- a/test/link/macho/dead_strip_dylibs/build.zig +++ b/test/link/macho/dead_strip_dylibs/build.zig @@ -49,6 +49,7 @@ fn createScenario( ) *std.Build.CompileStep { const exe = b.addExecutable(.{ .name = name, + .main_module = b.createModule(.{}), .optimize = optimize, }); exe.addCSourceFile("main.c", &[0][]const u8{}); diff --git a/test/link/macho/dylib/build.zig b/test/link/macho/dylib/build.zig index a4085b51e620..d7aa78ba497b 100644 --- a/test/link/macho/dylib/build.zig +++ b/test/link/macho/dylib/build.zig @@ -15,13 +15,19 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const dylib_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"a.c"}, + .flags = &.{}, + }, + }); const dylib = b.addSharedLibrary(.{ .name = "a", .version = .{ .major = 1, .minor = 0 }, + .main_module = dylib_mod, .optimize = optimize, .target = target, }); - dylib.addCSourceFile("a.c", &.{}); dylib.linkLibC(); const check_dylib = dylib.checkObject(); @@ -33,12 +39,18 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_step.dependOn(&check_dylib.step); + const exe_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "main", + .main_module = exe_mod, .optimize = optimize, .target = target, }); - exe.addCSourceFile("main.c", &.{}); exe.linkSystemLibrary("a"); exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource()); exe.addRPathDirectorySource(dylib.getOutputDirectorySource()); diff --git a/test/link/macho/empty/build.zig b/test/link/macho/empty/build.zig index 9933746d533a..6fb65c92aee5 100644 --- a/test/link/macho/empty/build.zig +++ b/test/link/macho/empty/build.zig @@ -15,13 +15,18 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{ "main.c", "empty.c" }, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "test", + .main_module = mod, .optimize = optimize, .target = target, }); - exe.addCSourceFile("main.c", &[0][]const u8{}); - exe.addCSourceFile("empty.c", &[0][]const u8{}); exe.linkLibC(); const run_cmd = b.addRunArtifact(exe); diff --git a/test/link/macho/entry/build.zig b/test/link/macho/entry/build.zig index e983bc9391cf..64fa86d56cdb 100644 --- a/test/link/macho/entry/build.zig +++ b/test/link/macho/entry/build.zig @@ -13,12 +13,18 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "main", + .main_module = mod, .optimize = optimize, .target = .{ .os_tag = .macos }, }); - exe.addCSourceFile("main.c", &.{}); exe.linkLibC(); exe.entry_symbol_name = "_non_main"; diff --git a/test/link/macho/entry_in_archive/build.zig b/test/link/macho/entry_in_archive/build.zig index f4b04bd162aa..f1fb6bf01005 100644 --- a/test/link/macho/entry_in_archive/build.zig +++ b/test/link/macho/entry_in_archive/build.zig @@ -13,16 +13,24 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const lib = b.addStaticLibrary(.{ .name = "main", + .main_module = lib_mod, .optimize = optimize, .target = .{ .os_tag = .macos }, }); - lib.addCSourceFile("main.c", &.{}); lib.linkLibC(); + const exe_mod = b.createModule(.{}); const exe = b.addExecutable(.{ .name = "main", + .main_module = exe_mod, .optimize = optimize, .target = .{ .os_tag = .macos }, }); diff --git a/test/link/macho/entry_in_dylib/build.zig b/test/link/macho/entry_in_dylib/build.zig index 135661872dbb..ddd6623fa90c 100644 --- a/test/link/macho/entry_in_dylib/build.zig +++ b/test/link/macho/entry_in_dylib/build.zig @@ -13,21 +13,33 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"bootstrap.c"}, + .flags = &.{}, + }, + }); const lib = b.addSharedLibrary(.{ .name = "bootstrap", + .main_module = lib_mod, .optimize = optimize, .target = .{ .os_tag = .macos }, }); - lib.addCSourceFile("bootstrap.c", &.{}); lib.linkLibC(); lib.linker_allow_shlib_undefined = true; + const exe_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "main", + .main_module = exe_mod, .optimize = optimize, .target = .{ .os_tag = .macos }, }); - exe.addCSourceFile("main.c", &.{}); exe.linkLibrary(lib); exe.linkLibC(); exe.entry_symbol_name = "_bootstrap"; diff --git a/test/link/macho/headerpad/build.zig b/test/link/macho/headerpad/build.zig index 22cfcc90eca2..6686b038be4c 100644 --- a/test/link/macho/headerpad/build.zig +++ b/test/link/macho/headerpad/build.zig @@ -107,6 +107,7 @@ fn simpleExe( ) *std.Build.CompileStep { const exe = b.addExecutable(.{ .name = name, + .main_module = b.createModule(.{}), .optimize = optimize, }); exe.addCSourceFile("main.c", &.{}); diff --git a/test/link/macho/linksection/build.zig b/test/link/macho/linksection/build.zig index b8b3a59f35ba..e5814b8bfaa6 100644 --- a/test/link/macho/linksection/build.zig +++ b/test/link/macho/linksection/build.zig @@ -17,7 +17,9 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const obj = b.addObject(.{ .name = "test", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = target, }); diff --git a/test/link/macho/needed_framework/build.zig b/test/link/macho/needed_framework/build.zig index fc80a44f734b..b13704c826d9 100644 --- a/test/link/macho/needed_framework/build.zig +++ b/test/link/macho/needed_framework/build.zig @@ -16,11 +16,17 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { // -dead_strip_dylibs // -needed_framework Cocoa + const exe_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "test", + .main_module = exe_mod, .optimize = optimize, }); - exe.addCSourceFile("main.c", &[0][]const u8{}); exe.linkLibC(); exe.linkFrameworkNeeded("Cocoa"); exe.dead_strip_dylibs = true; diff --git a/test/link/macho/needed_library/build.zig b/test/link/macho/needed_library/build.zig index cb9ea38d4bcc..08a90a75a833 100644 --- a/test/link/macho/needed_library/build.zig +++ b/test/link/macho/needed_library/build.zig @@ -15,23 +15,35 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const dylib_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"a.c"}, + .flags = &.{}, + }, + }); const dylib = b.addSharedLibrary(.{ .name = "a", + .main_module = dylib_mod, .version = .{ .major = 1, .minor = 0 }, .optimize = optimize, .target = target, }); - dylib.addCSourceFile("a.c", &.{}); dylib.linkLibC(); // -dead_strip_dylibs // -needed-la + const exe_mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "test", + .main_module = exe_mod, .optimize = optimize, .target = target, }); - exe.addCSourceFile("main.c", &[0][]const u8{}); exe.linkLibC(); exe.linkSystemLibraryNeeded("a"); exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource()); diff --git a/test/link/macho/objc/build.zig b/test/link/macho/objc/build.zig index 4cd12f786fe1..290be5d87686 100644 --- a/test/link/macho/objc/build.zig +++ b/test/link/macho/objc/build.zig @@ -14,13 +14,18 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{ "Foo.m", "test.m" }, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "test", + .main_module = mod, .optimize = optimize, }); exe.addIncludePath("."); - exe.addCSourceFile("Foo.m", &[0][]const u8{}); - exe.addCSourceFile("test.m", &[0][]const u8{}); exe.linkLibC(); // TODO when we figure out how to ship framework stubs for cross-compilation, // populate paths to the sysroot here. diff --git a/test/link/macho/objcpp/build.zig b/test/link/macho/objcpp/build.zig index aebf0e17fd93..8483744d6955 100644 --- a/test/link/macho/objcpp/build.zig +++ b/test/link/macho/objcpp/build.zig @@ -14,14 +14,19 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{ "Foo.mm", "test.mm" }, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "test", + .main_module = mod, .optimize = optimize, }); b.default_step.dependOn(&exe.step); exe.addIncludePath("."); - exe.addCSourceFile("Foo.mm", &[0][]const u8{}); - exe.addCSourceFile("test.mm", &[0][]const u8{}); exe.linkLibCpp(); // TODO when we figure out how to ship framework stubs for cross-compilation, // populate paths to the sysroot here. diff --git a/test/link/macho/pagezero/build.zig b/test/link/macho/pagezero/build.zig index b467df2b20b7..fa548ef6aed1 100644 --- a/test/link/macho/pagezero/build.zig +++ b/test/link/macho/pagezero/build.zig @@ -10,12 +10,18 @@ pub fn build(b: *std.Build) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; { + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "pagezero", + .main_module = mod, .optimize = optimize, .target = target, }); - exe.addCSourceFile("main.c", &.{}); exe.linkLibC(); exe.pagezero_size = 0x4000; @@ -32,12 +38,18 @@ pub fn build(b: *std.Build) void { } { + const mod = b.createModule(.{ + .c_source_files = .{ + .files = &.{"main.c"}, + .flags = &.{}, + }, + }); const exe = b.addExecutable(.{ .name = "no_pagezero", + .main_module = mod, .optimize = optimize, .target = target, }); - exe.addCSourceFile("main.c", &.{}); exe.linkLibC(); exe.pagezero_size = 0; diff --git a/test/link/macho/search_strategy/build.zig b/test/link/macho/search_strategy/build.zig index 4777629c8b9a..cdcb2c3effcc 100644 --- a/test/link/macho/search_strategy/build.zig +++ b/test/link/macho/search_strategy/build.zig @@ -49,6 +49,7 @@ fn createScenario( ) *std.Build.CompileStep { const static = b.addStaticLibrary(.{ .name = name, + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); @@ -60,6 +61,7 @@ fn createScenario( const dylib = b.addSharedLibrary(.{ .name = name, + .main_module = b.createModule(.{}), .version = .{ .major = 1, .minor = 0 }, .optimize = optimize, .target = target, @@ -72,6 +74,7 @@ fn createScenario( const exe = b.addExecutable(.{ .name = name, + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); diff --git a/test/link/macho/stack_size/build.zig b/test/link/macho/stack_size/build.zig index c7d308d004e4..b245e1e0f11c 100644 --- a/test/link/macho/stack_size/build.zig +++ b/test/link/macho/stack_size/build.zig @@ -15,8 +15,10 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const mod = b.createModule(.{}); const exe = b.addExecutable(.{ .name = "main", + .main_module = mod, .optimize = optimize, .target = target, }); diff --git a/test/link/macho/strict_validation/build.zig b/test/link/macho/strict_validation/build.zig index 34a0cd73fc1c..facce5a65b59 100644 --- a/test/link/macho/strict_validation/build.zig +++ b/test/link/macho/strict_validation/build.zig @@ -16,9 +16,12 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const exe = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = mod, .optimize = optimize, .target = target, }); diff --git a/test/link/macho/tls/build.zig b/test/link/macho/tls/build.zig index f155f514f881..23cb4beb9be7 100644 --- a/test/link/macho/tls/build.zig +++ b/test/link/macho/tls/build.zig @@ -15,8 +15,10 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const lib_mod = b.createModule(.{}); const lib = b.addSharedLibrary(.{ .name = "a", + .main_module = lib_mod, .version = .{ .major = 1, .minor = 0 }, .optimize = optimize, .target = target, @@ -24,8 +26,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize lib.addCSourceFile("a.c", &.{}); lib.linkLibC(); + const test_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = test_mod, .optimize = optimize, .target = target, }); diff --git a/test/link/macho/unwind_info/build.zig b/test/link/macho/unwind_info/build.zig index 4ace2a4e96d3..6e3ba8e1169b 100644 --- a/test/link/macho/unwind_info/build.zig +++ b/test/link/macho/unwind_info/build.zig @@ -68,6 +68,7 @@ fn createScenario( ) *std.Build.CompileStep { const exe = b.addExecutable(.{ .name = name, + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); diff --git a/test/link/macho/weak_framework/build.zig b/test/link/macho/weak_framework/build.zig index 5dfd421243ff..3c7e8b664d93 100644 --- a/test/link/macho/weak_framework/build.zig +++ b/test/link/macho/weak_framework/build.zig @@ -16,6 +16,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "test", + .main_module = b.createModule(.{}), .optimize = optimize, }); exe.addCSourceFile("main.c", &[0][]const u8{}); diff --git a/test/link/macho/weak_library/build.zig b/test/link/macho/weak_library/build.zig index 88d72ad48775..5c3292a1dccc 100644 --- a/test/link/macho/weak_library/build.zig +++ b/test/link/macho/weak_library/build.zig @@ -15,8 +15,10 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const target: std.zig.CrossTarget = .{ .os_tag = .macos }; + const dylib_mod = b.createModule(.{}); const dylib = b.addSharedLibrary(.{ .name = "a", + .main_module = dylib_mod, .version = .{ .major = 1, .minor = 0, .patch = 0 }, .target = target, .optimize = optimize, @@ -25,8 +27,10 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize dylib.linkLibC(); b.installArtifact(dylib); + const exe_mod = b.createModule(.{}); const exe = b.addExecutable(.{ .name = "test", + .main_module = exe_mod, .target = target, .optimize = optimize, }); diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig index 120134af196e..0e67fc493b71 100644 --- a/test/link/wasm/archive/build.zig +++ b/test/link/wasm/archive/build.zig @@ -15,9 +15,12 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { // The code in question will pull-in compiler-rt, // and therefore link with its archive file. + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = lib_mod, .optimize = optimize, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, }); diff --git a/test/link/wasm/basic-features/build.zig b/test/link/wasm/basic-features/build.zig index be709a698fa2..f3c14c10afe8 100644 --- a/test/link/wasm/basic-features/build.zig +++ b/test/link/wasm/basic-features/build.zig @@ -4,9 +4,12 @@ pub const requires_stage2 = true; pub fn build(b: *std.Build) void { // Library with explicitly set cpu features + const mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "main.zig" }, + .main_module = mod, .optimize = .Debug, .target = .{ .cpu_arch = .wasm32, diff --git a/test/link/wasm/bss/build.zig b/test/link/wasm/bss/build.zig index 4a26e78a1200..652e5c7554a5 100644 --- a/test/link/wasm/bss/build.zig +++ b/test/link/wasm/bss/build.zig @@ -14,9 +14,12 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode, is_safe: bool) void { { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize_mode, }); @@ -57,9 +60,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt // verify zero'd declaration is stored in bss for all optimization modes. { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib2.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib2.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize_mode, }); diff --git a/test/link/wasm/export-data/build.zig b/test/link/wasm/export-data/build.zig index 38b8c3e19e82..135bb3f50e79 100644 --- a/test/link/wasm/export-data/build.zig +++ b/test/link/wasm/export-data/build.zig @@ -9,9 +9,12 @@ pub fn build(b: *std.Build) void { return; } + const mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = mod, .optimize = .ReleaseSafe, // to make the output deterministic in address positions .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, }); diff --git a/test/link/wasm/export/build.zig b/test/link/wasm/export/build.zig index 794201dbf6c9..d68d2bc64474 100644 --- a/test/link/wasm/export/build.zig +++ b/test/link/wasm/export/build.zig @@ -13,18 +13,24 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const no_export_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const no_export = b.addSharedLibrary(.{ .name = "no-export", - .root_source_file = .{ .path = "main.zig" }, + .main_module = no_export_mod, .optimize = optimize, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, }); no_export.use_llvm = false; no_export.use_lld = false; + const dynamic_export_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const dynamic_export = b.addSharedLibrary(.{ .name = "dynamic", - .root_source_file = .{ .path = "main.zig" }, + .main_module = dynamic_export_mod, .optimize = optimize, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, }); @@ -32,9 +38,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize dynamic_export.use_llvm = false; dynamic_export.use_lld = false; + const force_export_mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const force_export = b.addSharedLibrary(.{ .name = "force", - .root_source_file = .{ .path = "main.zig" }, + .main_module = force_export_mod, .optimize = optimize, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, }); diff --git a/test/link/wasm/extern-mangle/build.zig b/test/link/wasm/extern-mangle/build.zig index 6c292acbab6e..fd9291ad1be2 100644 --- a/test/link/wasm/extern-mangle/build.zig +++ b/test/link/wasm/extern-mangle/build.zig @@ -11,9 +11,12 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); diff --git a/test/link/wasm/extern/build.zig b/test/link/wasm/extern/build.zig index 55562143c2f0..472b171ee287 100644 --- a/test/link/wasm/extern/build.zig +++ b/test/link/wasm/extern/build.zig @@ -13,13 +13,16 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const exe_mod = b.createModule(.{ .source_file = .{ .path = "main.zig" }, .c_source_files = .{ + .files = &.{"foo.c"}, + .flags = &.{}, + } }); const exe = b.addExecutable(.{ .name = "extern", - .root_source_file = .{ .path = "main.zig" }, + .main_module = exe_mod, .optimize = optimize, .target = .{ .cpu_arch = .wasm32, .os_tag = .wasi }, }); - exe.addCSourceFile("foo.c", &.{}); exe.use_llvm = false; exe.use_lld = false; diff --git a/test/link/wasm/function-table/build.zig b/test/link/wasm/function-table/build.zig index 4ce62947277b..9cb10bbcc0b3 100644 --- a/test/link/wasm/function-table/build.zig +++ b/test/link/wasm/function-table/build.zig @@ -13,9 +13,12 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const import_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const import_table = b.addSharedLibrary(.{ .name = "import_table", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = import_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); @@ -23,9 +26,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize import_table.use_lld = false; import_table.import_table = true; + const export_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const export_table = b.addSharedLibrary(.{ .name = "export_table", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = export_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); @@ -33,9 +39,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize export_table.use_lld = false; export_table.export_table = true; + const regular_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const regular_table = b.addSharedLibrary(.{ .name = "regular_table", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = regular_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); diff --git a/test/link/wasm/infer-features/build.zig b/test/link/wasm/infer-features/build.zig index 00fb48651b03..6c9a1049bb6f 100644 --- a/test/link/wasm/infer-features/build.zig +++ b/test/link/wasm/infer-features/build.zig @@ -4,8 +4,14 @@ pub const requires_stage2 = true; pub fn build(b: *std.Build) void { // Wasm Object file which we will use to infer the features from + const c_obj_mod = b.createModule(.{ .c_source_files = .{ + .files = &.{"foo.c"}, + .flags = &.{}, + } }); + const c_obj = b.addObject(.{ .name = "c_obj", + .main_module = c_obj_mod, .optimize = .Debug, .target = .{ .cpu_arch = .wasm32, @@ -13,13 +19,15 @@ pub fn build(b: *std.Build) void { .os_tag = .freestanding, }, }); - c_obj.addCSourceFile("foo.c", &.{}); // Wasm library that doesn't have any features specified. This will // infer its featureset from other linked object files. + const mod = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "main.zig" }, + .main_module = mod, .optimize = .Debug, .target = .{ .cpu_arch = .wasm32, diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig index 439a66cfa51c..94dd6f4a8d90 100644 --- a/test/link/wasm/producers/build.zig +++ b/test/link/wasm/producers/build.zig @@ -14,9 +14,12 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); diff --git a/test/link/wasm/segments/build.zig b/test/link/wasm/segments/build.zig index 59fab9bb84ca..5c433d144fbc 100644 --- a/test/link/wasm/segments/build.zig +++ b/test/link/wasm/segments/build.zig @@ -13,9 +13,12 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig index bf643c1e3a39..e5b7514a8b31 100644 --- a/test/link/wasm/stack_pointer/build.zig +++ b/test/link/wasm/stack_pointer/build.zig @@ -13,9 +13,12 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig index 7a779f6c21ff..f05654d81de5 100644 --- a/test/link/wasm/type/build.zig +++ b/test/link/wasm/type/build.zig @@ -13,9 +13,12 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "lib.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .main_module = lib_mod, .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, .optimize = optimize, }); diff --git a/test/src/Cases.zig b/test/src/Cases.zig index b2c8ff555e99..2596fc8d6b85 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -484,28 +484,44 @@ pub fn lowerToBuildSteps( for (update.files.items) |file| { writefiles.add(file.path, file.src); } + + var deps = std.ArrayList(std.Build.ModuleDependency).init(b.allocator); + deps.ensureUnusedCapacity(case.deps.items.len) catch @panic("OOM"); + for (case.deps.items) |dep| { + deps.appendAssumeCapacity(.{ + .name = dep.name, + .module = b.createModule(.{ + .source_file = writefiles.getFileSource(dep.path).?, + }), + }); + } + const root_source_file = writefiles.getFileSource(update.files.items[0].path).?; + const main_mod = b.createModule(.{ + .source_file = root_source_file, + .dependencies = deps.items, + }); const artifact = if (case.is_test) b.addTest(.{ - .root_source_file = root_source_file, + .main_module = main_mod, .name = case.name, .target = case.target, .optimize = case.optimize_mode, }) else switch (case.output_mode) { .Obj => b.addObject(.{ - .root_source_file = root_source_file, + .main_module = main_mod, .name = case.name, .target = case.target, .optimize = case.optimize_mode, }), .Lib => b.addStaticLibrary(.{ - .root_source_file = root_source_file, + .main_module = main_mod, .name = case.name, .target = case.target, .optimize = case.optimize_mode, }), .Exe => b.addExecutable(.{ - .root_source_file = root_source_file, + .main_module = main_mod, .name = case.name, .target = case.target, .optimize = case.optimize_mode, @@ -525,12 +541,6 @@ pub fn lowerToBuildSteps( }, } - for (case.deps.items) |dep| { - artifact.addAnonymousModule(dep.name, .{ - .source_file = writefiles.getFileSource(dep.path).?, - }); - } - switch (update.case) { .Compile => { parent_step.dependOn(&artifact.step); diff --git a/test/src/CompareOutput.zig b/test/src/CompareOutput.zig index fb89082defc9..bdab5d00875e 100644 --- a/test/src/CompareOutput.zig +++ b/test/src/CompareOutput.zig @@ -96,6 +96,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { const exe = b.addExecutable(.{ .name = "test", + .main_module = b.createModule(.{}), .target = .{}, .optimize = .Debug, }); @@ -120,7 +121,9 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { const basename = case.sources.items[0].filename; const exe = b.addExecutable(.{ .name = "test", - .root_source_file = write_src.getFileSource(basename).?, + .main_module = b.createModule(.{ + .source_file = write_src.getFileSource(basename).?, + }), .optimize = optimize, .target = .{}, }); @@ -147,7 +150,9 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { const basename = case.sources.items[0].filename; const exe = b.addExecutable(.{ .name = "test", - .root_source_file = write_src.getFileSource(basename).?, + .main_module = b.createModule(.{ + .source_file = write_src.getFileSource(basename).?, + }), .target = .{}, .optimize = .Debug, }); diff --git a/test/src/StackTrace.zig b/test/src/StackTrace.zig index c32720a210b3..61cb9b1d955b 100644 --- a/test/src/StackTrace.zig +++ b/test/src/StackTrace.zig @@ -74,9 +74,12 @@ fn addExpect( const src_basename = "source.zig"; const write_src = b.addWriteFile(src_basename, source); + const mod = b.createModule(.{ + .source_file = write_src.getFileSource(src_basename).?, + }); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = write_src.getFileSource(src_basename).?, + .main_module = mod, .optimize = optimize_mode, .target = .{}, }); diff --git a/test/standalone.zig b/test/standalone.zig index 1f4d7cfded9f..4ebe9a26d6a8 100644 --- a/test/standalone.zig +++ b/test/standalone.zig @@ -218,10 +218,6 @@ pub const build_cases = [_]BuildCase{ // .build_root = "test/standalone/options", // .import = @import("standalone/options/build.zig"), //}, - .{ - .build_root = "test/standalone/strip_empty_loop", - .import = @import("standalone/strip_empty_loop/build.zig"), - }, }; const std = @import("std"); diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig index 6c5f2b4db6b9..216d1a003cbe 100644 --- a/test/standalone/c_compiler/build.zig +++ b/test/standalone/c_compiler/build.zig @@ -16,6 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const exe_c = b.addExecutable(.{ .name = "test_c", + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); @@ -24,6 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const exe_cpp = b.addExecutable(.{ .name = "test_cpp", + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); diff --git a/test/standalone/dep_diamond/build.zig b/test/standalone/dep_diamond/build.zig index 6c6d9b6d1a25..2d5a4820e005 100644 --- a/test/standalone/dep_diamond/build.zig +++ b/test/standalone/dep_diamond/build.zig @@ -9,21 +9,27 @@ pub fn build(b: *std.Build) void { const shared = b.createModule(.{ .source_file = .{ .path = "shared.zig" }, }); - - const exe = b.addExecutable(.{ - .name = "test", - .root_source_file = .{ .path = "test.zig" }, - .optimize = optimize, - }); - exe.addAnonymousModule("foo", .{ + const foo = b.createModule(.{ .source_file = .{ .path = "foo.zig" }, .dependencies = &.{.{ .name = "shared", .module = shared }}, }); - exe.addAnonymousModule("bar", .{ + const bar = b.createModule(.{ .source_file = .{ .path = "bar.zig" }, .dependencies = &.{.{ .name = "shared", .module = shared }}, }); + const exe = b.addExecutable(.{ + .name = "test", + .main_module = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + .dependencies = &.{ + .{ .name = "foo", .module = foo }, + .{ .name = "bar", .module = bar }, + }, + }), + .optimize = optimize, + }); + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/dep_mutually_recursive/build.zig b/test/standalone/dep_mutually_recursive/build.zig index e70e77540182..138e3cbc270c 100644 --- a/test/standalone/dep_mutually_recursive/build.zig +++ b/test/standalone/dep_mutually_recursive/build.zig @@ -17,10 +17,11 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .main_module = b.createModule(.{ .source_file = .{ .path = "test.zig" }, .dependencies = &.{ + .{ .name = "foo", .module = foo }, + } }), .optimize = optimize, }); - exe.addModule("foo", foo); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/dep_recursive/build.zig b/test/standalone/dep_recursive/build.zig index 2e2cf4ea4d4f..86e79615422e 100644 --- a/test/standalone/dep_recursive/build.zig +++ b/test/standalone/dep_recursive/build.zig @@ -13,10 +13,14 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + .dependencies = &.{ + .{ .name = "foo", .module = foo }, + }, + }), .optimize = optimize, }); - exe.addModule("foo", foo); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/dep_shared_builtin/build.zig b/test/standalone/dep_shared_builtin/build.zig index 175118d33192..6f4882ec3093 100644 --- a/test/standalone/dep_shared_builtin/build.zig +++ b/test/standalone/dep_shared_builtin/build.zig @@ -6,14 +6,19 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; + const foo = b.createModule(.{ + .source_file = .{ .path = "foo.zig" }, + }); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + .dependencies = &.{ + .{ .name = "foo", .module = foo }, + }, + }), .optimize = optimize, }); - exe.addAnonymousModule("foo", .{ - .source_file = .{ .path = "foo.zig" }, - }); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/dep_triangle/build.zig b/test/standalone/dep_triangle/build.zig index 63eed997ceb6..e213a29e108c 100644 --- a/test/standalone/dep_triangle/build.zig +++ b/test/standalone/dep_triangle/build.zig @@ -10,16 +10,22 @@ pub fn build(b: *std.Build) void { .source_file = .{ .path = "shared.zig" }, }); + const foo_mod = b.createModule(.{ + .source_file = .{ .path = "foo.zig" }, + .dependencies = &.{.{ .name = "shared", .module = shared }}, + }); + const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + .dependencies = &.{ + .{ .name = "foo", .module = foo_mod }, + .{ .name = "shared", .module = shared }, + }, + }), .optimize = optimize, }); - exe.addAnonymousModule("foo", .{ - .source_file = .{ .path = "foo.zig" }, - .dependencies = &.{.{ .name = "shared", .module = shared }}, - }); - exe.addModule("shared", shared); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/embed_generated_file/build.zig b/test/standalone/embed_generated_file/build.zig index af1ae0a00f70..168b2a8e0539 100644 --- a/test/standalone/embed_generated_file/build.zig +++ b/test/standalone/embed_generated_file/build.zig @@ -6,7 +6,9 @@ pub fn build(b: *std.Build) void { const bootloader = b.addExecutable(.{ .name = "bootloader", - .root_source_file = .{ .path = "bootloader.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "bootloader.zig" }, + }), .target = .{ .cpu_arch = .x86, .os_tag = .freestanding, @@ -14,13 +16,18 @@ pub fn build(b: *std.Build) void { .optimize = .ReleaseSmall, }); + const bootloader_mod = b.createModule(.{ + .source_file = bootloader.getOutputSource(), + }); const exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + .dependencies = &.{ + .{ .name = "bootloader.elf", .module = bootloader_mod }, + }, + }), .optimize = .Debug, }); - exe.addAnonymousModule("bootloader.elf", .{ - .source_file = bootloader.getOutputSource(), - }); test_step.dependOn(&exe.step); } diff --git a/test/standalone/empty_env/build.zig b/test/standalone/empty_env/build.zig index 27ec75be22df..d6cc2106590b 100644 --- a/test/standalone/empty_env/build.zig +++ b/test/standalone/empty_env/build.zig @@ -14,7 +14,9 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, }); diff --git a/test/standalone/extern/build.zig b/test/standalone/extern/build.zig index 153380e91ded..2915a92a428f 100644 --- a/test/standalone/extern/build.zig +++ b/test/standalone/extern/build.zig @@ -5,12 +5,16 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "exports", - .root_source_file = .{ .path = "exports.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "export.zig" }, + }), .target = .{}, .optimize = optimize, }); const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, }); main.addObject(obj); diff --git a/test/standalone/global_linkage/build.zig b/test/standalone/global_linkage/build.zig index d560027265cb..846519031ad7 100644 --- a/test/standalone/global_linkage/build.zig +++ b/test/standalone/global_linkage/build.zig @@ -9,20 +9,26 @@ pub fn build(b: *std.Build) void { const obj1 = b.addStaticLibrary(.{ .name = "obj1", - .root_source_file = .{ .path = "obj1.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "obj1.zig" }, + }), .optimize = optimize, .target = target, }); const obj2 = b.addStaticLibrary(.{ .name = "obj2", - .root_source_file = .{ .path = "obj2.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "obj2.zig" }, + }), .optimize = optimize, .target = target, }); const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, }); main.linkLibrary(obj1); diff --git a/test/standalone/install_raw_hex/build.zig b/test/standalone/install_raw_hex/build.zig index b34bb013788e..71afd00fe5b1 100644 --- a/test/standalone/install_raw_hex/build.zig +++ b/test/standalone/install_raw_hex/build.zig @@ -17,7 +17,9 @@ pub fn build(b: *std.Build) void { const elf = b.addExecutable(.{ .name = "zig-nrf52-blink.elf", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .target = target, .optimize = optimize, }); diff --git a/test/standalone/issue_11595/build.zig b/test/standalone/issue_11595/build.zig index b03d3c66cedc..cdd10aac606f 100644 --- a/test/standalone/issue_11595/build.zig +++ b/test/standalone/issue_11595/build.zig @@ -15,7 +15,9 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "zigtest", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .target = target, .optimize = optimize, }); diff --git a/test/standalone/issue_12588/.gitignore b/test/standalone/issue_12588/.gitignore new file mode 100644 index 000000000000..2c8ac475a3fb --- /dev/null +++ b/test/standalone/issue_12588/.gitignore @@ -0,0 +1,2 @@ +main.bc +main.ll \ No newline at end of file diff --git a/test/standalone/issue_12706/build.zig b/test/standalone/issue_12706/build.zig index 04eb826b44d8..49bc852a387f 100644 --- a/test/standalone/issue_12706/build.zig +++ b/test/standalone/issue_12706/build.zig @@ -11,7 +11,9 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = target, }); diff --git a/test/standalone/issue_13030/build.zig b/test/standalone/issue_13030/build.zig index e31863fee2fb..d9f37807ff0f 100644 --- a/test/standalone/issue_13030/build.zig +++ b/test/standalone/issue_13030/build.zig @@ -15,7 +15,9 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const obj = b.addObject(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = .{}, }); diff --git a/test/standalone/issue_13970/build.zig b/test/standalone/issue_13970/build.zig index cc70144596df..69822e32b80b 100644 --- a/test/standalone/issue_13970/build.zig +++ b/test/standalone/issue_13970/build.zig @@ -5,15 +5,21 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test1 = b.addTest(.{ - .root_source_file = .{ .path = "test_root/empty.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "test_root/empty.zig" }, + }), .test_runner = "src/main.zig", }); const test2 = b.addTest(.{ - .root_source_file = .{ .path = "src/empty.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "src/empty.zig" }, + }), .test_runner = "src/main.zig", }); const test3 = b.addTest(.{ - .root_source_file = .{ .path = "empty.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "empty.zig" }, + }), .test_runner = "src/main.zig", }); diff --git a/test/standalone/issue_339/build.zig b/test/standalone/issue_339/build.zig index f4215dbb8bc2..1a1547a11fb0 100644 --- a/test/standalone/issue_339/build.zig +++ b/test/standalone/issue_339/build.zig @@ -9,7 +9,9 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + }), .target = target, .optimize = optimize, }); diff --git a/test/standalone/issue_5825/build.zig b/test/standalone/issue_5825/build.zig index e8e8d4877230..9f2b9bad57dd 100644 --- a/test/standalone/issue_5825/build.zig +++ b/test/standalone/issue_5825/build.zig @@ -12,13 +12,16 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const obj = b.addObject(.{ .name = "issue_5825", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = target, }); const exe = b.addExecutable(.{ .name = "issue_5825", + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); diff --git a/test/standalone/issue_794/build.zig b/test/standalone/issue_794/build.zig index 8527f4af2c77..5bf841add166 100644 --- a/test/standalone/issue_794/build.zig +++ b/test/standalone/issue_794/build.zig @@ -5,7 +5,9 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test_artifact = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), }); test_artifact.addIncludePath("a_directory"); diff --git a/test/standalone/issue_8550/build.zig b/test/standalone/issue_8550/build.zig index 32bb3e10eb89..ee0f27b23116 100644 --- a/test/standalone/issue_8550/build.zig +++ b/test/standalone/issue_8550/build.zig @@ -13,9 +13,12 @@ pub fn build(b: *std.Build) !void { }, }; + const mod = b.createModule(.{ + .source_file = .{ .path = "./main.zig" }, + }); const kernel = b.addExecutable(.{ .name = "kernel", - .root_source_file = .{ .path = "./main.zig" }, + .main_module = mod, .optimize = optimize, .target = target, }); diff --git a/test/standalone/load_dynamic_library/build.zig b/test/standalone/load_dynamic_library/build.zig index 6dec8de7ae76..2195cef559d1 100644 --- a/test/standalone/load_dynamic_library/build.zig +++ b/test/standalone/load_dynamic_library/build.zig @@ -12,7 +12,9 @@ pub fn build(b: *std.Build) void { const lib = b.addSharedLibrary(.{ .name = "add", - .root_source_file = .{ .path = "add.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "add.zig" }, + }), .version = .{ .major = 1, .minor = 0 }, .optimize = optimize, .target = target, @@ -20,7 +22,9 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = target, }); diff --git a/test/standalone/main_pkg_path/build.zig b/test/standalone/main_pkg_path/build.zig index f3eacce767b8..068aa68c6d72 100644 --- a/test/standalone/main_pkg_path/build.zig +++ b/test/standalone/main_pkg_path/build.zig @@ -5,7 +5,9 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "a/test.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "a/test.zig" }, + }), }); test_exe.setMainPkgPath("."); diff --git a/test/standalone/mix_c_files/build.zig b/test/standalone/mix_c_files/build.zig index 39a0da27ad4c..48fb6ea12f4e 100644 --- a/test/standalone/mix_c_files/build.zig +++ b/test/standalone/mix_c_files/build.zig @@ -18,7 +18,9 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, }); exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"}); diff --git a/test/standalone/mix_o_files/build.zig b/test/standalone/mix_o_files/build.zig index 2d9323ff00de..56bfcfb76adc 100644 --- a/test/standalone/mix_o_files/build.zig +++ b/test/standalone/mix_o_files/build.zig @@ -7,15 +7,19 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const target: std.zig.CrossTarget = .{}; + const obj_mod = b.createModule(.{ + .source_file = .{ .path = "base64.zig" }, + }); const obj = b.addObject(.{ .name = "base64", - .root_source_file = .{ .path = "base64.zig" }, + .main_module = obj_mod, .optimize = optimize, .target = target, }); const exe = b.addExecutable(.{ .name = "test", + .main_module = b.createModule(.{}), .optimize = optimize, .target = target, }); diff --git a/test/standalone/pie/build.zig b/test/standalone/pie/build.zig index 1efcd5c26e87..f624d18b46ae 100644 --- a/test/standalone/pie/build.zig +++ b/test/standalone/pie/build.zig @@ -11,7 +11,9 @@ pub fn build(b: *std.Build) void { }; const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = target, }); diff --git a/test/standalone/pkg_import/build.zig b/test/standalone/pkg_import/build.zig index 30f4b2ede49b..548e6a8aacc7 100644 --- a/test/standalone/pkg_import/build.zig +++ b/test/standalone/pkg_import/build.zig @@ -6,12 +6,19 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; + const my_pkg = b.createModule(.{ + .source_file = .{ .path = "pkg.zig" }, + }); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + .dependencies = &.{ + .{ .name = "my_pkg", .module = my_pkg }, + }, + }), .optimize = optimize, }); - exe.addAnonymousModule("my_pkg", .{ .source_file = .{ .path = "pkg.zig" } }); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/shared_library/build.zig b/test/standalone/shared_library/build.zig index 377bf8186264..bd5aa501ee1d 100644 --- a/test/standalone/shared_library/build.zig +++ b/test/standalone/shared_library/build.zig @@ -6,9 +6,12 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const target: std.zig.CrossTarget = .{}; + const lib_mod = b.createModule(.{ + .source_file = .{ .path = "mathtest.zig" }, + }); const lib = b.addSharedLibrary(.{ .name = "mathtest", - .root_source_file = .{ .path = "mathtest.zig" }, + .main_module = lib_mod, .version = .{ .major = 1, .minor = 0 }, .target = target, .optimize = optimize, @@ -16,6 +19,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "test", + .main_module = b.createModule(.{}), .target = target, .optimize = optimize, }); diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig index 3feae705fcdb..f1ad7f30dcd4 100644 --- a/test/standalone/static_c_lib/build.zig +++ b/test/standalone/static_c_lib/build.zig @@ -8,6 +8,7 @@ pub fn build(b: *std.Build) void { const foo = b.addStaticLibrary(.{ .name = "foo", + .main_module = b.createModule(.{}), .optimize = optimize, .target = .{}, }); @@ -15,7 +16,9 @@ pub fn build(b: *std.Build) void { foo.addIncludePath("."); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "foo.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "foo.zig" }, + }), .optimize = optimize, }); test_exe.linkLibrary(foo); diff --git a/test/standalone/strip_empty_loop/build.zig b/test/standalone/strip_empty_loop/build.zig index 73c70d661627..52be6f6a5a51 100644 --- a/test/standalone/strip_empty_loop/build.zig +++ b/test/standalone/strip_empty_loop/build.zig @@ -9,7 +9,9 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, .target = target, }); diff --git a/test/standalone/test_runner_module_imports/build.zig b/test/standalone/test_runner_module_imports/build.zig index f27771889827..d3eaa90c16c9 100644 --- a/test/standalone/test_runner_module_imports/build.zig +++ b/test/standalone/test_runner_module_imports/build.zig @@ -1,18 +1,21 @@ const std = @import("std"); pub fn build(b: *std.Build) void { - const t = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, - .test_runner = "test_runner/main.zig", - }); - const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } }); const module2 = b.createModule(.{ .source_file = .{ .path = "module2/main.zig" }, .dependencies = &.{.{ .name = "module1", .module = module1 }}, }); - t.addModule("module2", module2); + const t = b.addTest(.{ + .main_module = b.createModule(.{ + .source_file = .{ .path = "src/main.zig" }, + .dependencies = &.{ + .{ .name = "module2", .module = module2 }, + }, + }), + .test_runner = "test_runner/main.zig", + }); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&b.addRunArtifact(t).step); diff --git a/test/standalone/test_runner_path/build.zig b/test/standalone/test_runner_path/build.zig index 352a18efe058..6a64f547beb3 100644 --- a/test/standalone/test_runner_path/build.zig +++ b/test/standalone/test_runner_path/build.zig @@ -6,8 +6,11 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test the program"); b.default_step = test_step; + const mod = b.createModule(.{ + .source_file = .{ .path = "test.zig" }, + }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "test.zig" }, + .main_module = mod, }); test_exe.test_runner = "test_runner.zig"; diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig index 6fa0a1f3a5b6..fbb0ceeb475f 100644 --- a/test/standalone/use_alias/build.zig +++ b/test/standalone/use_alias/build.zig @@ -7,7 +7,9 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .main_module = b.createModule(.{ + .source_file = .{ .path = "main.zig" }, + }), .optimize = optimize, }); main.addIncludePath("."); diff --git a/test/tests.zig b/test/tests.zig index 4b16ac50c78b..ac6056769ecb 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -540,9 +540,12 @@ pub fn addStackTraceTests( test_filter: ?[]const u8, optimize_modes: []const OptimizeMode, ) *Step { + const check_mod = b.createModule(.{ + .source_file = .{ .path = "test/src/check-stack-trace.zig" }, + }); const check_exe = b.addExecutable(.{ .name = "check-stack-trace", - .root_source_file = .{ .path = "test/src/check-stack-trace.zig" }, + .main_module = check_mod, .target = .{}, .optimize = .Debug, }); @@ -579,10 +582,14 @@ pub fn addStandaloneTests( if (os_tag != builtin.os.tag) continue; } + const mod = b.createModule(.{ + .source_file = .{ .path = case.src_path }, + }); + if (case.is_exe) { const exe = b.addExecutable(.{ .name = std.fs.path.stem(case.src_path), - .root_source_file = .{ .path = case.src_path }, + .main_module = mod, .optimize = optimize, .target = case.target, }); @@ -594,7 +601,7 @@ pub fn addStandaloneTests( if (case.is_test) { const exe = b.addTest(.{ .name = std.fs.path.stem(case.src_path), - .root_source_file = .{ .path = case.src_path }, + .main_module = mod, .optimize = optimize, .target = case.target, }); @@ -983,8 +990,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { else options.max_rss; + const these_tests_mod = b.createModule(.{ + .source_file = .{ .path = options.root_src }, + }); const these_tests = b.addTest(.{ - .root_source_file = .{ .path = options.root_src }, + .main_module = these_tests_mod, .optimize = test_target.optimize_mode, .target = test_target.target, .max_rss = max_rss, @@ -1020,13 +1030,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { var altered_target = test_target.target; altered_target.ofmt = null; - const compile_c = b.addExecutable(.{ - .name = qualified_name, - .link_libc = test_target.link_libc, - .target = altered_target, - }); - compile_c.overrideZigLibDir("lib"); - compile_c.addCSourceFileSource(.{ + const compile_c_mod = b.createModule(.{}); + compile_c_mod.addCSourceFileSource(.{ .source = these_tests.getOutputSource(), .args = &.{ // TODO output -std=c89 compatible C code @@ -1043,6 +1048,14 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { "-Wno-absolute-value", }, }); + + const compile_c = b.addExecutable(.{ + .name = qualified_name, + .main_module = compile_c_mod, + .link_libc = test_target.link_libc, + .target = altered_target, + }); + compile_c.overrideZigLibDir("lib"); compile_c.addIncludePath("lib"); // for zig.h if (test_target.link_libc == false and test_target.target.getOsTag() == .windows) { compile_c.subsystem = .Console; @@ -1085,8 +1098,11 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM"); + const test_mod = b.createModule(.{ + .source_file = .{ .path = "test/c_abi/main.zig" }, + }); const test_step = b.addTest(.{ - .root_source_file = .{ .path = "test/c_abi/main.zig" }, + .main_module = test_mod, .optimize = optimize_mode, .target = c_abi_target, .name = b.fmt("test-c-abi-{s}-{s}", .{