mizux / dotnet-native Goto Github PK
View Code? Open in Web Editor NEWTemplate to build a multi-platforms Native Net 6.0 Nuget package using dotnet cli
License: Apache License 2.0
Template to build a multi-platforms Native Net 6.0 Nuget package using dotnet cli
License: Apache License 2.0
I'm trying to write bindings for a C/C++ library which I don't control. I've included that library, as is, as a submodule in this repo.
I'm trying to adapt this template so that the bindings can be a sibling of the library folder, rather than a child (so it works with a submodule). That is:
this template:
├─ Foo/
│ ├─ CMakeLists.txt
│ ├─ dotnet/
│ │ ├─ CMakeLists.txt
mine:
├─ Foo/
│ ├─ CMakeLists.txt
├─ Foo.dotnet/
│ ├─ CMakeLists.txt
Right now, it's failing because the swig-generated wrapper doesn't have access to the header file.
[build] C:\whisper.dotnet\build\dotnet\NickDarvey.Whisper\Whisper\whisperCSHARP_wrap.cxx(766,10): fatal error C1083: Cannot open include file: 'whisper.cpp/whisper.h': No such file or directory [C:\whisper.dotnet\build\whisper.cpp.dotnet\dotnet_whisper.vcxproj]
When I build this (mizux/dotnet-native) repo with Visual Studio 2022 kit selected it generates a build\Foo\dotnet\dotnet_Foo.vcxproj
which has:
AdditionalIncludeDirectories
<AdditionalIncludeDirectories>C:\dotnet-native\Foo\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
swig.exe
[...]swig.exe -csharp -IC:/dotnet-native -IC:/dotnet-native/dotnet -IC:/dotnet-native/Foo/include -namespace Mizux.DotnetNative.Foo -dllimport mizux-dotnetnative-native -outdir C:/dotnet-native/build/dotnet/Mizux.DotnetNative/Foo -c++ -o C:/dotnet-native/build/dotnet/Mizux.DotnetNative/Foo/fooCSHARP_wrap.cxx C:/dotnet-native/Foo/dotnet/foo.i
When I (attempt) to build my (nickdarvey/whisper.dotnet) it generates a vcxproj which has neither of those. I think that's why I'm getting that error.
Are you able to help me get the location of my header files, ./whisper.cpp
, to appear in AdditionalIncludeDirectories
?
I have a C++ library with NetStandard2.0 wrapper; this library has specialized builds for Windows, Linux and MacOS. I can generate the .Net wrapper and shared library which is specific for each platform only on this platform (i.e. no cross compilation).
note: You can find this example at: https://github.com/Mizux/dotnet
On Linux-x64:
Native.cpp -> Native.so -------+
Native.cpp -> Native.linux.cs -+-> Foo.linux-x64.csproj -> Mizux.Foo.linux-x64.npkg
src: https://github.com/Mizux/dotnet/blob/master/src/Foo.linux-x64/Foo.linux-x64.csproj
On osx-x64:
Native.cpp -> Native.dylib --+
Native.cpp -> Native.osx.cs -+-> Foo.osx-x64.csproj -> Mizux.Foo.osx-x64.npkg
src: https://github.com/Mizux/dotnet/blob/master/src/Foo.osx-x64/Foo.osx-x64.csproj
On win-x64:
Native.cpp -> Native.dll ----+
Native.cpp -> Native.win.cs -+-> Foo.win-x64.csproj -> Mizux.Foo.win-x64.npkg
src: https://github.com/Mizux/dotnet/blob/master/src/Foo.win-x64/Foo.win-x64.csproj
So I can generate native package one each OS for this OS.
Question 1: Does my nuget package layout correct ?
unzip -l package/Mizux.Foo.linux-x64.1.0.0.nupkg
Archive: package/Mizux.Foo.linux-x64.1.0.0.nupkg
Length Date Time Name
--------- ---------- ----- ----
509 2018-08-14 15:47 _rels/.rels
498 2018-08-14 15:47 Mizux.Foo.linux-x64.nuspec
3584 2018-08-14 13:33 runtimes/linux-x64/lib/netstandard2.0/Mizux.Foo.linux-x64.dll # .CS which load the native.so -> should be in the same repository
0 2018-08-09 12:04 runtimes/linux-x64/lib/netstandard2.0/native.so
520 2018-08-14 15:47 [Content_Types].xml
633 2018-08-14 15:47 package/services/metadata/core-properties/d5f8836b446941b1a8eb822b3c4e009c.psmdcp
--------- -------
5744 6 files
So here I put files in runtimes/linux-x64/lib/netstandard2.0
but when building with: dotnet build --runtime win-x64 src/Foo.linux-x64
file are placed in [bin/Debug/]netstandard2.0/linux-x64/*
So do I need to place files in lib/linux-x64/netstandard2.0
instead ?
Then I want to create a meta-package Mizux.Foo containing the three dependencies as PackageReference
(supposing I copy past all generated in a local package folder).
package/Mizux.Foo.linux-x64.nupkg -+
package/Mizux.Foo.osx-x64.nupkg ---+-(PackageReference)> Foo.csproj -> Mizux.Foo.nupkg
package/Mizux.Foo.win-x64.nupkg ---+
src: https://github.com/Mizux/dotnet/blob/master/src/Foo/Foo.csproj
I manage to create the nupkg with the .csproj and Mizux.Foo.nuspec inside the nuget package contains:
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Mizux.Foo.linux-x64" version="1.0.0" exclude="Build,Analyzers" />
<dependency id="Mizux.Foo.osx-x64" version="1.0.0" exclude="Build,Analyzers" />
<dependency id="Mizux.Foo.win-x64" version="1.0.0" exclude="Build,Analyzers" />
</group>
</dependencies>
So far so good ???
I manage to build a FooApp if I use ProjectReference on Foo.csproj and condition on RuntimeIdentifier i.e.
dotnet build --runtime linux-x64 src/FooApp
dotnet src/FooApp/bin/Debug/netcoreapp2.1/linux-x64/Mizux.FooApp.dll
src: https://github.com/Mizux/dotnet/blob/master/src/FooApp/FooApp.csproj
This works but in fact it create a degenerated project where Foo.osx-x64 and Foo.win-x64 are ignored (which is cool when testing locally but not when building the meta-package...)
side note: dotnet run --runtime linux-x64 --project src/FooApp
won't work since RuntimeIdentifier is ignored, so it try to rebuild as pure .Net project and look in bin/debug/netstandard2.0...
So far so good ???
So now I now I want to create a Example
which PackageReference Mizux.Foo package...
dotnet build -r linux-x64 example/Example
Program.cs(8,7): error CS0103: The name 'Foo' does not exist in the current context [/usr/local/google/home/corentinl/work/dotnet/example/Example/Example.csproj]
Build FAILED.
src: https://github.com/Mizux/dotnet/blob/master/example/Example/Example.csproj
Question 2: What's wrong here why example don't see the runtimes dir ?
Question 3: It's seems Foo doesn't expose Foo.*-x64 i.e. transitivity not working, why ?
When trying to run dotnet build
all output .dll are renamed
e.g. dotnet package use AssemblyName:
dotnet-native/cmake/dotnet.cmake
Line 23 in 7ac1c8f
so with any generator but XCode we got dotnet cli generating the command with arg /out:obj/x64/Release/net6.0/Mizux.DotnetNative.dll
but Xcode export the env TARGETNAME=dotnet_package
leading to the dotnet internal build command replaced by /out:obj/x64/Release/net6.0/dotnet_package.dll
This impact build
, pack
, test
and run
command AFAIK
Hi Mizux
I tried to generalize your setup a bit fill out the missing parts of the .csproj.in
packages. Something that I cannot get my head around are:
I removed the NuGet repository to avoid uploading to nuget.org
, such that RestoreSources
only contains a local package dir. Do I need to upload stuff or can I use a local directory?
I can build everything but not execute the C# tests. It insists on naming stuff Mizux
and DotNetNative
but only runtime.
When using the -G "Xcode"
generator, it seems we can't run the samples from CTest.
It seems dotnet didn't succeed to find all its dependencies
A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in '...'.
ref: https://github.com/Mizux/dotnet-native/runs/670363781?check_suite_focus=true
note: When using the default make generator, everything work flawlessly
see: https://github.com/Mizux/dotnet-native/runs/670363803?check_suite_focus=true
Have you tried building it using .NET48. At least on Windows, I get numerous errors about incompatibility on the given platform. The framework is for sure installed. We are still stuck on .NET48
How can I produce runtime packages compatible with .NET Framework?
I tried to change the framework identified netcoreapp3.1 to netstandard2.0 or net461 but I failed to produce working examples.
The reason why I fail to run the examples is that there are no native DLLs copied to the binary space for the example project:
Analysis of the differences:
The nuspec files for the wrapper and native package are the same except for the targetFramework identifier.
Are runtime packages restricted to .NET core and .NET 5.0+ ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.