Skip to content

Commit 867c6e7

Browse files
a-khabarovchrisirhc
authored andcommitted
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 ziglang#19818
1 parent bd97b66 commit 867c6e7

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
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,
@@ -238,6 +239,7 @@ pub const CreateOptions = struct {
238239
link_libcpp: ?bool = null,
239240
single_threaded: ?bool = null,
240241
strip: ?bool = null,
242+
soname: ?std.zig.SoName = null,
241243
unwind_tables: ?std.builtin.UnwindTables = null,
242244
dwarf_format: ?std.dwarf.Format = null,
243245
code_model: std.builtin.CodeModel = .default,
@@ -288,6 +290,7 @@ pub fn init(
288290
.frameworks = .{},
289291
.link_objects = .{},
290292
.strip = options.strip,
293+
.soname = options.soname,
291294
.unwind_tables = options.unwind_tables,
292295
.single_threaded = options.single_threaded,
293296
.stack_protector = options.stack_protector,
@@ -561,6 +564,14 @@ pub fn appendZigProcessFlags(
561564
.full => try zig_args.append("-fsanitize-c=full"),
562565
};
563566

567+
if (m.soname) |soname| {
568+
try zig_args.append(switch (soname) {
569+
.no => "-fno-soname",
570+
.yes_default_value => "-fsoname",
571+
.yes => |value| b.fmt("-fsoname={s}", .{value}),
572+
});
573+
}
574+
564575
if (m.dwarf_format) |dwarf_format| {
565576
try zig_args.append(switch (dwarf_format) {
566577
.@"32" => "-gdwarf32",

lib/std/zig.zig

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

320320
pub const LtoMode = enum { none, full, thin };
321321

322+
pub const SoName = union(enum) {
323+
no,
324+
yes_default_value,
325+
yes: []const u8,
326+
};
327+
322328
/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
323329
/// via the `-mcpu` flag passed to the Zig compiler.
324330
/// Appends the result to `buffer`.

src/main.zig

Lines changed: 2 additions & 7 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;
@@ -685,12 +686,6 @@ const usage_build_generic =
685686
\\
686687
;
687688

688-
const SOName = union(enum) {
689-
no,
690-
yes_default_value,
691-
yes: []const u8,
692-
};
693-
694689
const EmitBin = union(enum) {
695690
no,
696691
yes_default_path,
@@ -837,7 +832,7 @@ fn buildOutputType(
837832
var target_arch_os_abi: ?[]const u8 = null;
838833
var target_mcpu: ?[]const u8 = null;
839834
var emit_h: Emit = .no;
840-
var soname: SOName = undefined;
835+
var soname: SoName = undefined;
841836
var want_compiler_rt: ?bool = null;
842837
var want_ubsan_rt: ?bool = null;
843838
var linker_script: ?[]const u8 = null;

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)