Skip to content

Commit

Permalink
[Build] Self-contained UIX applications
Browse files Browse the repository at this point in the history
- Use self-contained applications, avoids relying on installed .NET runtimes
- CMake generated solutions with mixed C#, C++ and C++/CLI projects require that managed project files are in separate folders from native projects due to an issue with Nuget resolving.
- Fixed sham dependencies on schema .NET bindings, as Visual Studio .NET targets cannot depend on custom commands, create intermediary target to merge all schema dependencies.
- Upgraded to .NET6.0, better support for missing .NET runtimes and numerous fixes to self-contained apps
- Default to latest C# language version for the given SDK
- .NET6 implicitly disables com-interop support with trimming, re-enable it

#48
  • Loading branch information
miguel-petersen committed Jan 21, 2024
1 parent 15a999e commit e412bba
Show file tree
Hide file tree
Showing 51 changed files with 356 additions and 81 deletions.
65 changes: 44 additions & 21 deletions Build/CSharp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,64 @@ function(Project_AddDotNet NAME)
# DotNet
set_target_properties(
${NAME} PROPERTIES
VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.8"
DOTNET_SDK "Microsoft.NET.Sdk"
DOTNET_TARGET_FRAMEWORK "net6.0"
VS_GLOBAL_Platforms "x64"
VS_GLOBAL_RuntimeIdentifier "win-x64"
VS_GLOBAL_SelfContained "true"
VS_GLOBAL_AppendTargetFrameworkToOutputPath "false"
VS_GLOBAL_AppendRuntimeIdentifierToOutputPath "false"
VS_GLOBAL_ROOTNAMESPACE ${NAME}
)

# IDE source discovery
SetSourceDiscovery(${NAME} CS Include Source Schema)
endfunction()

# Add a .NET merge target for generated files
# ! Must be called in the same CMakeLists.txt as the custom commands
function(Project_AddDotNetGeneratedMerge NAME GENERATED_SOURCES)
set(Command "")

# Copy each schema target
foreach(File ${${GENERATED_SOURCES}})
list(APPEND Command COMMAND "${CMAKE_COMMAND}" -E copy "${File}.gen" "${File}")

# Generated project / MSBUILD does not check that if inbound file originates from
# another target.
if (NOT EXISTS ${File})
file(WRITE "${File}" "Generation target file")
endif()
endforeach()

# Schema Gen -> Schema
add_custom_target(
${NAME}
DEPENDS ${${GENERATED_SOURCES}_Gen}
BYPRODUCTS ${${GENERATED_SOURCES}}
${Command}
)
endfunction()

function(Project_AddDotNetEx)
cmake_parse_arguments(
ARGS
"UNSAFE;EXECUTABLE" # Options
"NAME;LANG;PROPS" # One Value
"SOURCE;GENERATED;ASSEMBLIES;LIBS;FLAGS" # Multi Value
"SOURCE;DEPENDENCIES;ASSEMBLIES;LIBS;FLAGS" # Multi Value
${ARGN}
)

if (NOT "${ARGS_GENERATED}" STREQUAL "")
# Generate sham target
# ! WORKAROUND, Visual Studio generators do not support C# sources from add_custom_command
# Check introduced by 3.24
add_library(${ARGS_NAME}.Sham INTERFACE ${${ARGS_GENERATED}_Sham})

# Create dummy file to keep MSVC happy
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${${ARGS_GENERATED}_Sham}")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${${ARGS_GENERATED}_Sham}" Sham)
endif()
endif()

# Create library
if ("${ARGS_EXECUTABLE}")
add_executable(
${ARGS_NAME}
${ARGS_SOURCE}
${${ARGS_GENERATED}}
)
else()
add_library(
${ARGS_NAME} SHARED
${ARGS_SOURCE}
${${ARGS_GENERATED}}
)
endif()

Expand All @@ -95,7 +112,13 @@ function(Project_AddDotNetEx)
# Set .NET, link to assemblies and libs
set_target_properties(
${ARGS_NAME} PROPERTIES
VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.8"
DOTNET_SDK "Microsoft.NET.Sdk"
DOTNET_TARGET_FRAMEWORK "net6.0"
VS_GLOBAL_Platforms "x64"
VS_GLOBAL_RuntimeIdentifier "win-x64"
VS_GLOBAL_SelfContained "true"
VS_GLOBAL_AppendTargetFrameworkToOutputPath "false"
VS_GLOBAL_AppendRuntimeIdentifierToOutputPath "false"
VS_GLOBAL_ROOTNAMESPACE "${ARGS_NAME}"
VS_DOTNET_REFERENCES "${ARGS_ASSEMBLIES};${ARGS_LIBS}"
VS_USER_PROPS "${CMAKE_SOURCE_DIR}/Build/cs.configuration.props"
Expand Down Expand Up @@ -128,10 +151,10 @@ function(Project_AddDotNetEx)
endif()
endif()

# Reference sham target to let dependencies generate before use
if (NOT "${ARGS_GENERATED}" STREQUAL "")
add_dependencies(${ARGS_NAME} ${ARGS_NAME}.Sham)
endif()
# Add additional dependencies
if (NOT "${ARGS_DEPENDENCIES}" STREQUAL "")
add_dependencies(${ARGS_NAME} ${ARGS_DEPENDENCIES})
endif()

# IDE source discovery
SetSourceDiscovery(${ARGS_NAME} ${ARGS_LANG} Include Source)
Expand Down
3 changes: 3 additions & 0 deletions Build/cs.configuration.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ResolveNuGetPackages>false</ResolveNuGetPackages>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|x64'" Label="Configuration">
<Optimize>true</Optimize>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ if (${ENABLE_UIX} AND CMAKE_GENERATOR MATCHES "Visual Studio")
enable_language(CSharp)

# Set standard C# properties
SET(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "v4.8")
SET(CMAKE_CSharp_FLAGS "/langversion:6")
SET(CMAKE_DOTNET_TARGET_FRAMEWORK "net6.0")
SET(CMAKE_CSharp_FLAGS "/langversion:latest")
SET(CMAKE_CSharp_FLAGS "/platform:x64")
else()
set(BUILD_UIX OFF)
Expand Down
3 changes: 2 additions & 1 deletion Source/Features/Concurrency/Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ Project_AddTest(
#----- .Net bindings -----#

if (${BUILD_UIX})
Project_AddSchemaDotNet(GRS.Features.Concurrency.Backend.DotNet GeneratedCS)
Project_AddDotNetGeneratedMerge(GRS.Features.Concurrency.Backend.DotNet.GenMerge GeneratedCS)
add_subdirectory(DotNet)
endif()
31 changes: 31 additions & 0 deletions Source/Features/Concurrency/Backend/DotNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.,
# Fatalist Development AB (Avalanche Studio Group),
# and Miguel Petersen.
#
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

Project_AddSchemaDotNet(
GRS.Features.Concurrency.Backend.DotNet
GRS.Features.Concurrency.Backend.DotNet.GenMerge
GeneratedCS
)
2 changes: 1 addition & 1 deletion Source/Features/Concurrency/Frontend/UIX/UIX.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetCulture>en</TargetCulture>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;MinSizeRel;RelWithDebInfo</Configurations>
Expand Down
3 changes: 2 additions & 1 deletion Source/Features/Descriptor/Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ Project_AddTest(
#----- .Net bindings -----#

if (${BUILD_UIX})
Project_AddSchemaDotNet(GRS.Features.Descriptor.Backend.DotNet GeneratedCS)
Project_AddDotNetGeneratedMerge(GRS.Features.Descriptor.Backend.DotNet.GenMerge GeneratedCS)
add_subdirectory(DotNet)
endif()
31 changes: 31 additions & 0 deletions Source/Features/Descriptor/Backend/DotNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.,
# Fatalist Development AB (Avalanche Studio Group),
# and Miguel Petersen.
#
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

Project_AddSchemaDotNet(
GRS.Features.Descriptor.Backend.DotNet
GRS.Features.Descriptor.Backend.DotNet.GenMerge
GeneratedCS
)
2 changes: 1 addition & 1 deletion Source/Features/Descriptor/Frontend/UIX/UIX.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetCulture>en</TargetCulture>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;MinSizeRel;RelWithDebInfo</Configurations>
Expand Down
3 changes: 2 additions & 1 deletion Source/Features/ExportStability/Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ Project_AddTest(
#----- .Net bindings -----#

if (${BUILD_UIX})
Project_AddSchemaDotNet(GRS.Features.ExportStability.Backend.DotNet GeneratedCS)
Project_AddDotNetGeneratedMerge(GRS.Features.ExportStability.Backend.DotNet.GenMerge GeneratedCS)
add_subdirectory(DotNet)
endif()
31 changes: 31 additions & 0 deletions Source/Features/ExportStability/Backend/DotNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.,
# Fatalist Development AB (Avalanche Studio Group),
# and Miguel Petersen.
#
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

Project_AddSchemaDotNet(
GRS.Features.ExportStability.Backend.DotNet
GRS.Features.ExportStability.Backend.DotNet.GenMerge
GeneratedCS
)
2 changes: 1 addition & 1 deletion Source/Features/ExportStability/Frontend/UIX/UIX.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetCulture>en</TargetCulture>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;MinSizeRel;RelWithDebInfo</Configurations>
Expand Down
3 changes: 2 additions & 1 deletion Source/Features/Initialization/Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ Project_AddTest(
#----- .Net bindings -----#

if (${BUILD_UIX})
Project_AddSchemaDotNet(GRS.Features.Initialization.Backend.DotNet GeneratedCS)
Project_AddDotNetGeneratedMerge(GRS.Features.Initialization.Backend.DotNet.GenMerge GeneratedCS)
add_subdirectory(DotNet)
endif()
31 changes: 31 additions & 0 deletions Source/Features/Initialization/Backend/DotNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.,
# Fatalist Development AB (Avalanche Studio Group),
# and Miguel Petersen.
#
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

Project_AddSchemaDotNet(
GRS.Features.Initialization.Backend.DotNet
GRS.Features.Initialization.Backend.DotNet.GenMerge
GeneratedCS
)
2 changes: 1 addition & 1 deletion Source/Features/Initialization/Frontend/UIX/UIX.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetCulture>en</TargetCulture>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;MinSizeRel;RelWithDebInfo</Configurations>
Expand Down
3 changes: 2 additions & 1 deletion Source/Features/Loop/Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ Project_AddTest(
#----- .Net bindings -----#

if (${BUILD_UIX})
Project_AddSchemaDotNet(GRS.Features.Loop.Backend.DotNet GeneratedCS)
Project_AddDotNetGeneratedMerge(GRS.Features.Loop.Backend.DotNet.GenMerge GeneratedCS)
add_subdirectory(DotNet)
endif()
31 changes: 31 additions & 0 deletions Source/Features/Loop/Backend/DotNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.,
# Fatalist Development AB (Avalanche Studio Group),
# and Miguel Petersen.
#
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

Project_AddSchemaDotNet(
GRS.Features.Loop.Backend.DotNet
GRS.Features.Loop.Backend.DotNet.GenMerge
GeneratedCS
)
2 changes: 1 addition & 1 deletion Source/Features/Loop/Frontend/UIX/UIX.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetCulture>en</TargetCulture>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;MinSizeRel;RelWithDebInfo</Configurations>
Expand Down
3 changes: 2 additions & 1 deletion Source/Features/ResourceBounds/Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ Project_AddTest(
#----- .Net bindings -----#

if (${BUILD_UIX})
Project_AddSchemaDotNet(GRS.Features.ResourceBounds.Backend.DotNet GeneratedCS)
Project_AddDotNetGeneratedMerge(GRS.Features.ResourceBounds.Backend.DotNet.GenMerge GeneratedCS)
add_subdirectory(DotNet)
endif()
Loading

0 comments on commit e412bba

Please sign in to comment.