Skip to content

Commit e49db46

Browse files
feat: upgrade wasmtime and add netstandard2.0 local bucketing support (#104)
* Upgrade wasmtime version and add new target framework * updates to fix net2.0 issues and match wasmtime updates * using precompiler directives for net2.0 specific code * Update DevCycle.SDK.Server.Local/Api/LocalBucketing.cs Co-authored-by: Jamie Sinn <jamie.sinn@taplytics.com> * Update DevCycle.SDK.Server.Local/Api/LocalBucketing.cs Co-authored-by: Jamie Sinn <jamie.sinn@taplytics.com> * changing target of the example * Add action to test example * tweaks * try with windows * tinkering with version numbers * try to get it working * change secret name * enable cloud example test * more tweaks try earlier version * fix version * try a matrix * remove the matrix thing * trying net48 again * restore project config * debugging experiment * try diagnostic logging to figure out linker problem * fixing framework targetting * remove versioned refs * removing some steps * try to force release on run * removed diagnostic logging * trying a different approach * experimenting * try again * try again * try again * expanding the script * just make the examples work with Net6.0 and enable github action to test run them * readme tweak * Update DevCycle.SDK.Server.Local/DevCycle.SDK.Server.Local.csproj Co-authored-by: Jamie Sinn <jamie.sinn@taplytics.com> * Update README.md Co-authored-by: Jamie Sinn <jamie.sinn@taplytics.com> --------- Co-authored-by: Jamie Sinn <jamie.sinn@taplytics.com>
1 parent 9e69079 commit e49db46

File tree

7 files changed

+67
-13
lines changed

7 files changed

+67
-13
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test Run Examples
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
# Using the DevCycle Internal Default key
11+
DVC_SERVER_SDK_KEY: "${{ secrets.EXAMPLE_DEVCYCLE_SERVER_SDK_KEY }}"
12+
13+
jobs:
14+
run-example:
15+
runs-on: windows-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v2
20+
with:
21+
dotnet-version: "6.0.x"
22+
- name: Build
23+
run: |
24+
dotnet build
25+
- name: Run Local Example
26+
run: |
27+
dotnet run --configuration Release --project .\DevCycle.SDK.Server.Local.Example\DevCycle.SDK.Server.Local.Example.csproj
28+
- name: Run Cloud Example
29+
run: |
30+
dotnet run --configuration Release --project .\DevCycle.SDK.Server.Cloud.Example\DevCycle.SDK.Server.Cloud.Example.csproj
31+
32+

DevCycle.SDK.Server.Cloud.Example/DevCycle.SDK.Server.Cloud.Example.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<!-- Uncomment the following line to test with .NET 4.8
57
<TargetFramework>net48</TargetFramework>
8+
-->
69
<ReleaseVersion>1.0.1</ReleaseVersion>
710
<RootNamespace>Example</RootNamespace>
811
</PropertyGroup>
@@ -13,8 +16,12 @@
1316
</ItemGroup>
1417

1518
<ItemGroup>
16-
<PackageReference Include="DevCycle.SDK.Server.Cloud" Version="1.10.2" />
1719
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1820
<PackageReference Include="RestSharp" Version="110.2.0" />
1921
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\DevCycle.SDK.Server.Common\DevCycle.SDK.Server.Common.csproj" />
25+
<ProjectReference Include="..\DevCycle.SDK.Server.Cloud\DevCycle.SDK.Server.Cloud.csproj" />
26+
</ItemGroup>
2027
</Project>

DevCycle.SDK.Server.Local.Example/DevCycle.SDK.Server.Local.Example.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6+
<!-- Uncomment the following line to test with .NET 4.8
7+
<TargetFramework>net48</TargetFramework>
8+
-->
69
<ReleaseVersion>1.0.1</ReleaseVersion>
710
<RootNamespace>Example</RootNamespace>
811
</PropertyGroup>
@@ -13,8 +16,6 @@
1316
</ItemGroup>
1417

1518
<ItemGroup>
16-
<PackageReference Include="DevCycle.SDK.Server.Common" Version="1.11.2" />
17-
<PackageReference Include="DevCycle.SDK.Server.Local" Version="2.8.2" />
1819
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1920
<PackageReference Include="RestSharp" Version="110.2.0" />
2021
</ItemGroup>

DevCycle.SDK.Server.Local.Example/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ private static void ClientInitialized(User user)
6464

6565
Console.WriteLine(api.Variable(user, "test-variable", true));
6666
Console.WriteLine(api.AllVariables(user));
67+
68+
api.Dispose();
6769
}
6870
}
6971
}

DevCycle.SDK.Server.Local/Api/LocalBucketing.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public LocalBucketing()
6969
pinnedAddresses = new HashSet<int>();
7070
sdkKeyAddresses = new Dictionary<string, int>();
7171

72-
Console.WriteLine("Initializing .NETStandard2.1 Local Bucketing");
72+
Console.WriteLine("Initializing Local Bucketing");
7373
Assembly assembly = typeof(LocalBucketing).GetTypeInfo().Assembly;
7474

7575
Stream wasmResource = assembly.GetManifestResourceStream("DevCycle.bucketing-lib.release.wasm");
@@ -123,18 +123,20 @@ public LocalBucketing()
123123
Console.WriteLine(message);
124124
})
125125
);
126+
126127
WASMLinker.Define(
127128
"env",
128129
"Date.now",
129130
Function.FromCallback(WASMStore,
130-
(Caller _) => (DateTime.Now.ToUniversalTime() - DateTime.UnixEpoch).TotalMilliseconds)
131+
(Caller _) => Convert.ToDouble(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
132+
)
131133
);
132134
WASMLinker.Define(
133135
"env",
134136
"seed",
135137
Function.FromCallback(WASMStore,
136-
(Caller _) =>
137-
(random.NextDouble() * (DateTime.Now.ToUniversalTime() - DateTime.UnixEpoch).TotalMilliseconds))
138+
(Caller _) => (random.NextDouble() * DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
139+
)
138140
);
139141

140142
WASMInstance = WASMLinker.Instantiate(WASMStore, WASMModule);
@@ -426,10 +428,15 @@ private Function GetFunction(string name)
426428

427429
private int GetParameter(string param)
428430
{
429-
var paramAddress =
430-
(int)NewFunc.Invoke(Encoding.Unicode.GetByteCount(param), WasmObjectIdString)!;
431-
431+
#if NETSTANDARD2_0
432+
byte[] data = Encoding.Unicode.GetBytes(param);
433+
var paramAddress = (int)NewFunc.Invoke(data.Length, WasmObjectIdString)!;
434+
Span<byte> paramSpan = WASMMemory.GetSpan<byte>(paramAddress, data.Length);
435+
data.CopyTo(paramSpan);
436+
#elif NETSTANDARD2_1
437+
var paramAddress = (int)NewFunc.Invoke(Encoding.Unicode.GetByteCount(param), WasmObjectIdString)!;
432438
Encoding.Unicode.GetBytes(param, WASMMemory.GetSpan(paramAddress, Encoding.Unicode.GetByteCount(param)));
439+
#endif
433440

434441
return paramAddress;
435442
}
@@ -525,7 +532,12 @@ private static string ReadAssemblyScriptString(Memory memory, int address)
525532
{
526533
// The byte length of the string is at offset -4 in AssemblyScript string layout.
527534
var length = memory.ReadInt32(address - 4);
535+
#if NETSTANDARD2_0
536+
Span<byte> span = memory.GetSpan<byte>(address, length);
537+
return Encoding.Unicode.GetString(span.ToArray());
538+
#elif NETSTANDARD2_1
528539
return Encoding.Unicode.GetString(memory.GetSpan(address, length));
540+
#endif
529541
}
530542

531543
private static byte[] ReadAssemblyScriptByteArray(Memory memory, int address)

DevCycle.SDK.Server.Local/DevCycle.SDK.Server.Local.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
3030
<LangVersion>latest</LangVersion>
3131
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
32-
<TargetFramework>netstandard2.1</TargetFramework>
32+
<TargetFramework>netstandard2.0</TargetFramework>
3333
</PropertyGroup>
3434

3535
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -45,7 +45,7 @@
4545
<PrivateAssets>all</PrivateAssets>
4646
</PackageReference>
4747
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
48-
<PackageReference Include="Wasmtime" Version="3.0.0" />
48+
<PackageReference Include="Wasmtime" Version="11.0.1" />
4949
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
5050
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
5151
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Welcome to the DevCycle .NET Server SDK, which interfaces with a local bucketing library. This SDK requests config from DevCycle servers on DVCClient initialization.
44
All calls to the client will then perform local bucketing to determine if a user receives a specific variation.
55
Events are queued and flushed periodically in the background.
6-
This version uses .NET Standard 2.1 and utilizes more resources to perform local bucketing.
6+
This version is compatible with .NET Standard 2.0 and utilizes more resources to perform local bucketing.
77

88
## Installation
99
Download the SDK from Nuget - https://www.nuget.org/packages/DevCycle.SDK.Server.Local/

0 commit comments

Comments
 (0)