Skip to content

Commit caddc4c

Browse files
Make static linking optional and fix publishing without explicit runtime id
1 parent ab5d078 commit caddc4c

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public record struct Velocity(float X, float Y);
4949

5050
**Flecs.NET.Native - Precompiled native libraries**
5151
- Provides both shared and static libraries for Windows, MacOS, Linux, iOS, and WASM
52-
- `$(FlecsStaticLibrary)` is provided for static linking in MSBuild projects
5352
- Packaged with Zig for dependency free cross-compilation everywhere
5453

5554
## NuGet
@@ -70,11 +69,10 @@ dotnet add PROJECT package Flecs.NET.Bindings.Release --version *-*
7069
dotnet add PROJECT package Flecs.NET.Native.Release --version *-*
7170
```
7271

73-
**Flecs.NET** provides both [release](https://www.nuget.org/packages/Flecs.NET.Release) and [debug](https://www.nuget.org/packages/Flecs.NET.Debug) packages for nuget.
72+
**Flecs.NET** provides both [release](https://www.nuget.org/packages/Flecs.NET.Release) and [debug](https://www.nuget.org/packages/Flecs.NET.Debug) packages for nuget. It is recommended that the debug packages be used when developing as they include checks for incorrect usage of the API.
7473
To include both of them in your project based on your build configuration, use the package references below. The latest stable or prerelease versions will be added to your project.
7574
```xml
7675
<Project Sdk="Microsoft.NET.Sdk">
77-
7876
<PropertyGroup>
7977
<OutputType>Exe</OutputType>
8078
<TargetFramework>net8.0</TargetFramework>
@@ -84,7 +82,20 @@ To include both of them in your project based on your build configuration, use t
8482
<PackageReference Include="Flecs.NET.Debug" Version="*-*" Condition="'$(Configuration)' == 'Debug'" />
8583
<PackageReference Include="Flecs.NET.Release" Version="*-*" Condition="'$(Configuration)' == 'Release'" />
8684
</ItemGroup>
85+
</Project>
86+
```
87+
### Static Linking
88+
**Flecs.NET** provides precompiled static libraries that can be used when ``PublishAOT`` is enabled. To enable static linking, add ``<FlecsStaticLink>true</FlecsStaticLink>`` to a property group. To prevent shared libraries from being copied to the output directory, add ``ExcludeAssets="native"`` to your package reference.
89+
```xml
90+
<Project Sdk="Microsoft.NET.Sdk">
91+
<PropertyGroup>
92+
<PublishAot>true</PublishAot>
93+
<FlecsStaticLink>true</FlecsStaticLink>
94+
</PropertyGroup>
8795

96+
<ItemGroup>
97+
<PackageReference Include="Flecs.NET.Debug" Version="*-*" ExcludeAssets="native"/>
98+
</ItemGroup>
8899
</Project>
89100
```
90101

@@ -106,7 +117,6 @@ dotnet add PROJECT package Flecs.NET.Release --version *-build.*
106117

107118
```xml
108119
<Project Sdk="Microsoft.NET.Sdk">
109-
110120
<PropertyGroup>
111121
<OutputType>Exe</OutputType>
112122
<TargetFramework>net8.0</TargetFramework>
@@ -115,7 +125,6 @@ dotnet add PROJECT package Flecs.NET.Release --version *-build.*
115125
<ItemGroup>
116126
<PackageReference Include="Flecs.NET.Debug" Version="*-build.*"/>
117127
</ItemGroup>
118-
119128
</Project>
120129
```
121130
___
@@ -167,7 +176,6 @@ Reference the project and import the native libraries. You should now be able to
167176

168177
```xml
169178
<Project Sdk="Microsoft.NET.Sdk">
170-
171179
<PropertyGroup>
172180
<OutputType>Exe</OutputType>
173181
<TargetFramework>net8.0</TargetFramework>
@@ -176,7 +184,6 @@ Reference the project and import the native libraries. You should now be able to
176184
<ItemGroup>
177185
<ProjectReference Include="PATH/Flecs.NET/src/Flecs.NET/Flecs.NET.csproj" />
178186
</ItemGroup>
179-
180187
</Project>
181188
```
182189

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>4.0.2</VersionPrefix>
3+
<VersionPrefix>4.0.3</VersionPrefix>
44
<Authors>BeanCheeseBurrito</Authors>
55
<Copyright>BeanCheeseBurrito</Copyright>
66
<PackageProjectUrl>https://github.com/BeanCheeseBurrito/Flecs.NET</PackageProjectUrl>
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
<Project>
2-
<PropertyGroup>
3-
<IsWindowsRuntime Condition="'$(RuntimeIdentifier)' != '' and $(RuntimeIdentifier.StartsWith('win-'))">true</IsWindowsRuntime>
4-
<FlecsStaticPath>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)../static/$(RuntimeIdentifier)/native/'))</FlecsStaticPath>
5-
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' == 'true'">$(FlecsStaticPath)flecs.lib</FlecsStaticLibrary>
6-
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' != 'true'">$(FlecsStaticPath)libflecs.a</FlecsStaticLibrary>
7-
</PropertyGroup>
82
</Project>
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<Project>
2-
<ItemGroup Condition="'$(PublishAot)' == 'true' And Exists('$(FlecsStaticLibrary)')">
3-
<DirectPInvoke Include="flecs"/>
4-
<NativeLibrary Include="$(FlecsStaticLibrary)"/>
5-
</ItemGroup>
2+
<PropertyGroup>
3+
<IsWindowsRuntime Condition="'$(RuntimeIdentifier)' != '' and $(RuntimeIdentifier.StartsWith('win-'))">true</IsWindowsRuntime>
4+
<FlecsStaticPath>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)../static/$(RuntimeIdentifier)/native/'))</FlecsStaticPath>
5+
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' == 'true'">$(FlecsStaticPath)flecs.lib</FlecsStaticLibrary>
6+
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' != 'true'">$(FlecsStaticPath)libflecs.a</FlecsStaticLibrary>
7+
</PropertyGroup>
8+
9+
<ItemGroup Condition="'$(PublishAot)' == 'true' And '$(FlecsStaticLink)' == 'true' And Exists('$(FlecsStaticLibrary)')">
10+
<DirectPInvoke Include="flecs"/>
11+
<NativeLibrary Include="$(FlecsStaticLibrary)"/>
12+
</ItemGroup>
613
</Project>

0 commit comments

Comments
 (0)