Skip to content

Commit

Permalink
native libraries load improvements (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid authored Nov 10, 2022
1 parent 4385474 commit a4fd3be
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
38 changes: 33 additions & 5 deletions .github/workflows/full.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Full Flow'

env:
VERSION: 1.2.2
VERSION: 1.2.3
#PACKAGE_SUFFIX: '-preview-03'
PACKAGE_SUFFIX: ''
ASM_VERSION: 1.0.0
Expand Down Expand Up @@ -70,23 +70,40 @@ jobs:
echo "VCPKG_TRIPLET=${{ matrix.arch }}-osx" >> $GITHUB_ENV
echo "VCPKG_CONFIG=RelWithDebInfo" >> $GITHUB_ENV
- name: Windows x86
- name: Windows x64
if: runner.os == 'Windows' && matrix.arch == 'x64'
run: |
echo "DOTNET_RID=win-x64" >> $env:GITHUB_ENV
- name: Windows x32
if: runner.os == 'Windows' && matrix.arch == 'x86'
run: |
echo "DOTNET_RID=win-x32" >> $env:GITHUB_ENV
echo "VCPKG_OPTIONS=-D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 -D LINK_FLAGS=-m32" >> $env:GITHUB_ENV
- name: Linux x64
if: runner.os == 'Linux' && matrix.arch == 'x64'
run: |
echo "DOTNET_RID=linux-x64" >> $GITHUB_ENV
- name: Linux ARM x64
- name: Linux ARM
if: runner.os == 'Linux' && matrix.arch == 'arm64'
run: |
sudo apt-get update
sudo apt-get --yes install g++-aarch64-linux-gnu pkg-config-aarch64-linux-gnu
echo "VCPKG_OPTIONS=-D CMAKE_SYSTEM_PROCESSOR=aarch64 -D CMAKE_C_COMPILER=$(which aarch64-linux-gnu-gcc) -D CMAKE_CXX_COMPILER=$(which aarch64-linux-gnu-g++)" >> $GITHUB_ENV
echo "DOTNET_RID=linux-arm64" >> $GITHUB_ENV
- name: MacOS M1
- name: OSX x64
if: runner.os == 'macOS' && matrix.arch == 'x64'
run: |
echo "DOTNET_RID=osx-x64" >> $GITHUB_ENV
- name: OSX M1
if: runner.os == 'macOS' && matrix.arch == 'arm64'
run: |
echo "VCPKG_OPTIONS=-D CMAKE_OSX_ARCHITECTURES=arm64" >> $GITHUB_ENV
echo "DOTNET_RID=osx-arm64" >> $GITHUB_ENV
- uses: friendlyanon/setup-vcpkg@v1
# seems like the absense of commit hash expects vcpkg submodule, i don't want that
Expand Down Expand Up @@ -123,6 +140,10 @@ jobs:
fail-fast: false
name: 'test: ${{ matrix.os }}'

#env:
# LD_DEBUG: libs
# DYLD_PRINT_LIBRARIES: 1

steps:

- uses: actions/checkout@v3
Expand All @@ -132,7 +153,7 @@ jobs:
name: native
path: native/ubin/

- name: debug
- name: debug1
run: ls -R
working-directory: native

Expand All @@ -143,6 +164,13 @@ jobs:
3.1.x
6.0.x
- name: build
run: dotnet build managed/IronCompress.sln

- name: debug2
run: ls -R
working-directory: .

- name: Test
run: dotnet test managed/IronCompress.sln

Expand Down
15 changes: 9 additions & 6 deletions managed/IronCompress/IronCompress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,29 @@
<PackageReference Include="System.Buffers" Version="4.5.1" />
</ItemGroup>

<!-- native dependencies -->


<!-- native dependencies. https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2022#content -->
<!-- from what I understand, the "Link" attribute is only used for ProjectReference and local development. It has zero effect on generated nuget. -->
<ItemGroup Label="Native">
<!-- Windows -->
<Content Include="..\..\native\ubin\nironcompress-x64.dll" Link="nironcompress.dll" PackagePath="runtimes/win-x64/native">
<Content Include="..\..\native\ubin\runtimes\win-x64\native\nironcompress.dll" Link="nironcompress.dll" PackagePath="runtimes/win-x64/native">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

<!-- Linux -->
<Content Include="..\..\native\ubin\libnironcompress-x64.so" Link="libnironcompress.so" PackagePath="runtimes/linux-x64/native">
<Content Include="..\..\native\ubin\runtimes\linux-x64\native\libnironcompress.so" Link="libnironcompress.so" PackagePath="runtimes/linux-x64/native">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\native\ubin\libnironcompress-arm64.so" Link="libnironcompress-arm64.so" PackagePath="runtimes/linux-arm64/native">
<Content Include="..\..\native\ubin\runtimes\linux-arm64\native\libnironcompress.so" PackagePath="runtimes/linux-arm64/native">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

<!-- Mac -->
<Content Include="..\..\native\ubin\libnironcompress-x64.dylib" Link="libnironcompress.dylib" PackagePath="runtimes/osx-x64/native">
<Content Include="..\..\native\ubin\runtimes\osx-x64\native\libnironcompress.dylib" Link="libnironcompress.dylib" PackagePath="runtimes/osx-x64/native">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\native\ubin\libnironcompress-arm64.dylib" Link="libnironcompress-arm64.dylib" PackagePath="runtimes/osx-arm64/native">
<Content Include="..\..\native\ubin\runtimes\osx-arm64\native\libnironcompress.dylib" PackagePath="runtimes/osx-arm64/native">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down
8 changes: 3 additions & 5 deletions managed/IronCompress/Native.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Runtime.InteropServices;

namespace IronCompress {
static class Native {
const string LibName = "nironcompress";

/*
static Native() {
// lower versions will just have to rely on 64-bit only version, which is the default with no arch suffixes.
Expand Down Expand Up @@ -60,6 +57,7 @@ private static IntPtr DllImportResolver(string libraryName, Assembly assembly, D
return NativeLibrary.Load(nativeName, assembly, searchPath);
}
#endif
*/

[DllImport(LibName)]
internal static extern unsafe bool compress(
Expand Down
2 changes: 1 addition & 1 deletion native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ add_custom_command(
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:nironcompress>
${CMAKE_SOURCE_DIR}/ubin/$<TARGET_FILE_PREFIX:nironcompress>$<TARGET_FILE_BASE_NAME:nironcompress>$ENV{FILE_ARCH}$<TARGET_FILE_SUFFIX:nironcompress>
${CMAKE_SOURCE_DIR}/ubin/runtimes/$ENV{DOTNET_RID}/native/$<TARGET_FILE_NAME:nironcompress>
)

0 comments on commit a4fd3be

Please sign in to comment.