Skip to content

Commit b98a110

Browse files
committed
Support --subsystem linker flag by way of OutputType (added WinExe).
Closes #43.
1 parent 9a777f5 commit b98a110

File tree

8 files changed

+28
-22
lines changed

8 files changed

+28
-22
lines changed

doc/configuration/properties.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ historical reasons.
1515
* `AssemblyName`: Name of the project. By default, this is set to the file name
1616
of the project file. Used to compute the final binary name (e.g. `foo` becomes
1717
`libfoo.so`).
18-
* `OutputType` (`Exe`, `Library`): Output binary type. Defaults to `Library`.
18+
* `OutputType` (`Exe`, `WinExe`, `Library`): Output binary type. When targeting
19+
Windows and building executables, `Exe` and `WinExe` will target the CUI and
20+
GUI subsystems, respectively. Defaults to `Library`.
1921
* `IsTestable` (`true`, `false`): Enable/disable `dotnet test` for Zig projects.
2022
Defaults to `true`.
2123
* `IsPackable` (`true`, `false`): Enable/disable `dotnet pack`. Defaults to

src/samples/cexe/cexe.cproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Vezel.Zig.Sdk">
22
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
3+
<OutputType>WinExe</OutputType>
44
</PropertyGroup>
55

66
<ItemGroup>

src/sdk/ZigCompile.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ protected override string GenerateCommandLineCommands()
211211
{
212212
(ZigCompilerMode.C, _) => "cc",
213213
(ZigCompilerMode.Cxx, _) => "c++",
214-
(ZigCompilerMode.Zig, ZigOutputType.Exe) => "build-exe",
215214
(ZigCompilerMode.Zig, ZigOutputType.Library) => "build-lib",
215+
(ZigCompilerMode.Zig, _) => "build-exe",
216216
(ZigCompilerMode.Test, _) => "test",
217217
_ => throw new Exception(),
218218
});
@@ -224,14 +224,7 @@ protected override string GenerateCommandLineCommands()
224224

225225
builder.AppendSwitch($"-target {TargetTriple.ToLowerInvariant()}");
226226

227-
if (_outputType == ZigOutputType.Exe)
228-
{
229-
builder.AppendSwitch("-fPIE");
230-
231-
if (_symbolExports == ZigSymbolExports.All)
232-
builder.AppendSwitch("-rdynamic");
233-
}
234-
else
227+
if (_outputType == ZigOutputType.Library)
235228
{
236229
builder.AppendSwitch("-fPIC");
237230

@@ -247,6 +240,13 @@ protected override string GenerateCommandLineCommands()
247240
builder.AppendSwitch(isZig ? $"-z {un}defs" : $"-Wl,-z,{un}defs");
248241
builder.AppendSwitch(isZig ? $"-f{no}allow-shlib-undefined" : $"-Wl,--{no}allow-shlib-undefined");
249242
}
243+
else
244+
{
245+
builder.AppendSwitch("-fPIE");
246+
247+
if (_symbolExports == ZigSymbolExports.All)
248+
builder.AppendSwitch("-rdynamic");
249+
}
250250

251251
if (isZig)
252252
{
@@ -604,6 +604,9 @@ void TryAppendWarningSwitch(string name)
604604
builder.AppendSwitch(isZig ? "-z origin" : "-Wl,-z,origin");
605605
builder.AppendSwitchIfNotNull(isZig ? "-rpath " : "-Wl,-rpath,", "$ORIGIN");
606606

607+
builder.AppendSwitchIfNotNull(
608+
isZig ? "--subsystem " : "-Wl,--subsystem,", _outputType == ZigOutputType.WinExe ? "windows" : "console");
609+
607610
// TODO: https://github.com/vezel-dev/zig-sdk/issues/8
608611

609612
builder.AppendFileNamesIfNotNull(Sources, delimiter: " ");

src/sdk/ZigOutputType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ namespace Vezel.Zig.Tasks;
33
public enum ZigOutputType
44
{
55
Exe,
6+
WinExe,
67
Library,
78
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
<Compile Include="**/*.cxx"
2121
Excludes="$(DefaultItemExcludes); $(DefaultExcludesInProjectFolder)"
2222
Condition="'$(CompilerMode)' == 'Cxx'" />
23-
<Compile Include="main.zig"
24-
Condition="'$(CompilerMode)' == 'Zig' and '$(OutputType)' == 'Exe'" />
2523
<Compile Include="$(AssemblyName).zig"
26-
Condition="'$(CompilerMode)' == 'Zig' and '$(OutputType)' != 'Exe'" />
24+
Condition="'$(CompilerMode)' == 'Zig' and '$(OutputType)' == 'Library'" />
25+
<Compile Include="main.zig"
26+
Condition="'$(CompilerMode)' == 'Zig' and '$(OutputType)' != 'Library'" />
2727
</ItemGroup>
2828
</Project>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
<IsCrossExecuting Condition="'$(IsCrossCompilingSystem)' == 'true'">true</IsCrossExecuting>
3232
</PropertyGroup>
3333

34-
<PropertyGroup Condition="'$(OutputType)' == 'Exe'">
35-
<TargetSuffix>$(TargetExeSuffix)</TargetSuffix>
36-
</PropertyGroup>
37-
3834
<PropertyGroup Condition="'$(OutputType)' == 'Library'">
3935
<TargetPrefix>$(TargetLibraryPrefix)</TargetPrefix>
4036
<TargetSuffix>$(TargetLibrarySuffix)</TargetSuffix>
4137
</PropertyGroup>
4238

39+
<PropertyGroup Condition="'$(OutputType)' != 'Library'">
40+
<TargetSuffix>$(TargetExeSuffix)</TargetSuffix>
41+
</PropertyGroup>
42+
4343
<!--
4444
These are the properties used by the rest of the MSBuild ecosystem. We can
4545
now set them based on the conditional logic above.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Returns="@(_NativeBinary)">
6161
<PropertyGroup>
6262
<_PackageNativePath>runtimes</_PackageNativePath>
63-
<_PackageNativePath Condition="'$(OutputType)' == 'Exe'">tools</_PackageNativePath>
63+
<_PackageNativePath Condition="'$(OutputType)' != 'Library'">tools</_PackageNativePath>
6464
</PropertyGroup>
6565

6666
<ItemGroup>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project>
2-
<PropertyGroup Condition="'$(RunCommand)' == '' and '$(OutputType)' == 'Exe' and '$(EmulatorCommand)' != ''">
2+
<PropertyGroup Condition="'$(RunCommand)' == '' and '$(OutputType)' != 'Library' and '$(EmulatorCommand)' != ''">
33
<RunCommand>$(EmulatorCommand)</RunCommand>
44
<RunArguments>$(EmulatorArgumentPrefix)&quot;$(TargetPath)&quot;$(EmulatorArgumentSuffix)$(StartArguments)</RunArguments>
55
</PropertyGroup>
66

7-
<PropertyGroup Condition="'$(RunCommand)' == '' and '$(OutputType)' == 'Exe'">
7+
<PropertyGroup Condition="'$(RunCommand)' == '' and '$(OutputType)' != 'Library'">
88
<RunCommand>$(TargetPath)</RunCommand>
99
<RunArguments>$(StartArguments)</RunArguments>
1010
</PropertyGroup>
@@ -16,7 +16,7 @@
1616

1717
<Target Name="_UnableToRun">
1818
<Error Text="A project with output type '$(OutputType)' cannot be executed"
19-
Condition="'$(OutputType)' != 'Exe'" />
19+
Condition="'$(OutputType)' == 'Library'" />
2020
<Error Text="A suitable binary emulator is not available for '$(HostRuntimeIdentifier)' -> '$(TargetRuntimeIdentifier)'"
2121
Condition="'$(EmulatorCommand)' == ''" />
2222
</Target>

0 commit comments

Comments
 (0)