Skip to content

Test what changed #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7704600
cache access
tkstanczak Sep 25, 2018
6d43fa3
all to core only
tkstanczak Sep 25, 2018
55d40b8
update native to 5.15.10
tkstanczak Sep 25, 2018
0eb5c37
native files include
tkstanczak Sep 25, 2018
9433204
fixing rocksdb-sharp build
tkstanczak Sep 25, 2018
357cd93
rocksdb-sharp build changes for v5.15.10
tkstanczak Sep 25, 2018
2565419
removed .idea files, microsoft.csharp 4.5.0
tkstanczak Sep 26, 2018
be8f982
native
tkstanczak Sep 28, 2018
5f3419a
ubuntu 16.04 rocks
tkstanczak Sep 28, 2018
a1e049c
Added librocks.dylib for mac
spetz Oct 1, 2018
ee53a2c
transitional - removed not core part
tkstanczak Oct 1, 2018
37de424
Merge branch 'master' of https://github.com/NethermindEth/rocksdb-sharp
tkstanczak Oct 1, 2018
1242bbe
netcore upgrade
tkstanczak Feb 5, 2019
ea59b67
Merge branch 'master' of https://github.com/warrenfalk/rocksdb-sharp
tkstanczak Apr 17, 2019
37727ae
runtimes
tkstanczak Apr 17, 2019
b1e9ba2
just include
tkstanczak Apr 17, 2019
11b94db
Initial commit - get by Span
kkokosa Jul 18, 2019
33ce7d8
Merge pull request #1 from NethermindEth/spanification
tkstanczak Jul 20, 2019
8cb97be
updated rocksdb to 6.4.6
tkstanczak Dec 4, 2019
3aed41e
Merge branch 'master' of https://github.com/NethermindEth/rocksdb-sharp
tkstanczak Dec 4, 2019
53a6cb6
rocks30
tkstanczak Dec 6, 2019
08900d4
Creating build trigger for rocksdb lib
matilote Dec 9, 2019
1f591b8
6.4.6 loader
tkstanczak Dec 9, 2019
0db8d61
Merge branch 'master' of https://github.com/NethermindEth/rocksdb-sharp
tkstanczak Dec 9, 2019
e8909e6
Merge branch 'master' of https://github.com/warrenfalk/rocksdb-sharp …
tkstanczak Dec 9, 2019
7793d06
Merge branch 'warrenfalk-master'
tkstanczak Dec 9, 2019
3f5cab6
try updating the libs fro rocks
tkstanczak Dec 9, 2019
4982794
updating librocksdb.so with PORTABLE=1
matilote Dec 18, 2019
96aaf92
upgrading netcore version
matilote Mar 12, 2020
3cac0b5
upgrade Core
tkstanczak Mar 17, 2020
89f4206
upgrade of core
tkstanczak Mar 19, 2020
d3273bc
Merge branch 'master' of https://github.com/NethermindEth/rocksdb-sharp
tkstanczak Mar 19, 2020
5abaf53
upgraded some refs
tkstanczak Mar 19, 2020
310b0ab
rocksdb 313
tkstanczak Mar 27, 2020
231f21f
put span
tkstanczak Jul 19, 2020
aca35a2
adding arm runtimes
matilote Jan 5, 2021
fc8c863
Merge pull request #3 from NethermindEth/runtimesarm
matilote Jan 5, 2021
709d4bd
changing paths
matilote Jan 6, 2021
443d953
Merge pull request #4 from NethermindEth/runtimes_fixes
matilote Jan 6, 2021
546f129
removing osx-arm64 for now
matilote Jan 6, 2021
2331d64
Merge pull request #5 from NethermindEth/runtimes_fixes
matilote Jan 6, 2021
46cc8d8
add osx-arm64 support
matilote Oct 27, 2021
0d6715d
net6.0 update
LukaszRozmej Nov 9, 2021
63cc551
LangVersion latest
LukaszRozmej Nov 26, 2021
51b7dd7
updating to latest rocksdb version
matilote Dec 11, 2021
098c7b4
fix rocksdb load on M1 mac
LukaszRozmej Mar 28, 2022
fe9c977
fix language version
LukaszRozmej Mar 28, 2022
dda0e1e
Add files via upload (#7)
FalcoXYZ May 10, 2022
4dab010
fix rocksdb arm64 binary
matilote May 10, 2022
f6d0766
TreatWarningsAsErrors
LukaszRozmej Jul 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/trigger-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Trigger RocksDB build on nethermind repo

on:
push:
branches:
- master

jobs:
bls-building:
name: Building RocksDB
runs-on: ubuntu-latest
steps:
- name: Send dispatch event to nethermind repo
run: |
curl -v -X POST -u "${{ secrets.REPOSITORY_DISPATCH_TOKEN }}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" --data '{"event_type":"rocksdb_build"}' https://github.com/api/repos/nethermindeth/nethermind/dispatches

7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,13 @@ $RECYCLE.BIN/
# SASS Compiler cache
.sass-cache

# Rider
.idea/

# Visual Studio 2014 CTP
**/*.sln.ide
.vs/

amd64/rocksdb.dll
native/**/*.dll
native/
native*/
*.xz
*.zip
*.userprefs
Expand Down
77 changes: 42 additions & 35 deletions RocksDbNative/RocksDbNative.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Versions.targets.include"/>
<Import Project="..\Versions.targets.include" />
<PropertyGroup>
<Title>RocksDbNative</Title>
<TargetFrameworks>netstandard1.6;net40;net45</TargetFrameworks>
<Version>$(RocksDbVersion).$(RocksDbNativeBuild)</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
Expand All @@ -18,51 +17,59 @@
<Copyright>Copyright 2016</Copyright>
<PackageReleaseNotes>Native RocksDb Binaries (Install RocksDbSharp package for managed wraper)</PackageReleaseNotes>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<!-- "DispatchToInnerBuilds" will cause this to run in the outer build (i.e. once regardless of number of frameworks) -->
<!-- Condition="!Exists('rocksdb-$(RocksDbVersion)\runtimes\win-x64\native\rocksdb.dll') and !Exists('$(BaseIntermediateOutputPath)\rocksdb-v$(RocksDbVersion)-win-x64.zip')" -->
<Target Name="DownloadNativeLibs" BeforeTargets="DispatchToInnerBuilds">
<!-- Here we download the native libraries from the rocksdb-sharp-native project releases according to the version number, if they don't exist -->
<DownloadFile
Condition="!Exists('$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(NativeLib.RuntimeId)\native\%(NativeLib.Lib)') And !Exists('$(BaseIntermediateOutputPath)rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip')"
SourceUrl="https://github.com/warrenfalk/rocksdb-sharp-native/releases/download/v$(RocksDbVersion)/rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip"
DestinationFolder="$(BaseIntermediateOutputPath)">
</DownloadFile>
<Unzip
Condition="Exists('$(BaseIntermediateOutputPath)rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip') And !Exists('$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(NativeLib.RuntimeId)\native\%(NativeLib.Lib)')"
SourceFiles="$(BaseIntermediateOutputPath)rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip"
DestinationFolder="$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(NativeLib.RuntimeId)\native\">
</Unzip>
</Target>
<!--<Target Name="DownloadNativeLibs" BeforeTargets="DispatchToInnerBuilds">-->
<!--&lt;!&ndash; Here we download the native libraries from the rocksdb-sharp-native project releases according to the version number, if they don't exist &ndash;&gt;-->
<!--<DownloadFile Condition="!Exists('$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(NativeLib.RuntimeId)\native\%(NativeLib.Lib)') And !Exists('$(BaseIntermediateOutputPath)rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip')" SourceUrl="https://github.com/warrenfalk/rocksdb-sharp-native/releases/download/v$(RocksDbVersion)/rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip" DestinationFolder="$(BaseIntermediateOutputPath)">-->
<!--</DownloadFile>-->
<!--<Unzip Condition="Exists('$(BaseIntermediateOutputPath)rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip') And !Exists('$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(NativeLib.RuntimeId)\native\%(NativeLib.Lib)')" SourceFiles="$(BaseIntermediateOutputPath)rocksdb-v$(RocksDbVersion)-%(NativeLib.RuntimeId).zip" DestinationFolder="$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(NativeLib.RuntimeId)\native\">-->
<!--</Unzip>-->
<!--</Target>-->
<ItemGroup>
<!-- Define the native libraries here -->
<!-- The "Include" attribute is a required attribute in ItemGroups outside of Targets, but I don't know why -->
<NativeLib Include="%(RuntimeId)-%(Lib)" RuntimeId="win-x64" Lib="rocksdb.dll" />
<NativeLib Include="%(RuntimeId)-%(Lib)" RuntimeId="linux-x64" Lib="librocksdb.so" />
<NativeLib Include="%(RuntimeId)-%(Lib)" RuntimeId="osx-x64" Lib="librocksdb.dylib" />
<!--<NativeLib Include="win-x64-rocksdb.dll" RuntimeId="win-x64" Lib="rocksdb.dll" />-->
<!--<NativeLib Include="linux-x64-librocksdb.so" RuntimeId="linux-x64" Lib="librocksdb.so" />-->
<!--<NativeLib Include="osx-x64-librocksdb.dylib" RuntimeId="osx-x64" Lib="librocksdb.dylib" />-->

<!--<Content Include="@(NativeLib -> '.\runtimes\%(RuntimeId)\native\%(Lib)')">-->
<!--<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>-->
<!--</Content>-->
<!-- This "Content" is applied for all "NativeLib" and ensures that it is packaged into the correct folder -->
<!-- This also will cause it to be copied to the output directory, which was so far the only way to get it
to work correctly when referenced using a ProjectReference. When packaged as a nupkg and referenced
with PackageReference, then these go to the runtimes folders in the nuget cache, which is enough for
with PackageReference, then these go to the runtimes folders in the nuget cache, which is enough for
standard consumers, but framework consumers get them copied from the nuget cache to the output via
the .targets files for those frameworks.-->
<Content
Include="@(NativeLib -> '$(BaseIntermediateOutputPath)rocksdb-$(RocksDbVersion)\runtimes\%(RuntimeId)\native\%(Lib)')"
PackagePath="runtimes\%(RuntimeId)\native\%(Lib)"
Link="runtimes\%(RuntimeId)\native\%(Lib)">
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!-- These target files take care of copying from the nuget cache area into the output folder as required
<Compile Remove="build\**" />
<EmbeddedResource Remove="build\**" />
<!-- These target files take care of copying from the nuget cache area into the output folder as required
by the .Net Framework frameworks -->
<None Remove="build\**" />
<None Include="build\net40\RocksDbNative.targets">
<Pack>true</Pack>
<PackagePath>build/net40</PackagePath>
</None>
<None Include="build\net45\RocksDbNative.targets">
<Pack>true</Pack>
<PackagePath>build/net45</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="runtimes\linux-arm64\native\librocksdb.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\linux-arm\native\librocksdb.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\linux-x64\native\librocksdb.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\osx-x64\native\librocksdb.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\osx-arm64\native\librocksdb.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="runtimes\win-x64\native\rocksdb.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
20 changes: 0 additions & 20 deletions RocksDbNative/build/net40/RocksDbNative.targets

This file was deleted.

20 changes: 0 additions & 20 deletions RocksDbNative/build/net45/RocksDbNative.targets

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added RocksDbNative/runtimes/win-x64/native/rocksdb.dll
Binary file not shown.
42 changes: 31 additions & 11 deletions RocksDbSharp/AutoNativeImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static string GetArchName(Architecture arch)
case Architecture.X86:
return "i386";
case Architecture.X64:
return "amd64";
return "x64";
default:
return arch.ToString().ToLower();
}
Expand Down Expand Up @@ -368,6 +368,20 @@ public static T Import<T>(INativeLibImporter importer, string libName, string ve
"",
};

HashSet<string> basePaths = new();
void TryAddBasePath(string path)
{
if (path is not null)
{
try { basePaths.Add(path); }
catch
{
/* Ignore */
}
}
}


// If the RocksDbNative package is referenced, then dynamically load it here so that it can tell us where the native libraries are
string nativeCodeBase = null;
try
Expand All @@ -379,18 +393,24 @@ public static T Import<T>(INativeLibImporter importer, string libName, string ve
var getCodeBase = getCodeBaseMethod.CreateDelegate<Func<string>>();
nativeCodeBase = getCodeBase();
}
catch (Exception)
catch { /* Ignore */ }

//Some paths might throw NotSupportedException when used from single file deployment. We could test for that, but we can also just ignore it
TryAddBasePath(nativeCodeBase);
TryAddBasePath(Directory.GetCurrentDirectory());
TryAddBasePath(Path.GetDirectoryName(UriToPath(AppContext.BaseDirectory)));
TryAddBasePath(Path.GetDirectoryName(UriToPath(Transitional.CurrentFramework.GetBaseDirectory())));
TryAddBasePath(Path.GetDirectoryName(UriToPath(Assembly.GetEntryAssembly()?.Location)));
TryAddBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location));
TryAddBasePath(Path.GetDirectoryName(UriToPath(typeof(PosixImporter).GetTypeInfo().Assembly.Location)));
TryAddBasePath(Path.GetDirectoryName(typeof(PosixImporter).GetTypeInfo().Assembly.Location));

// for Apple ARM64 - M1
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
}
TryAddBasePath("/opt/homebrew/lib");
}

var basePaths = new string[] {
nativeCodeBase,
Path.GetDirectoryName(UriToPath(Transitional.CurrentFramework.GetBaseDirectory())),
Path.GetDirectoryName(UriToPath(Assembly.GetEntryAssembly()?.CodeBase)),
Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location),
Path.GetDirectoryName(UriToPath(typeof(PosixImporter).GetTypeInfo().Assembly.CodeBase)),
Path.GetDirectoryName(typeof(PosixImporter).GetTypeInfo().Assembly.Location),
};
var search = basePaths
.Where(p => p != null)
.Distinct()
Expand Down
2 changes: 1 addition & 1 deletion RocksDbSharp/Native.Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static Native()
{
if (RuntimeInformation.ProcessArchitecture == Architecture.X86 && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
throw new RocksDbSharpException("Rocksdb on windows is not supported for 32 bit applications");
Instance = NativeImport.Auto.Import<Native>("rocksdb", "6.2.2", true);
Instance = NativeImport.Auto.Import<Native>("rocksdb", "6.4.6", true);
}

public Native()
Expand Down
35 changes: 33 additions & 2 deletions RocksDbSharp/Native.Marshaled.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
/*
The functions in this file provide some wrappers around the lowest level C API to aid in marshalling.
This is kept separate so that the lowest level imports can be kept as close as possible to c.h from rocksdb.
See Native.Raw.cs for more information.
*/
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Transitional;
Expand Down Expand Up @@ -155,7 +156,37 @@ public byte[] rocksdb_get(
rocksdb_free(resultPtr);
return result;
}


public unsafe Span<byte> rocksdb_get_span(
IntPtr db,
IntPtr read_options,
byte[] key,
long keyLength,
out IntPtr errptr,
ColumnFamilyHandle cf = null)
{
UIntPtr skLength = (UIntPtr)keyLength;
var resultPtr = cf == null
? rocksdb_get(db, read_options, key, skLength, out UIntPtr valueLength, out errptr)
: rocksdb_get_cf(db, read_options, cf.Handle, key, skLength, out valueLength, out errptr);
if (errptr != IntPtr.Zero)
return null;
if (resultPtr == IntPtr.Zero)
return null;
Span<byte> span = new Span<byte>((void*)resultPtr, (int)valueLength);
//MemoryMarshal.GetReference(span);


return span;
}

public unsafe void rocksdb_release_span(in Span<byte> span)
{
ref byte ptr = ref MemoryMarshal.GetReference(span);
IntPtr intPtr = new IntPtr(Unsafe.AsPointer(ref ptr));
rocksdb_free(intPtr);
}

/// <summary>
/// Executes a multi_get with automatic marshalling
/// </summary>
Expand Down
33 changes: 33 additions & 0 deletions RocksDbSharp/Native.Wrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ public void rocksdb_put(
if (errptr != IntPtr.Zero)
throw new RocksDbException(errptr);
}

public unsafe void rocksdb_put(
IntPtr db,
IntPtr writeOptions,
byte* key,
long keyLength,
byte* value,
long valueLength,
ColumnFamilyHandle cf)
{
IntPtr errptr;
UIntPtr sklength = (UIntPtr)keyLength;
UIntPtr svlength = (UIntPtr)valueLength;
if (cf == null)
rocksdb_put(db, writeOptions, key, sklength, value, svlength, out errptr);
else
rocksdb_put_cf(db, writeOptions, cf.Handle, key, sklength, value, svlength, out errptr);
if (errptr != IntPtr.Zero)
throw new RocksDbException(errptr);
}


public string rocksdb_get(
Expand Down Expand Up @@ -89,6 +109,19 @@ public byte[] rocksdb_get(
throw new RocksDbException(errptr);
return result;
}

public Span<byte> rocksdb_get_span(
IntPtr db,
IntPtr read_options,
byte[] key,
long keyLength = 0,
ColumnFamilyHandle cf = null)
{
var result = rocksdb_get_span(db, read_options, key, keyLength == 0 ? key.Length : keyLength, out IntPtr errptr, cf);
if (errptr != IntPtr.Zero)
throw new RocksDbException(errptr);
return result;
}

public System.Collections.Generic.KeyValuePair<string, string>[] rocksdb_multi_get(
IntPtr db,
Expand Down
Loading