Skip to content

Commit 5b78bfc

Browse files
committed
lib: add support for omitting soname
This commit adds the `soname` option for `Build.Module` and `OverlayOptions`. This controls whether `-fsoname` or `-fno-soname` is passed to the linker. The `SOName` type is moved to `std.zig` to make it accessible in other modules. This is needed to implement the new test in #19818
1 parent 3746b3d commit 5b78bfc

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

lib/std/Build/Module.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ frameworks: std.StringArrayHashMapUnmanaged(LinkFrameworkOptions),
1818
link_objects: std.ArrayListUnmanaged(LinkObject),
1919

2020
strip: ?bool,
21+
soname: ?std.zig.SOName,
2122
unwind_tables: ?std.builtin.UnwindTables,
2223
single_threaded: ?bool,
2324
stack_protector: ?bool,
@@ -251,6 +252,7 @@ pub const CreateOptions = struct {
251252
link_libcpp: ?bool = null,
252253
single_threaded: ?bool = null,
253254
strip: ?bool = null,
255+
soname: ?std.zig.SOName = null,
254256
unwind_tables: ?std.builtin.UnwindTables = null,
255257
dwarf_format: ?std.dwarf.Format = null,
256258
code_model: std.builtin.CodeModel = .default,
@@ -300,6 +302,7 @@ pub fn init(
300302
.frameworks = .{},
301303
.link_objects = .{},
302304
.strip = options.strip,
305+
.soname = options.soname,
303306
.unwind_tables = options.unwind_tables,
304307
.single_threaded = options.single_threaded,
305308
.stack_protector = options.stack_protector,
@@ -566,6 +569,14 @@ pub fn appendZigProcessFlags(
566569
try addFlag(zig_args, m.pic, "-fPIC", "-fno-PIC");
567570
try addFlag(zig_args, m.red_zone, "-mred-zone", "-mno-red-zone");
568571

572+
if (m.soname) |soname| {
573+
try zig_args.append(switch (soname) {
574+
.no => "-fno-soname",
575+
.yes_default_value => "-fsoname",
576+
.yes => |value| b.fmt("-fsoname={s}", .{value}),
577+
});
578+
}
579+
569580
if (m.dwarf_format) |dwarf_format| {
570581
try zig_args.append(switch (dwarf_format) {
571582
.@"32" => "-gdwarf32",

lib/std/zig.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ pub const BuildId = union(enum) {
315315

316316
pub const LtoMode = enum { none, full, thin };
317317

318+
pub const SOName = union(enum) {
319+
no,
320+
yes_default_value,
321+
yes: []const u8,
322+
};
323+
318324
/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
319325
/// via the `-mcpu` flag passed to the Zig compiler.
320326
/// Appends the result to `buffer`.

src/main.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const native_os = builtin.os.tag;
1616
const Cache = std.Build.Cache;
1717
const Path = std.Build.Cache.Path;
1818
const Directory = std.Build.Cache.Directory;
19+
const SOName = std.zig.SOName;
1920
const EnvVar = std.zig.EnvVar;
2021
const LibCInstallation = std.zig.LibCInstallation;
2122
const AstGen = std.zig.AstGen;
@@ -688,12 +689,6 @@ const usage_build_generic =
688689
\\
689690
;
690691

691-
const SOName = union(enum) {
692-
no,
693-
yes_default_value,
694-
yes: []const u8,
695-
};
696-
697692
const EmitBin = union(enum) {
698693
no,
699694
yes_default_path,

test/link/link.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const OverlayOptions = struct {
4444
zig_source_bytes: ?[]const u8 = null,
4545
pic: ?bool = null,
4646
strip: ?bool = null,
47+
soname: ?std.zig.SOName = null,
4748
};
4849

4950
pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile {
@@ -97,6 +98,7 @@ fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module
9798
},
9899
.pic = overlay.pic,
99100
.strip = if (base.strip) |s| s else overlay.strip,
101+
.soname = overlay.soname,
100102
});
101103

102104
if (overlay.objcpp_source_bytes) |bytes| {

0 commit comments

Comments
 (0)