Skip to content

Commit

Permalink
Make static linking optional and fix publishing without explicit runt…
Browse files Browse the repository at this point in the history
…ime id
  • Loading branch information
BeanCheeseBurrito committed Nov 22, 2024
1 parent ab5d078 commit caddc4c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public record struct Velocity(float X, float Y);

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

## NuGet
Expand All @@ -70,11 +69,10 @@ dotnet add PROJECT package Flecs.NET.Bindings.Release --version *-*
dotnet add PROJECT package Flecs.NET.Native.Release --version *-*
```

**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.
**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.
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.
```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -84,7 +82,20 @@ To include both of them in your project based on your build configuration, use t
<PackageReference Include="Flecs.NET.Debug" Version="*-*" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Flecs.NET.Release" Version="*-*" Condition="'$(Configuration)' == 'Release'" />
</ItemGroup>
</Project>
```
### Static Linking
**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.
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PublishAot>true</PublishAot>
<FlecsStaticLink>true</FlecsStaticLink>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flecs.NET.Debug" Version="*-*" ExcludeAssets="native"/>
</ItemGroup>
</Project>
```

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

```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -115,7 +125,6 @@ dotnet add PROJECT package Flecs.NET.Release --version *-build.*
<ItemGroup>
<PackageReference Include="Flecs.NET.Debug" Version="*-build.*"/>
</ItemGroup>

</Project>
```
___
Expand Down Expand Up @@ -167,7 +176,6 @@ Reference the project and import the native libraries. You should now be able to

```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -176,7 +184,6 @@ Reference the project and import the native libraries. You should now be able to
<ItemGroup>
<ProjectReference Include="PATH/Flecs.NET/src/Flecs.NET/Flecs.NET.csproj" />
</ItemGroup>

</Project>
```

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>4.0.2</VersionPrefix>
<VersionPrefix>4.0.3</VersionPrefix>
<Authors>BeanCheeseBurrito</Authors>
<Copyright>BeanCheeseBurrito</Copyright>
<PackageProjectUrl>https://github.com/BeanCheeseBurrito/Flecs.NET</PackageProjectUrl>
Expand Down
6 changes: 0 additions & 6 deletions src/Flecs.NET.Native/buildTransitive/Flecs.NET.Native.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
<Project>
<PropertyGroup>
<IsWindowsRuntime Condition="'$(RuntimeIdentifier)' != '' and $(RuntimeIdentifier.StartsWith('win-'))">true</IsWindowsRuntime>
<FlecsStaticPath>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)../static/$(RuntimeIdentifier)/native/'))</FlecsStaticPath>
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' == 'true'">$(FlecsStaticPath)flecs.lib</FlecsStaticLibrary>
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' != 'true'">$(FlecsStaticPath)libflecs.a</FlecsStaticLibrary>
</PropertyGroup>
</Project>
15 changes: 11 additions & 4 deletions src/Flecs.NET.Native/buildTransitive/Flecs.NET.Native.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<Project>
<ItemGroup Condition="'$(PublishAot)' == 'true' And Exists('$(FlecsStaticLibrary)')">
<DirectPInvoke Include="flecs"/>
<NativeLibrary Include="$(FlecsStaticLibrary)"/>
</ItemGroup>
<PropertyGroup>
<IsWindowsRuntime Condition="'$(RuntimeIdentifier)' != '' and $(RuntimeIdentifier.StartsWith('win-'))">true</IsWindowsRuntime>
<FlecsStaticPath>$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)../static/$(RuntimeIdentifier)/native/'))</FlecsStaticPath>
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' == 'true'">$(FlecsStaticPath)flecs.lib</FlecsStaticLibrary>
<FlecsStaticLibrary Condition="'$(IsWindowsRuntime)' != 'true'">$(FlecsStaticPath)libflecs.a</FlecsStaticLibrary>
</PropertyGroup>

<ItemGroup Condition="'$(PublishAot)' == 'true' And '$(FlecsStaticLink)' == 'true' And Exists('$(FlecsStaticLibrary)')">
<DirectPInvoke Include="flecs"/>
<NativeLibrary Include="$(FlecsStaticLibrary)"/>
</ItemGroup>
</Project>

0 comments on commit caddc4c

Please sign in to comment.