Skip to content

Commit 3c34b1b

Browse files
committed
Link Zig projects dynamically in all cases.
1 parent c29d17c commit 3c34b1b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/sdk/Zig.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,25 @@ protected override string GenerateCommandLineCommands()
194194
}
195195
else
196196
{
197-
builder.AppendSwitch(isZig ? "-dynamic" : "-shared");
198197
builder.AppendSwitch("-fPIC");
199198

200199
if (!isZig)
200+
{
201+
builder.AppendSwitch("-shared");
201202
builder.AppendSwitchIfNotNull("-Wl,-soname,", TargetFileName);
203+
}
202204
}
203205

204206
if (isZig)
205207
{
206-
builder.AppendSwitchIfNotNull("-rpath ", "$ORIGIN");
207-
208-
// When building Zig code, the compiler links to libc statically
209-
// by default. We do not want that behavior when building code
210-
// that might be loaded in a .NET process.
208+
// The compiler uses static linking by default when building Zig
209+
// code. We want dynamic linking in all cases.
210+
builder.AppendSwitch("-dynamic");
211+
212+
// When building Zig code, by default, the compiler links
213+
// statically to a platform-appropriate libc. We absolutely do
214+
// not want that behavior when building code that might be
215+
// loaded in a .NET process.
211216
builder.AppendSwitch("-lc");
212217

213218
if (_configuration == ZigConfiguration.Release)
@@ -218,8 +223,6 @@ protected override string GenerateCommandLineCommands()
218223
}
219224
else
220225
{
221-
builder.AppendSwitchIfNotNull($"-Wl,-rpath,", "$ORIGIN");
222-
223226
// These exact flags are treated specially by zig cc/c++. They
224227
// activate Debug, ReleaseFast, ReleaseSafe, and ReleaseSmall
225228
// respectively. This in turns activates a bunch of other
@@ -526,6 +529,8 @@ void TryAppendWarningSwitch(string name)
526529
foreach (var prelude in PreludeHeaders)
527530
builder.AppendSwitchIfNotNull("-include ", prelude);
528531

532+
builder.AppendSwitchIfNotNull(isZig ? "-rpath " : "-Wl,-rpath,", "$ORIGIN");
533+
529534
// TODO: https://github.com/alexrp/zig-msbuild-sdk/issues/8
530535

531536
builder.AppendFileNamesIfNotNull(Sources, " ");

0 commit comments

Comments
 (0)