Mizux / dotnet-native

Template to build a multi-platforms Native Net 6.0 Nuget package using dotnet cli
Apache License 2.0
86 stars 16 forks source link

How to change name of library #8

Closed JensMunkHansen closed 9 months ago

JensMunkHansen commented 9 months ago

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.

jensmunkhansen3shape commented 9 months ago

I figured it out, I encountered some weird renaming of the .so's.

Mizux commented 9 months ago

few points:

  1. Most name are derived from the CMake Project name or from DOTNET_PACKAGE https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/CMakeLists.txt#L13 https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/cmake/dotnet.cmake#L22-L23 https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/cmake/dotnet.cmake#L45 https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/cmake/dotnet.cmake#L94

  2. Assembly name for meta package is templated https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/dotnet/Mizux.DotnetNative.csproj.in#L8 https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/dotnet/Mizux.DotnetNative.csproj.in#L16

  3. good point some assembly name for the runtime package are note "templated" https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/dotnet/Mizux.DotnetNative.runtime.csproj.in#L6 https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/dotnet/Mizux.DotnetNative.runtime.csproj.in#L15 note: this name is also use by SWIG when generating its wrapper: https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/Foo/dotnet/CMakeLists.txt#L4 So I should specify it in dotnet.cmake than passe it/use it here and there

On my way to make it more generic, the goal is for anyone to be able to change one or two name then everything just work

  1. No you can use a local directory, no need to "deploy" to nuget that the point to hack RestoreSources to use local directory note: this is how work the docker ci copy the built nupkg https://github.com/Mizux/dotnet-native/blob/c2cd57ef86cc158f47373f2c47eb96333e4e3d1b/ci/docker/archlinux/Dockerfile#L32 then Sample,csproj will use it, even if this docker stage don't have the source/build dir of the dotnet-native project... https://github.com/Mizux/dotnet-native/blob/main/ci/samples/Mizux.Sample.csproj#L39

Hope you'll better understand how it works... On my way to reduce the Misux/DotnetNative string to 1 occurence if possible...

jensmunkhansen3shape commented 9 months ago

Thank you so much. I got it to work without hanging for connecting to nuget.org, also went through a bunch of renaming, but I got a little stuck when I encountered .so's being named DotNetNative and not dotnotnative, but that was due to NuGet being pulled from my local repo. I started out from scratch with cherry-picking and slowly found out why I need the different parts. A little easier to interate on a smaller problem. But, really nice that somebody is sharing an elegant use SWIG and C#. Used SWIG for almost two decades, but never with C#.

Mizux commented 9 months ago

dotnet nuget locals all --clear and cleaning ~/.dotnet/packs/ when testing is a life saver ;)

jensmunkhansen3shape commented 9 months ago

Not in any way a fan Microsoft, but in my current job it is a necessary evil. CMake, SWIG and other tooling can make life easier.

Mizux commented 9 months ago

https://github.com/Mizux/dotnet-native/blob/bd8b83f3e6fe5610bd6b52bfaac6a992e5230cd8/CMakeLists.txt#L13-L14 note: project(Name will generate the PROJECT_NAME... see: https://cmake.org/cmake/help/latest/command/project.html

Then generate the native library name from both variables... https://github.com/Mizux/dotnet-native/blob/bd8b83f3e6fe5610bd6b52bfaac6a992e5230cd8/cmake/dotnet.cmake#L99

JensMunkHansen commented 9 months ago

You could consider renaming Mizux.DotnetNative.csproj to CompanyName.DotnetNative.csproj, if not you will get into some trouble.

JensMunkHansen commented 9 months ago

CompanyName.ProjectName of course and with/without runtime. The runtime in the test libraries, you have updated...