Skip to content

Commit 3b935bd

Browse files
committed
Create monolithic NuGet package for C# libraries
1 parent 66b5144 commit 3b935bd

File tree

18 files changed

+132
-133
lines changed

18 files changed

+132
-133
lines changed

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ ExternalProject_Add(
1818
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/sdk/install
1919
)
2020

21+
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
22+
set(DOTNET_CONFIGURATION Debug)
23+
else()
24+
set(DOTNET_CONFIGURATION ${CMAKE_BUILD_TYPE})
25+
endif()
26+
27+
add_custom_target(
28+
sdk_nuget_package ALL
29+
dotnet pack
30+
-c ${DOTNET_CONFIGURATION}
31+
"\"${CMAKE_CURRENT_SOURCE_DIR}/csharp/ConstraintSDK.csproj\""
32+
)
33+
2134
ExternalProject_Add(
2235
bare_wasm_cpp
2336
PREFIX examples/bare_wasm_cpp
@@ -53,16 +66,11 @@ ExternalProject_Add(
5366
add_dependencies(examples emscripten_cpp)
5467

5568
if(NOT "${NATIVEAOT_ROOT}" STREQUAL "")
56-
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
57-
set(DOTNET_CONFIGURATION Debug)
58-
else()
59-
set(DOTNET_CONFIGURATION ${CMAKE_BUILD_TYPE})
60-
endif()
61-
6269
add_custom_target(
6370
emscripten_csharp
64-
COMMAND cmake -E env "\"NATIVEAOT_ROOT=${NATIVEAOT_ROOT}\""
71+
COMMAND cmake -E env "\"NATIVEAOT_ROOT=${NATIVEAOT_ROOT}\"" "\"SDK_NUGET_PACKAGE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/csharp/bin/${DOTNET_CONFIGURATION}\""
6572
dotnet publish
73+
--packages ${CMAKE_CURRENT_BINARY_DIR}/nuget_packages
6674
-r browser-wasm
6775
-c ${DOTNET_CONFIGURATION}
6876
-p:Platform=wasm
@@ -71,7 +79,7 @@ if(NOT "${NATIVEAOT_ROOT}" STREQUAL "")
7179
"\"${CMAKE_CURRENT_SOURCE_DIR}/examples/emscripten_csharp/Example.csproj\""
7280
)
7381

74-
add_dependencies(emscripten_csharp sdk)
82+
add_dependencies(emscripten_csharp sdk sdk_nuget_package)
7583

7684
add_dependencies(examples emscripten_csharp)
7785
endif()
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3-
using static Solver;
3+
using static ConstraintSDK.Solver;
44

55
#pragma warning disable CS0660, CS0661
66

7-
namespace ConstraintArithmetic {
7+
namespace ConstraintSDK.ConstraintArithmetic {
88
public struct ArithmeticConstraint {
99
public float LeftConstant;
1010
public float[] LeftCoefficients;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
5+
<PackageVersion>0.0.2</PackageVersion>
56
</PropertyGroup>
67

78
<ItemGroup>
8-
<ProjectReference Include="../Solver/Solver.csproj" />
9+
<Content Include="build/*">
10+
<PackagePath>build</PackagePath>
11+
</Content>
912
</ItemGroup>
1013

1114
</Project>

sdk/lib/csharp/Controls/Controls.cs renamed to csharp/Controls.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Collections.Generic;
44
using System.Runtime.InteropServices;
55
using System.Runtime.CompilerServices;
6-
using static SystemControls;
7-
using ConstraintArithmetic;
6+
using static ConstraintSDK.SystemControls;
7+
using ConstraintSDK.ConstraintArithmetic;
88

9-
namespace Controls {
9+
namespace ConstraintSDK.Controls {
1010
public class Label {
1111
public ArithmeticVariable Left;
1212
public ArithmeticVariable Top;

csharp/Solver.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace ConstraintSDK {
5+
public static class Solver {
6+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
7+
[return: MarshalAs(UnmanagedType.U1)]
8+
public static extern bool solve(
9+
UIntPtr variable_count,
10+
UIntPtr constraint_count,
11+
[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.U1)] bool[] is_variable_external,
12+
ref float objective_constant,
13+
float[] objective_coefficients,
14+
UIntPtr[] constraint_variable_indices,
15+
[In, Out] float[] constraint_constants,
16+
float[] constraint_coefficients
17+
);
18+
}
19+
}

csharp/SystemControls.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace ConstraintSDK {
5+
public static class SystemControls {
6+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
7+
public static extern float get_text_width(
8+
byte[] text_data,
9+
UIntPtr text_length,
10+
byte[] font_family_data,
11+
UIntPtr font_family_length,
12+
float font_size
13+
);
14+
15+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
16+
public static extern void get_frame_size(
17+
out float width,
18+
out float height
19+
);
20+
21+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
22+
public static extern void clear_controls();
23+
24+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
25+
public static extern UIntPtr create_label(
26+
float x,
27+
float y,
28+
byte[] text_data,
29+
UIntPtr text_length,
30+
byte[] font_family_data,
31+
UIntPtr font_family_length,
32+
float font_size
33+
);
34+
35+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
36+
public static extern UIntPtr create_button(
37+
float x,
38+
float y,
39+
float width,
40+
float height,
41+
byte[] text_data,
42+
UIntPtr text_length,
43+
byte[] font_family_data,
44+
UIntPtr font_family_length,
45+
float font_size
46+
);
47+
48+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
49+
public static extern UIntPtr create_text_input(
50+
float x,
51+
float y,
52+
float width,
53+
float height,
54+
byte[] text_data,
55+
UIntPtr text_length,
56+
byte[] font_family_data,
57+
UIntPtr font_family_length,
58+
float font_size
59+
);
60+
61+
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
62+
public static extern UIntPtr get_text_input_text(
63+
UIntPtr text_input,
64+
[In, Out] byte[] buffer,
65+
UIntPtr buffer_size
66+
);
67+
}
68+
}

csharp/build/ConstraintSDK.props

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<PropertyGroup>
4+
<EmccExtraArgs Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">$(EmccExtraArgs) $(ConstraintSDKPath)/lib/wasm32-emscripten/libsolver.a --js-library $(ConstraintSDKPath)/lib/system_controls_emscripten.js -s NO_EXIT_RUNTIME -s EXTRA_EXPORTED_RUNTIME_METHODS=["ccall"] -s EXPORTED_FUNCTIONS=["_main","_button_press_handler","_frame_resize_handler","_text_input_change_handler"]</EmccExtraArgs>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Content Condition="'$(RuntimeIdentifier)' == 'browser-wasm'" Include="$(ConstraintSDKPath)/lib/system_controls.js">
9+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
10+
</Content>
11+
</ItemGroup>
12+
13+
</Project>

examples/emscripten_cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ add_custom_target(
1515
)
1616

1717
add_executable(example main.cpp)
18-
set_target_properties(example PROPERTIES LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/emscripten_library.js")
18+
set_target_properties(example PROPERTIES LINK_DEPENDS "${ConstraintSDK_DIR}/lib/system_controls_emscripten.js")
1919
target_include_directories(example PRIVATE ${ConstraintSDK_INCLUDE_DIRS})
2020
target_link_libraries(example PRIVATE ${ConstraintSDK_LIBRARIES})
21-
target_link_options(example PRIVATE --js-library "${CMAKE_CURRENT_SOURCE_DIR}/emscripten_library.js")
21+
target_link_options(example PRIVATE --js-library "${ConstraintSDK_DIR}/lib/system_controls_emscripten.js")
2222
target_link_options(example PRIVATE "-s" EXTRA_EXPORTED_RUNTIME_METHODS=[\"ccall\"])
2323
target_link_options(example PRIVATE "-s " EXPORTED_FUNCTIONS=[\"_init\",\"_button_press_handler\",\"_frame_resize_handler\",\"_text_input_change_handler\"])
2424
add_dependencies(example copy_files)

examples/emscripten_csharp/Example.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

8-
<PropertyGroup>
9-
<EmccExtraArgs>$(ConstraintSDKPath)/lib/wasm32-emscripten/libsolver.a --js-library $(MSBuildProjectDirectory)/emscripten_library.js -s NO_EXIT_RUNTIME -s EXTRA_EXPORTED_RUNTIME_METHODS=["ccall"] -s EXPORTED_FUNCTIONS=["_main","_button_press_handler","_frame_resize_handler","_text_input_change_handler"]</EmccExtraArgs>
10-
</PropertyGroup>
11-
128
<ItemGroup>
139
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="6.0.0-*" />
14-
<ProjectReference Include="../../sdk/lib/csharp/Controls/Controls.csproj" />
10+
<PackageReference Include="ConstraintSDK" Version="0.0.2" />
1511
</ItemGroup>
1612

1713
<ItemGroup>
18-
<Content Include="index.html;index.js;index.css;$(ConstraintSDKPath)/lib/system_controls.js">
14+
<Content Include="index.html;index.js;index.css;">
1915
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2016
</Content>
2117
</ItemGroup>

0 commit comments

Comments
 (0)