Skip to content

Commit aec96e2

Browse files
committed
Add support for an ExecutionModel property (Command/Reactor) for WebAssembly.
1 parent 3920d54 commit aec96e2

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

doc/configuration/properties.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ historical reasons.
153153
* `ReleaseMode` (`Fast`, `Safe`, `Small`): The
154154
[build mode](https://ziglang.org/documentation/master/#Build-Mode) to use when
155155
`Configuration` is set to `Release`. Defaults to `Fast`.
156+
* `ExecutionModel` (`Command`, `Reactor`): Specifies the execution model to use
157+
when building WebAssembly executables. Defaults to `Command`.
156158
* `FastMath` (`true`, `false`): Enable/disable certain lossy floating point
157159
optimizations that may not be standards-compliant. Defaults to `false`.
158160
* `LinkTimeOptimization` (`true`, `false`): Enable/disable link-time

src/sdk/ZigCompile.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public string Configuration
7171
[Required]
7272
public bool EagerBinding { get; set; }
7373

74+
[Required]
75+
public string ExecutionModel
76+
{
77+
get => _executionModel.ToString();
78+
set => _executionModel = (ZigExecutionModel)Enum.Parse(typeof(ZigExecutionModel), value);
79+
}
80+
7481
[Required]
7582
public bool FastMath { get; set; }
7683

@@ -196,6 +203,8 @@ public string SymbolVisibility
196203

197204
private ZigConfiguration _configuration;
198205

206+
private ZigExecutionModel _executionModel;
207+
199208
private int? _imageBase;
200209

201210
private ZigOutputType _outputType;
@@ -251,7 +260,9 @@ protected override string GenerateCommandLineCommands()
251260
}
252261
else
253262
{
254-
if (!TargetTriple.StartsWith("wasm", StringComparison.Ordinal))
263+
if (TargetTriple.StartsWith("wasm", StringComparison.Ordinal))
264+
builder.AppendSwitch($"-mexec-model={ExecutionModel.ToLowerInvariant()}");
265+
else
255266
builder.AppendSwitch("-fPIE");
256267

257268
if (NoEntryPoint)

src/sdk/ZigExecutionModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: 0BSD
2+
3+
namespace Vezel.Zig.Tasks;
4+
5+
public enum ZigExecutionModel
6+
{
7+
Command,
8+
Reactor,
9+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
DynamicImageBase="$(DynamicImageBase)"
6565
EagerBinding="$(EagerBinding)"
6666
EnvironmentVariables="ZIG_GLOBAL_CACHE_DIR=$(GlobalCachePath); ZIG_LOCAL_CACHE_DIR=$(LocalCachePath)"
67+
ExecutionModel="$(ExecutionModel)"
6768
FastMath="$(FastMath)"
6869
ImageBase="$(ImageBase)"
6970
IncludeDirectories="@(IncludeDirectory)"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<AllowUndefinedSymbols Condition="'$(AllowUndefinedSymbols)' == ''">false</AllowUndefinedSymbols>
5757
<DynamicImageBase Condition="'$(DynamicImageBase)' == ''">true</DynamicImageBase>
5858
<EagerBinding Condition="'$(EagerBinding)' == ''">true</EagerBinding>
59+
<ExecutionModel Condition="'$(ExecutionModel)' == ''">Command</ExecutionModel>
5960
<FastMath Condition="'$(FastMath)' == ''">false</FastMath>
6061
<!-- TODO: https://github.com/vezel-dev/zig-sdk/issues/33 -->
6162
<LinkTimeOptimization Condition="'$(LinkTimeOptimization)' == ''">true</LinkTimeOptimization>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DynamicImageBase="$(DynamicImageBase)"
3737
EagerBinding="$(EagerBinding)"
3838
EnvironmentVariables="ZIG_GLOBAL_CACHE_DIR=$(GlobalCachePath); ZIG_LOCAL_CACHE_DIR=$(LocalCachePath)"
39+
ExecutionModel="$(ExecutionModel)"
3940
FastMath="$(FastMath)"
4041
ImageBase="$(ImageBase)"
4142
IncludeDirectories="@(IncludeDirectory)"

0 commit comments

Comments
 (0)