Skip to content

Commit ec49263

Browse files
committed
Add LinkerDirectory and LinkerReference item types.
Closes #51.
1 parent 9d79426 commit ec49263

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

doc/configuration/items.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ are used by the Zig SDK:
1313
* `LibraryIncludeDirectory`: Header include directories passed to the compiler
1414
with the `-isystem` flag. Note that this applies to Zig as well, not just
1515
C/C++.
16-
* `LibraryReference`: Native libraries that should be linked to. These can be
17-
either static or dynamic. For multi-platform projects, additions to this item
18-
should be conditioned on the value of `RuntimeIdentifier` (or similar).
16+
* `LinkerDirectory`: Library search directories passed to the linker with the
17+
`-L` flag.
18+
* `LinkerReference`: Names of native libraries that should be linked using the
19+
`-l` flag. These can be either static or dynamic.
20+
* `LibraryReference`: Direct paths to native library files that should be
21+
linked, ignoring library search directories. These can be either static or
22+
dynamic.
1923
* `CHeader`: Prepopulated by the Zig SDK with all files in the project directory
2024
ending in `.h`.
2125
* `CSource`: Prepopulated by the Zig SDK with all files in the project directory

src/sdk/ZigCompile.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public string Configuration
7272
[Required]
7373
public ITaskItem[] LibraryReferences { get; set; } = null!;
7474

75+
[Required]
76+
public ITaskItem[] LinkerDirectories { get; set; } = null!;
77+
78+
[Required]
79+
public ITaskItem[] LinkerReferences { get; set; } = null!;
80+
7581
[Required]
7682
public bool LinkTimeOptimization { get; set; }
7783

@@ -545,15 +551,15 @@ void TryAppendWarningSwitch(string name)
545551
builder.AppendSwitchIfNotNull("-I ", GetWorkingDirectory() ?? ".");
546552
builder.AppendSwitchIfNotNull("-I ", PublicIncludeDirectory);
547553

548-
foreach (var include in LibraryIncludeDirectories)
549-
builder.AppendSwitchIfNotNull("-isystem ", include);
554+
foreach (var directory in LibraryIncludeDirectories)
555+
builder.AppendSwitchIfNotNull("-isystem ", directory);
550556

551-
foreach (var include in IncludeDirectories)
552-
builder.AppendSwitchIfNotNull("-I ", include);
557+
foreach (var directory in IncludeDirectories)
558+
builder.AppendSwitchIfNotNull("-I ", directory);
553559

554560
if (!isZig)
555-
foreach (var prelude in PreludeHeaders)
556-
builder.AppendSwitchIfNotNull("-include ", prelude);
561+
foreach (var header in PreludeHeaders)
562+
builder.AppendSwitchIfNotNull("-include ", header);
557563

558564
if (EagerBinding)
559565
builder.AppendSwitch(isZig ? "-z now" : "-Wl,-z,now");
@@ -568,6 +574,13 @@ void TryAppendWarningSwitch(string name)
568574

569575
builder.AppendFileNamesIfNotNull(Sources, " ");
570576
builder.AppendFileNamesIfNotNull(LibraryReferences, " ");
577+
578+
foreach (var directory in LinkerDirectories)
579+
builder.AppendSwitchIfNotNull("-L ", directory);
580+
581+
foreach (var library in LinkerReferences)
582+
builder.AppendSwitchIfNotNull("-l ", library);
583+
571584
builder.AppendSwitchIfNotNull(isZig ? "-femit-bin=" : "-o ", OutputBinary);
572585

573586
if (!isZig)

src/sdk/build/Vezel.Zig.Sdk.Build.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
LanguageStandard="$(LanguageStandard)"
6060
LibraryIncludeDirectories="@(LibraryIncludeDirectory)"
6161
LibraryReferences="@(LibraryReference)"
62+
LinkerDirectories="@(LinkerDirectory)"
63+
LinkerReferences="@(LinkerReference)"
6264
LinkTimeOptimization="$(LinkTimeOptimization)"
6365
MicrosoftExtensions="$(MicrosoftExtensions)"
6466
NullabilityAnalysis="$(NullabilityAnalysis)"

src/sdk/build/Vezel.Zig.Sdk.Test.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
LanguageStandard="$(LanguageStandard)"
3636
LibraryIncludeDirectories="@(LibraryIncludeDirectory)"
3737
LibraryReferences="@(LibraryReference)"
38+
LinkerDirectories="@(LinkerDirectory)"
39+
LinkerReferences="@(LinkerReference)"
3840
LinkTimeOptimization="$(LinkTimeOptimization)"
3941
MicrosoftExtensions="$(MicrosoftExtensions)"
4042
NullabilityAnalysis="$(NullabilityAnalysis)"

0 commit comments

Comments
 (0)