1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Update packaging for .NET Core

This commit is contained in:
ektrah 2019-12-29 20:43:54 +01:00
parent 896b0e254d
commit 76289a2db1
14 changed files with 7 additions and 437 deletions

View File

@ -1,5 +0,0 @@
build
cache
temp
Makefile
!recipes/*

View File

@ -1,59 +0,0 @@
This directory contains scripts and files to package libsodium for .NET Core.
*Note:* The NuGet package is intended for the implementation of language
bindings such as [NSec](https://github.com/ektrah/nsec). It does not provide a
.NET API itself.
In .NET Core, it is customary to provide pre-compiled binaries for all platforms
as NuGet packages. The purpose of the `prepare.py` script in this directory is
to generate a `Makefile` that downloads and builds libsodium binaries for a
number of platforms and assembles them in a NuGet package that can be uploaded
to [nuget.org](https://nuget.org/).
* For Windows, binaries are obtained from
[download.libsodium.org](https://download.libsodium.org/libsodium/releases/).
* For macOS, binaries are extracted from the
[Homebrew libsodium bottle](https://bintray.com/homebrew/bottles/libsodium).
* For Linux, libsodium is compiled in Docker containers.
See `prepare.py` for the complete list of supported platforms.
The metadata for the NuGet package is located in `libsodium.props`.
**Versioning**
Version numbers for the packages for .NET Core consist of three components:
* *libsodium version*
The libsodium version is in the format `X.Y.Z`.
* *package revision*
It may be necessary to release more than one package for a libsodium version,
e.g., when adding support for a new platform or if a release contains a broken
binary. In this case, a package revision number is added as a fourth part to
the libsodium version, starting at `1`. For example, `1.0.18` is the initial
release of the package for libsodium 1.0.18 and `1.0.18.5` is the fifth
revision (sixth release) of that package.
* *pre-release label*
If a package is a pre-release, a label is appended to the version number in
`-preview-##` format where `##` is the number of the pre-release, starting at
`01`. For example, `1.0.18-preview-01` is the first pre-release of the package
for libsodium 1.0.18 and `1.0.18.5-preview-02` the second pre-release of the
fifth revision of the package for libsodium 1.0.18.
**Making a release**
1. Update any existing Docker images.
2. Run `python3 prepare.py <version>` to generate the `Makefile`, where
`<version>` is the package version number in the format described above.
3. Take a look at the generated `Makefile`. It uses `sudo` a few times.
4. Run `make` to download and build the binaries and create the NuGet package.
You may need to install `docker`, `make`, `curl`, `tar` and `unzip` first.
5. Grab a cup of coffee. Downloading the Docker images and compiling the Linux
binaries takes a while. When done, the NuGet package is output as a `.nupkg`
file in the `build` directory.
6. Run `make test` to perform a quick test of the NuGet package. Verify that
everything else in the `.nupkg` file is in place.
7. Publish the release by uploading the `.nupkg` file to
[nuget.org](https://nuget.org/).

View File

@ -1,24 +1,25 @@
<?xml version="1.0"?>
<Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<PackageOutputPath>$(MSBuildProjectDirectory)</PackageOutputPath>
<ProjectFileToPack>$(MSBuildProjectFullPath)</ProjectFileToPack>
</PropertyGroup>
<PropertyGroup>
<PackageId>libsodium</PackageId>
<Version><!-- set by prepare.py --></Version>
<Version>1.0.18</Version>
<Authors>Frank Denis</Authors>
<Description>Internal implementation package not meant for direct consumption. Please do not reference directly.</Description>
<Copyright>&#169; 2013-2019 Frank Denis</Copyright>
<Copyright>&#169; $([System.DateTime]::UtcNow.ToString(yyyy)) Frank Denis</Copyright>
<PackageLicenseExpression>ISC</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://raw.githubusercontent.com/jedisct1/libsodium/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://libsodium.org/</PackageProjectUrl>
<RepositoryUrl>https://github.com/jedisct1/libsodium.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<MinClientVersion>4.0</MinClientVersion>
</PropertyGroup>

View File

@ -1,302 +0,0 @@
#!/usr/bin/env python3
import os.path
import re
import sys
WINDOWS = [
# --------------------- ----------------- #
# Runtime ID Platform #
# --------------------- ----------------- #
("win-x64", "x64"),
("win-x86", "Win32"),
# --------------------- ----------------- #
]
MACOS = [
# --------------------- ----------------- #
# Runtime ID Codename #
# --------------------- ----------------- #
("osx-x64", "mojave"),
# --------------------- ----------------- #
]
LINUX = [
# --------------------- ----------------- #
# Runtime ID Docker Image #
# --------------------- ----------------- #
("linux-x64", "debian:stretch"),
# --------------------- ----------------- #
]
EXTRAS = ["LICENSE", "AUTHORS", "ChangeLog"]
PROPSFILE = "libsodium.props"
MAKEFILE = "Makefile"
BUILDDIR = "build"
CACHEDIR = "cache"
TEMPDIR = "temp"
PACKAGE = "libsodium"
LIBRARY = "libsodium"
DOCKER = "sudo docker"
class Version:
def __init__(self, libsodium_version, package_version):
self.libsodium_version = libsodium_version
self.package_version = package_version
self.builddir = os.path.join(BUILDDIR, libsodium_version)
self.tempdir = os.path.join(TEMPDIR, libsodium_version)
self.projfile = os.path.join(
self.builddir, "{0}.{1}.pkgproj".format(PACKAGE, package_version)
)
self.propsfile = os.path.join(self.builddir, "{0}.props".format(PACKAGE))
self.pkgfile = os.path.join(
BUILDDIR, "{0}.{1}.nupkg".format(PACKAGE, package_version)
)
class WindowsItem:
def __init__(self, version, rid, platform):
self.url = "https://download.libsodium.org/libsodium/releases/libsodium-{0}-stable-msvc.zip".format(
version.libsodium_version
)
self.cachefile = os.path.join(CACHEDIR, re.sub(r"[^A-Za-z0-9.]", "-", self.url))
self.packfile = os.path.join(
version.builddir, "runtimes", rid, "native", LIBRARY + ".dll"
)
self.itemfile = "{0}/Release/v140/dynamic/libsodium.dll".format(platform)
self.tempdir = os.path.join(version.tempdir, rid)
self.tempfile = os.path.join(self.tempdir, os.path.normpath(self.itemfile))
def make(self, f):
f.write("\n")
f.write("{0}: {1}\n".format(self.packfile, self.tempfile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write("\tcp -f $< $@\n")
f.write("\n")
f.write("{0}: {1}\n".format(self.tempfile, self.cachefile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write(
"\tcd {0} && unzip -q -DD -o {1} '{2}'\n".format(
self.tempdir,
os.path.relpath(self.cachefile, self.tempdir),
self.itemfile,
)
)
class MacOSItem:
def __init__(self, version, rid, codename):
self.url = "https://bintray.com/homebrew/bottles/download_file?file_path=libsodium-{0}.{1}.bottle.tar.gz".format(
version.libsodium_version, codename
)
self.cachefile = os.path.join(CACHEDIR, re.sub(r"[^A-Za-z0-9.]", "-", self.url))
self.packfile = os.path.join(
version.builddir, "runtimes", rid, "native", LIBRARY + ".dylib"
)
self.itemfile = "libsodium/{0}/lib/libsodium.dylib".format(
version.libsodium_version
)
self.tempdir = os.path.join(version.tempdir, rid)
self.tempfile = os.path.join(self.tempdir, os.path.normpath(self.itemfile))
def make(self, f):
f.write("\n")
f.write("{0}: {1}\n".format(self.packfile, self.tempfile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write("\tcp -f $< $@\n")
f.write("\n")
f.write("{0}: {1}\n".format(self.tempfile, self.cachefile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write(
"\tcd {0} && tar xzmf {1} '{2}'\n".format(
self.tempdir,
os.path.relpath(self.cachefile, self.tempdir),
os.path.dirname(self.itemfile),
)
)
class LinuxItem:
def __init__(self, version, rid, docker_image):
self.url = "https://download.libsodium.org/libsodium/releases/libsodium-{0}.tar.gz".format(
version.libsodium_version
)
self.cachefile = os.path.join(CACHEDIR, re.sub(r"[^A-Za-z0-9.]", "-", self.url))
self.packfile = os.path.join(
version.builddir, "runtimes", rid, "native", LIBRARY + ".so"
)
self.tempdir = os.path.join(version.tempdir, rid)
self.tempfile = os.path.join(self.tempdir, "libsodium.so")
self.docker_image = docker_image
self.recipe = rid
def make(self, f):
recipe = self.recipe
while not os.path.exists(os.path.join("recipes", recipe)):
m = re.fullmatch(r"([^.-]+)((([.][^.-]+)*)[.][^.-]+)?([-].*)?", recipe)
if m.group(5) is None:
recipe = "build"
break
elif m.group(2) is None:
recipe = m.group(1)
else:
recipe = m.group(1) + m.group(3) + m.group(5)
f.write("\n")
f.write("{0}: {1}\n".format(self.packfile, self.tempfile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write("\tcp -f $< $@\n")
f.write("\n")
f.write("{0}: {1}\n".format(self.tempfile, self.cachefile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write(
"\t{0} run --rm ".format(DOCKER)
+ "-v $(abspath recipes):/io/recipes "
+ "-v $(abspath $<):/io/libsodium.tar.gz "
+ "-v $(abspath $(dir $@)):/io/output "
+ "{0} sh -x -e /io/recipes/{1}\n".format(self.docker_image, recipe)
)
class ExtraItem:
def __init__(self, version, filename):
self.url = "https://download.libsodium.org/libsodium/releases/libsodium-{0}.tar.gz".format(
version.libsodium_version
)
self.cachefile = os.path.join(CACHEDIR, re.sub(r"[^A-Za-z0-9.]", "-", self.url))
self.packfile = os.path.join(version.builddir, filename)
self.itemfile = "libsodium-{0}/{1}".format(version.libsodium_version, filename)
self.tempdir = os.path.join(version.tempdir, "extras")
self.tempfile = os.path.join(self.tempdir, os.path.normpath(self.itemfile))
def make(self, f):
f.write("\n")
f.write("{0}: {1}\n".format(self.packfile, self.tempfile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write("\tcp -f $< $@\n")
f.write("\n")
f.write("{0}: {1}\n".format(self.tempfile, self.cachefile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write(
"\tcd {0} && tar xzmf {1} '{2}'\n".format(
self.tempdir,
os.path.relpath(self.cachefile, self.tempdir),
self.itemfile,
)
)
def main(args):
m = (
re.fullmatch(r"((\d+\.\d+\.\d+)(\.\d+)?)(?:-(\w+(?:[_.-]\w+)*))?", args[1])
if len(args) == 2
else None
)
if m is None:
print("Usage:")
print(" python3 prepare.py <version>")
print()
print("Examples:")
print(" python3 prepare.py 1.0.18-preview-01")
print(" python3 prepare.py 1.0.18-preview-02")
print(" python3 prepare.py 1.0.18-preview-03")
print(" python3 prepare.py 1.0.18")
print(" python3 prepare.py 1.0.18.1-preview-01")
print(" python3 prepare.py 1.0.18.1")
print(" python3 prepare.py 1.0.18.2")
return 1
version = Version(m.group(2), m.group(0))
items = (
[WindowsItem(version, rid, platform) for (rid, platform) in WINDOWS]
+ [MacOSItem(version, rid, codename) for (rid, codename) in MACOS]
+ [LinuxItem(version, rid, docker_image) for (rid, docker_image) in LINUX]
+ [ExtraItem(version, filename) for filename in EXTRAS]
)
downloads = {item.cachefile: item.url for item in items}
with open(MAKEFILE, "w") as f:
f.write("all: {0}\n".format(version.pkgfile))
for download in sorted(downloads):
f.write("\n")
f.write("{0}:\n".format(download))
f.write("\t@mkdir -p $(dir $@)\n")
f.write("\tcurl -f#Lo $@ '{0}'\n".format(downloads[download]))
for item in items:
item.make(f)
f.write("\n")
f.write("{0}: {1}\n".format(version.propsfile, PROPSFILE))
f.write("\t@mkdir -p $(dir $@)\n")
f.write("\tcp -f $< $@\n")
f.write("\n")
f.write("{0}: {1}\n".format(version.projfile, version.propsfile))
f.write("\t@mkdir -p $(dir $@)\n")
f.write(
"\techo '"
+ '<Project Sdk="Microsoft.NET.Sdk">'
+ '<Import Project="{0}" />'.format(
os.path.relpath(version.propsfile, os.path.dirname(version.projfile))
)
+ "<PropertyGroup>"
+ "<Version>{0}</Version>".format(version.package_version)
+ "</PropertyGroup>"
+ "</Project>' > $@\n"
)
f.write("\n")
f.write("{0}:".format(version.pkgfile))
f.write(" \\\n\t\t{0}".format(version.projfile))
f.write(" \\\n\t\t{0}".format(version.propsfile))
for item in items:
f.write(" \\\n\t\t{0}".format(item.packfile))
f.write("\n")
f.write("\t@mkdir -p $(dir $@)\n")
f.write(
"\t{0} run --rm ".format(DOCKER)
+ "-v $(abspath recipes):/io/recipes "
+ "-v $(abspath $(dir $<)):/io/input "
+ "-v $(abspath $(dir $@)):/io/output "
+ "{0} sh -x -e /io/recipes/{1} {2}\n".format(
"microsoft/dotnet:2.0-sdk",
"pack",
os.path.relpath(version.projfile, version.builddir),
)
)
f.write("\n")
f.write("test: {0}\n".format(version.pkgfile))
f.write(
"\t{0} run --rm ".format(DOCKER)
+ "-v $(abspath recipes):/io/recipes "
+ "-v $(abspath $(dir $<)):/io/packages "
+ '{0} sh -x -e /io/recipes/{1} "{2}"\n'.format(
"microsoft/dotnet:2.0-sdk", "test", version.package_version
)
)
print(
"prepared",
MAKEFILE,
"to make",
version.pkgfile,
"for libsodium",
version.libsodium_version,
)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))

View File

@ -1,3 +0,0 @@
apk add --update alpine-sdk
. $(dirname $0)/build

View File

@ -1,9 +0,0 @@
cd ~
tar xzf /io/libsodium.tar.gz
cd libsodium-*
./configure
make
make check
make install
strip --strip-all /usr/local/lib/libsodium.so
cp /usr/local/lib/libsodium.so /io/output

View File

@ -1,3 +0,0 @@
yum install -y binutils gcc make tar
. $(dirname $0)/build

View File

@ -1,4 +0,0 @@
apt-get update
apt-get install -y --no-install-recommends build-essential
. $(dirname $0)/build

View File

@ -1,3 +0,0 @@
dnf install -y binutils gcc make tar
. $(dirname $0)/build

View File

@ -1,4 +0,0 @@
apt-get update
apt-get install -y --no-install-recommends build-essential
. $(dirname $0)/build

View File

@ -1,3 +0,0 @@
zypper install -y --no-recommends -n binutils gcc make tar
. $(dirname $0)/build

View File

@ -1,5 +0,0 @@
cp -r /io/input ~/build
cd ~/build
dotnet restore $1
dotnet pack $1
cp *.nupkg /io/output

View File

@ -1,27 +0,0 @@
TEST_PROGRAM='using System;
using System.Runtime.InteropServices;
static class Program
{
[DllImport("libsodium")]
static extern int sodium_init();
static int Main()
{
int error = sodium_init();
Console.WriteLine(error == 0
? "ok"
: "error: sodium_init() returned {0}", error);
return error == 0 ? 0 : 1;
}
}
'
dotnet --info
cd ~
dotnet new console --name Test
cd Test
echo "$TEST_PROGRAM" > Program.cs
dotnet add package libsodium --version $1 --source /io/packages
dotnet restore
dotnet run

View File

@ -1,4 +0,0 @@
apt-get update
apt-get install -y --no-install-recommends build-essential
. $(dirname $0)/build