KodrAus / old-csharp-rust

Playground for C#/Rust Interop
16 stars 5 forks source link

Write a tool to turn cargo libs into nuget pkgs #2

Closed KodrAus closed 7 years ago

KodrAus commented 7 years ago

So the little build tool I wrote here turned out pretty well. If I was going to do it properly it would need some thought though. What I think would work well is taking that work and turning it into a tool for packaging Rust libs as .NET nuget packages.

The nuspec info could all be pulled from the cargo.toml, then it's just a question of what platforms to target. For example, the Libuv package has the following nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
    <metadata>
        <id>Libuv</id>
        <version>1.9.0</version>
        <authors>Libuv</authors>
        <owners>Libuv</owners>
        <licenseUrl>https://raw.githubusercontent.com/aspnet/libuv-package/dev/content/License.txt</licenseUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Multi-platform support library with a focus on asynchronous I/O.</description>
        <tags>libuv</tags>
        <dependencies>
            <group targetFramework=".NETStandard1.0">
                <dependency id="Microsoft.NETCore.Platforms" version="1.0.1" />
            </group>
        </dependencies>
    </metadata>
</package>

The actual output just goes in a root runtimes folder:

+ runtimes
 -- debian-x64
 -- osx
 -- win7-x64

This can then be copied into a package directory. I'll keep the other functionality for building, running tests and copying around in case it's still useful.

KodrAus commented 7 years ago

Ok, so the tool should work like this:

dev

Build a package for just the current platform (use the same process, but no additional platforms are available).

Bundle up the one library into a nupkg and copy to some destination (this is expected to be some local nuget cache)

pack

Build a package for the given platforms, expecting the system this is run on is capable of linking everything together.

KodrAus commented 7 years ago

I've started a new repo for this here.