diff --git a/lib/init/build.zig b/lib/init/build.zig index c75a4e6be3bbca6d4d79885d602280b72800d485..9be615ac31d0d2d6691efddfa48b953b1c7a43fd 100644 --- a/lib/init/build.zig +++ b/lib/init/build.zig @@ -47,7 +47,8 @@ pub fn build(b: *std.Build) void { // Now, we will create a static library based on the module we created above. // This creates a `std.Build.Step.Compile`, which is the build step responsible // for actually invoking the compiler. - const lib = b.addStaticLibrary(.{ + const lib = b.addLibrary(.{ + .linkage = .static, .name = "$", .root_module = lib_mod, }); diff --git a/lib/std/Build.zig b/lib/std/Build.zig index a9a5d18f6e36bacfcdd42a45835673f32066a734..ac97a23e9f16e9e0bb0b23c56e52264b66b778de 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -873,6 +873,7 @@ pub const SharedLibraryOptions = struct { error_tracing: ?bool = null, }; +/// Deprecated: use `b.addLibrary(.{ ..., .linkage = .dynamic })` instead. pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile { if (options.root_module != null and options.target != null) { @panic("`root_module` and `target` cannot both be populated"); @@ -943,6 +944,7 @@ pub const StaticLibraryOptions = struct { error_tracing: ?bool = null, }; +/// Deprecated: use `b.addLibrary(.{ ..., .linkage = .static })` instead. pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile { if (options.root_module != null and options.target != null) { @panic("`root_module` and `target` cannot both be populated"); @@ -973,6 +975,38 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile }); } +pub const LibraryOptions = struct { + linkage: std.builtin.LinkMode = .static, + name: []const u8, + root_module: *Module, + version: ?std.SemanticVersion = null, + max_rss: usize = 0, + use_llvm: ?bool = null, + use_lld: ?bool = null, + zig_lib_dir: ?LazyPath = null, + /// Embed a `.manifest` file in the compilation if the object format supports it. + /// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference + /// Manifest files must have the extension `.manifest`. + /// Can be set regardless of target. The `.manifest` file will be ignored + /// if the target object format does not support embedded manifests. + win32_manifest: ?LazyPath = null, +}; + +pub fn addLibrary(b: *Build, options: LibraryOptions) *Step.Compile { + return .create(b, .{ + .name = options.name, + .root_module = options.root_module, + .kind = .lib, + .linkage = options.linkage, + .version = options.version, + .max_rss = options.max_rss, + .use_llvm = options.use_llvm, + .use_lld = options.use_lld, + .zig_lib_dir = options.zig_lib_dir, + .win32_manifest = options.win32_manifest, + }); +} + pub const TestOptions = struct { name: []const u8 = "test", max_rss: usize = 0, diff --git a/test/behavior/x86_64/build.zig b/test/behavior/x86_64/build.zig index 336f55eaaae32edb68382a436d2452d16338c05e..227c3df9f88559a8930b0a8655bb64ba20e85503 100644 --- a/test/behavior/x86_64/build.zig +++ b/test/behavior/x86_64/build.zig @@ -6,7 +6,8 @@ pub fn build(b: *std.Build) void { "Skip tests that do not match any filter", ) orelse &[0][]const u8{}; - const compiler_rt_lib = b.addStaticLibrary(.{ + const compiler_rt_lib = b.addLibrary(.{ + .linkage = .static, .name = "compiler_rt", .use_llvm = false, .use_lld = false, diff --git a/test/link/common_symbols/build.zig b/test/link/common_symbols/build.zig index d4826956a58d63ce4a12ca1304d3880634406081..39684bbeade186e8bf5c9bdcc51125e166e55dba 100644 --- a/test/link/common_symbols/build.zig +++ b/test/link/common_symbols/build.zig @@ -11,7 +11,8 @@ 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 = b.addStaticLibrary(.{ + const lib_a = b.addLibrary(.{ + .linkage = .static, .name = "a", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/link/common_symbols_alignment/build.zig b/test/link/common_symbols_alignment/build.zig index 6f0a0efd8024b15b45ea914420d309ffadf99cc5..682b8a9b8f51bb0303207eabb3fbe980c14b2d25 100644 --- a/test/link/common_symbols_alignment/build.zig +++ b/test/link/common_symbols_alignment/build.zig @@ -11,7 +11,8 @@ 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 = b.addStaticLibrary(.{ + const lib_a = b.addLibrary(.{ + .linkage = .static, .name = "a", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/link/interdependent_static_c_libs/build.zig b/test/link/interdependent_static_c_libs/build.zig index b18371fdcc05cc56399293ae2761889fdebe5261..ec84ebb339868f686e5ba01634c99cab91af4325 100644 --- a/test/link/interdependent_static_c_libs/build.zig +++ b/test/link/interdependent_static_c_libs/build.zig @@ -11,7 +11,8 @@ 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 = b.addStaticLibrary(.{ + const lib_a = b.addLibrary(.{ + .linkage = .static, .name = "a", .root_module = b.createModule(.{ .root_source_file = null, @@ -22,7 +23,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); lib_a.root_module.addIncludePath(b.path(".")); - const lib_b = b.addStaticLibrary(.{ + const lib_b = b.addLibrary(.{ + .linkage = .static, .name = "b", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/link/link.zig b/test/link/link.zig index 960d8fd7430f37f7a1285ccd8957cb3fc00a7375..59198e6c8eb112c0899b94567ed8800ee9ef2790 100644 --- a/test/link/link.zig +++ b/test/link/link.zig @@ -65,7 +65,8 @@ pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile { } pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { - return b.addStaticLibrary(.{ + return b.addLibrary(.{ + .linkage = .static, .name = overlay.name, .root_module = createModule(b, base, overlay), .use_llvm = base.use_llvm, @@ -74,7 +75,8 @@ pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Comp } pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { - return b.addSharedLibrary(.{ + return b.addLibrary(.{ + .linkage = .dynamic, .name = overlay.name, .root_module = createModule(b, base, overlay), .use_llvm = base.use_llvm, diff --git a/test/link/static_libs_from_object_files/build.zig b/test/link/static_libs_from_object_files/build.zig index 461f26a37471473d6b61cf197e8c058138756398..809891112df8382261bb96351ba01a51bcda8b69 100644 --- a/test/link/static_libs_from_object_files/build.zig +++ b/test/link/static_libs_from_object_files/build.zig @@ -85,11 +85,13 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built mod.addCSourceFile(.{ .file = file, .flags = &flags }); } - const lib_a = b.addStaticLibrary(.{ + const lib_a = b.addLibrary(.{ + .linkage = .static, .name = "test2_a", .root_module = mod_a, }); - const lib_b = b.addStaticLibrary(.{ + const lib_b = b.addLibrary(.{ + .linkage = .static, .name = "test2_b", .root_module = mod_b, }); @@ -130,11 +132,13 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built lib_mod.addObject(obj); } - const lib_a = b.addStaticLibrary(.{ + const lib_a = b.addLibrary(.{ + .linkage = .static, .name = "test3_a", .root_module = mod_a, }); - const lib_b = b.addStaticLibrary(.{ + const lib_b = b.addLibrary(.{ + .linkage = .static, .name = "test3_b", .root_module = mod_b, }); diff --git a/test/src/Cases.zig b/test/src/Cases.zig index 360a0fda9241ec7e3d3b4622a5facdd0b3f04161..c49576b2f7ebfcb66117b44ea1a59ee85ce92762 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -684,7 +684,8 @@ pub fn lowerToBuildSteps( .name = case.name, .root_module = mod, }), - .Lib => b.addStaticLibrary(.{ + .Lib => b.addLibrary(.{ + .linkage = .static, .name = case.name, .root_module = mod, }), diff --git a/test/standalone/coff_dwarf/build.zig b/test/standalone/coff_dwarf/build.zig index b95ebed80dff67d64ec083106d2537a24cf1fb97..53425db8d34fb4fe1ce2fabe6212ae725b208285 100644 --- a/test/standalone/coff_dwarf/build.zig +++ b/test/standalone/coff_dwarf/build.zig @@ -21,7 +21,8 @@ pub fn build(b: *std.Build) void { }), }); - const lib = b.addSharedLibrary(.{ + const lib = b.addLibrary(.{ + .linkage = .dynamic, .name = "shared_lib", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/standalone/dep_duplicate_module/build.zig b/test/standalone/dep_duplicate_module/build.zig index 5974ba9968ffb0406df03030c0cd9086efa67519..3524b3392941d5d9569c82d871e8298963a678c9 100644 --- a/test/standalone/dep_duplicate_module/build.zig +++ b/test/standalone/dep_duplicate_module/build.zig @@ -23,7 +23,8 @@ pub fn build(b: *std.Build) void { lib_mod.addImport("mod", shared_mod); exe_mod.addImport("mod", shared_mod); - const lib = b.addStaticLibrary(.{ + const lib = b.addLibrary(.{ + .linkage = .static, .name = "lib", .root_module = lib_mod, }); diff --git a/test/standalone/extern/build.zig b/test/standalone/extern/build.zig index a3907e20dba8fa38bdba59bc415e1c6c3d2c0387..3c22f77f2a916ca380dcc86679c20e30d022ce2e 100644 --- a/test/standalone/extern/build.zig +++ b/test/standalone/extern/build.zig @@ -14,7 +14,8 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }), }); - const shared = b.addSharedLibrary(.{ + const shared = b.addLibrary(.{ + .linkage = .dynamic, .name = "shared", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/standalone/global_linkage/build.zig b/test/standalone/global_linkage/build.zig index 795bf008b31398364cad3b4ebe43f335e3d6c81d..c706b329004c21a464df8d2839e032cd5de4982e 100644 --- a/test/standalone/global_linkage/build.zig +++ b/test/standalone/global_linkage/build.zig @@ -7,7 +7,8 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const target = b.graph.host; - const obj1 = b.addStaticLibrary(.{ + const obj1 = b.addLibrary(.{ + .linkage = .static, .name = "obj1", .root_module = b.createModule(.{ .root_source_file = b.path("obj1.zig"), @@ -16,7 +17,8 @@ pub fn build(b: *std.Build) void { }), }); - const obj2 = b.addStaticLibrary(.{ + const obj2 = b.addLibrary(.{ + .linkage = .static, .name = "obj2", .root_module = b.createModule(.{ .root_source_file = b.path("obj2.zig"), diff --git a/test/standalone/install_headers/build.zig b/test/standalone/install_headers/build.zig index 9f725c0c8149b03e69e6fa77d1c76ce46dfc6d27..60ecaf1d9e824c8c5138d73eec2cf5ab48e2a4df 100644 --- a/test/standalone/install_headers/build.zig +++ b/test/standalone/install_headers/build.zig @@ -6,7 +6,8 @@ pub fn build(b: *std.Build) void { const empty_c = b.addWriteFiles().add("empty.c", ""); - const libfoo = b.addStaticLibrary(.{ + const libfoo = b.addLibrary(.{ + .linkage = .static, .name = "foo", .root_module = b.createModule(.{ .root_source_file = null, @@ -61,7 +62,8 @@ pub fn build(b: *std.Build) void { .FOO_CONFIG_2 = "2", })); - const libbar = b.addStaticLibrary(.{ + const libbar = b.addLibrary(.{ + .linkage = .static, .name = "bar", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/standalone/load_dynamic_library/build.zig b/test/standalone/load_dynamic_library/build.zig index ec05c45c21e2ab585916a8f9cd9b20777aaf9b0e..305ffde56506cf97cd0465d1af85f8680b7445b7 100644 --- a/test/standalone/load_dynamic_library/build.zig +++ b/test/standalone/load_dynamic_library/build.zig @@ -10,7 +10,8 @@ pub fn build(b: *std.Build) void { if (builtin.os.tag == .wasi) return; - const lib = b.addSharedLibrary(.{ + const lib = b.addLibrary(.{ + .linkage = .dynamic, .name = "add", .version = .{ .major = 1, .minor = 0, .patch = 0 }, .root_module = b.createModule(.{ diff --git a/test/standalone/shared_library/build.zig b/test/standalone/shared_library/build.zig index ab90c129b9965cd79d8a124715f6d149ee59eeda..5b105e18cc669fa6a863c8ae0aa17c47f927d7d3 100644 --- a/test/standalone/shared_library/build.zig +++ b/test/standalone/shared_library/build.zig @@ -6,7 +6,8 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const target = b.graph.host; - const lib = b.addSharedLibrary(.{ + const lib = b.addLibrary(.{ + .linkage = .dynamic, .name = "mathtest", .version = .{ .major = 1, .minor = 0, .patch = 0 }, .root_module = b.createModule(.{ diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index 9d660b5c57bac985af4c37483645b103aac49298..4a1ef4b5b2e964e4b7dc03399aed0b50cc02b3cb 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -68,7 +68,8 @@ pub fn build(b: *std.Build) void { // - x86_64: STACK_IMMD, STACK_IND // - aarch64: FRAMELESS, DWARF { - const c_shared_lib = b.addSharedLibrary(.{ + const c_shared_lib = b.addLibrary(.{ + .linkage = .dynamic, .name = "c_shared_lib", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig index 98b417aaf7cb69cc982fde714499ea04567318ea..4bed5cdefa5f496c702b60a051646d9e8979b177 100644 --- a/test/standalone/static_c_lib/build.zig +++ b/test/standalone/static_c_lib/build.zig @@ -6,7 +6,8 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const foo = b.addStaticLibrary(.{ + const foo = b.addLibrary(.{ + .linkage = .static, .name = "foo", .root_module = b.createModule(.{ .root_source_file = null, diff --git a/test/standalone/windows_argv/build.zig b/test/standalone/windows_argv/build.zig index ea4b26cc2281bd95bc33ff4dce38f65d943f0777..df988d2371e0a3e4dd0bca7f5b93090c64f3840e 100644 --- a/test/standalone/windows_argv/build.zig +++ b/test/standalone/windows_argv/build.zig @@ -9,7 +9,8 @@ pub fn build(b: *std.Build) !void { const optimize: std.builtin.OptimizeMode = .Debug; - const lib_gnu = b.addStaticLibrary(.{ + const lib_gnu = b.addLibrary(.{ + .linkage = .static, .name = "toargv-gnu", .root_module = b.createModule(.{ .root_source_file = b.path("lib.zig"), @@ -74,7 +75,8 @@ pub fn build(b: *std.Build) !void { break :has_msvc true; }; if (has_msvc) { - const lib_msvc = b.addStaticLibrary(.{ + const lib_msvc = b.addLibrary(.{ + .linkage = .static, .name = "toargv-msvc", .root_module = b.createModule(.{ .root_source_file = b.path("lib.zig"),