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

Simplify build of .NET pakages, including Windows/arm64

This commit is contained in:
Frank Denis 2024-04-27 23:28:28 +02:00
parent 4feb28379a
commit ef9ad0c041
4 changed files with 57 additions and 269 deletions

View File

@ -43,7 +43,7 @@ jobs:
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
with:
version: 0.11.0
version: 0.12.0
- name: Autogen
run: ./autogen.sh -s

View File

@ -7,10 +7,10 @@ on:
- next
jobs:
build-windows:
build-windows-msvc:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: buildbase.bat
run: buildbase.bat ..\vs2022\libsodium.sln 17
working-directory: builds/msvc/build/
@ -24,17 +24,26 @@ jobs:
name: build-win-x86
path: bin/Win32/Release/v143/dynamic/libsodium.dll
build-linux-glibc:
build-others:
runs-on: ubuntu-latest
steps:
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
uses: goto-bus-stop/setup-zig@2a9625d550eefc3a9b1a43d342ad655f563f8241
with:
version: 0.11.0
- uses: actions/checkout@v3
- name: build
version: 0.12.0
- uses: actions/checkout@v4
- name: build-win-arm64
run: |
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu.2.17 -Dcpu=sandybridge
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=aarch64-windows; ls -lR zig-out
- uses: actions/upload-artifact@v3
with:
name: build-win-arm64
path: zig-out/lib/libsodium.dll
- name: build-linux-x64
run: |
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu.2.17
- name: tests
run: cd zig-out/bin && ./run.sh
- uses: actions/upload-artifact@v3
@ -42,26 +51,23 @@ jobs:
name: build-linux-x64
path: zig-out/lib/libsodium.so
build-linux-glibc-arm:
runs-on: ubuntu-latest
steps:
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
with:
version: 0.11.0
- name: Set up emulation environment
- name: Set up arm and aarch64 emulation environment
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y build-essential qemu binfmt-support qemu-user-static qemu-system-arm gcc-arm-linux-gnueabihf libc6-armhf-cross
sudo apt-get install -y build-essential qemu binfmt-support qemu-user-static qemu-system-arm gcc-arm-linux-gnueabihf libc6-armhf-cross gcc-aarch64-linux-gnu libc6-arm64-cross
sudo dpkg --add-architecture armhf
sudo update-binfmts --enable qemu-arm
sudo update-binfmts --display
sudo ln -s /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.* /lib
- uses: actions/checkout@v3
- name: build
sudo dpkg --add-architecture arm64
sudo update-binfmts --enable qemu-aarch64
sudo update-binfmts --display
sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.* /lib
- name: build-linux-arm
run: |
zig build -Doptimize=ReleaseFast -Dtarget=arm-linux-gnueabihf.2.23 -Dcpu=baseline
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=arm-linux-gnueabihf.2.23
- name: tests
run: |
cd zig-out/bin && env LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib ./run.sh
@ -70,26 +76,9 @@ jobs:
name: build-linux-arm
path: zig-out/lib/libsodium.so
build-linux-glibc-arm64:
runs-on: ubuntu-latest
steps:
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
with:
version: 0.11.0
- name: Set up emulation environment
- name: build-linux-arm64
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y qemu binfmt-support qemu-user-static qemu-system-arm gcc-aarch64-linux-gnu libc6-arm64-cross
sudo dpkg --add-architecture arm64
sudo update-binfmts --enable qemu-aarch64
sudo update-binfmts --display
sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.* /lib
- uses: actions/checkout@v3
- name: build
run: |
zig build -Doptimize=ReleaseFast -Dtarget=aarch64-linux-gnu.2.23 -Dcpu=baseline
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=aarch64-linux-gnu.2.23
- name: tests
run: |
cd zig-out/bin && env LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib ./run.sh
@ -98,67 +87,34 @@ jobs:
name: build-linux-arm64
path: zig-out/lib/libsodium.so
build-linux-musl:
runs-on: ubuntu-latest
container:
image: alpine:3.13
steps:
- name: Set up build environment
- name: build-linux-musl-x64
run: |
apk update
apk add alpine-sdk ca-certificates xz
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
with:
version: 0.11.0
- uses: actions/checkout@v3
- name: build
run: |
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux-musl -Dcpu=sandybridge
- name: tests
run: |
cd zig-out/bin && ./run.sh
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux-musl
- uses: actions/upload-artifact@v3
with:
name: build-linux-musl-x64
path: zig-out/lib/libsodium.so
path: zig-out/lib/libsodium.a
build-linux-musl-arm:
runs-on: ubuntu-latest
steps:
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
with:
version: 0.11.0
- uses: actions/checkout@v3
- name: build
- name: build-linux-musl-arm
run: |
zig build -Doptimize=ReleaseFast -Dtarget=arm-linux-musleabihf -Dcpu=baseline
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=arm-linux-musleabihf
- uses: actions/upload-artifact@v3
with:
name: build-linux-musl-arm
path: zig-out/lib/libsodium.so
path: zig-out/lib/libsodium.a
build-linux-musl-arm64:
runs-on: ubuntu-latest
steps:
- name: Install Zig
uses: goto-bus-stop/setup-zig@d866436887ad1b24590684f9d00480376663dd36
with:
version: 0.11.0
- uses: actions/checkout@v3
- name: build
- name: build-linux-musl-arm64
run: |
zig build -Doptimize=ReleaseFast -Dtarget=aarch64-linux-musl -Dcpu=baseline
rm -fr zig-out zig-cache; zig build -Doptimize=ReleaseFast -Dtarget=aarch64-linux-musl
- uses: actions/upload-artifact@v3
with:
name: build-linux-musl-arm64
path: zig-out/lib/libsodium.so
path: zig-out/lib/libsodium.a
build-macos-x64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: configure
run: env CFLAGS="-Ofast -arch x86_64 -mmacosx-version-min=10.15" LDFLAGS="-arch x86_64 -mmacosx-version-min=10.15" ./configure --host=arm-apple-darwin20 --prefix=$PWD/.libsodium-build
- name: make
@ -175,7 +131,7 @@ jobs:
build-macos-arm64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: configure
run: env CFLAGS="-Ofast -arch arm64 -mmacosx-version-min=10.15" LDFLAGS="-arch arm64 -mmacosx-version-min=10.15" ./configure --host=arm-apple-darwin20 --prefix=$PWD/.libsodium-build
- name: make
@ -190,13 +146,8 @@ jobs:
pack:
runs-on: ubuntu-latest
needs:
- build-windows
- build-linux-glibc
- build-linux-glibc-arm
- build-linux-glibc-arm64
- build-linux-musl
- build-linux-musl-arm
- build-linux-musl-arm64
- build-windows-msvc
- build-others
- build-macos-x64
- build-macos-arm64
container:
@ -206,7 +157,7 @@ jobs:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build-win-x64
@ -215,6 +166,10 @@ jobs:
with:
name: build-win-x86
path: .libsodium-pack/runtimes/win-x86/native/
- uses: actions/download-artifact@v3
with:
name: build-win-arm64
path: .libsodium-pack/runtimes/win-arm64/native/
- uses: actions/download-artifact@v3
with:
name: build-linux-x64
@ -267,7 +222,7 @@ jobs:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: nuget-package

178
build.zig
View File

@ -168,12 +168,12 @@ pub fn build(b: *std.Build) !void {
}
const static_lib = b.addStaticLibrary(.{
.name = "sodium",
.name = if (target.result.isMinGW()) "libsodium-static" else "sodium",
.target = target,
.optimize = optimize,
});
const shared_lib = b.addSharedLibrary(.{
.name = if (target.result.isMinGW()) "sodium_shared" else "sodium",
.name = if (target.result.isMinGW()) "libsodium" else "sodium",
.target = target,
.optimize = optimize,
.strip = optimize != .Debug and !target.result.isMinGW(),
@ -208,129 +208,7 @@ pub fn build(b: *std.Build) !void {
initLibConfig(target, lib);
const MFlags = enum {
sse2,
ssse3,
sse41,
avx,
avx2,
avx512f,
aes,
pclmul,
rdrnd,
crypto,
fn f(flag: @This()) Target.Cpu.Feature.Set.Index {
return switch (flag) {
.sse2 => @intFromEnum(Target.x86.Feature.sse2),
.ssse3 => @intFromEnum(Target.x86.Feature.ssse3),
.sse41 => @intFromEnum(Target.x86.Feature.sse4_1),
.avx => @intFromEnum(Target.x86.Feature.avx),
.avx2 => @intFromEnum(Target.x86.Feature.avx2),
.avx512f => @intFromEnum(Target.x86.Feature.avx512f),
.aes => @intFromEnum(Target.x86.Feature.aes),
.pclmul => @intFromEnum(Target.x86.Feature.pclmul),
.rdrnd => @intFromEnum(Target.x86.Feature.rdrnd),
.crypto => @intFromEnum(Target.aarch64.Feature.crypto),
};
}
};
const MLib = struct {
name: []const u8,
count: usize,
sources: []const []const u8,
flags: []const MFlags,
arches: []const std.Target.Cpu.Arch,
lib: *Compile = undefined,
};
var mlibs: [8]MLib = .{
.{
.name = "armcrypto",
.count = 3,
.sources = &.{
"crypto_aead/aegis128l/aegis128l_armcrypto.c",
"crypto_aead/aegis256/aegis256_armcrypto.c",
"crypto_aead/aes256gcm/armcrypto/aead_aes256gcm_armcrypto.c",
},
.flags = &.{.aes},
.arches = &.{ .aarch64, .aarch64_be, .aarch64_32 },
},
.{
.name = "sse2",
.count = 1,
.sources = &.{
"crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c",
},
.flags = &.{.sse2},
.arches = &.{ .x86_64, .x86 },
},
.{
.name = "ssse3",
.count = 3,
.sources = &.{
"crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c",
"crypto_pwhash/argon2/argon2-fill-block-ssse3.c",
"crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c",
},
.flags = &.{ .sse2, .ssse3 },
.arches = &.{ .x86_64, .x86 },
},
.{
.name = "sse41",
.count = 1,
.sources = &.{
"crypto_generichash/blake2b/ref/blake2b-compress-sse41.c",
},
.flags = &.{ .sse2, .ssse3, .sse41 },
.arches = &.{ .x86_64, .x86 },
},
.{
.name = "avx2",
.count = 4,
.sources = &.{
"crypto_generichash/blake2b/ref/blake2b-compress-avx2.c",
"crypto_pwhash/argon2/argon2-fill-block-avx2.c",
"crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c",
"crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c",
},
.flags = &.{ .sse2, .ssse3, .sse41, .avx, .avx2 },
.arches = &.{.x86_64},
},
.{
.name = "avx512f",
.count = 1,
.sources = &.{
"crypto_pwhash/argon2/argon2-fill-block-avx512f.c",
},
.flags = &.{ .sse2, .ssse3, .sse41, .avx, .avx2, .avx512f },
.arches = &.{.x86_64},
},
.{
.name = "aesni",
.count = 3,
.sources = &.{
"crypto_aead/aegis128l/aegis128l_aesni.c",
"crypto_aead/aegis256/aegis256_aesni.c",
"crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c",
},
.flags = &.{ .avx, .aes, .pclmul },
.arches = &.{.x86_64},
},
.{
.name = "mrdrnd",
.count = 1,
.sources = &.{
"randombytes/internal/randombytes_internal_random.c",
},
.flags = &.{.rdrnd},
.arches = &.{ .x86_64, .x86 },
},
};
const base_flags = &.{
const flags = &.{
"-fvisibility=hidden",
"-fno-strict-aliasing",
"-fno-strict-overflow",
@ -340,61 +218,15 @@ pub fn build(b: *std.Build) !void {
const allocator = heap.page_allocator;
// compile CPU-specific library code
for (&mlibs) |*mlib| {
var target2 = target;
for (mlib.arches) |arch| {
if (target.result.cpu.arch == arch) {
for (mlib.flags) |flag| {
target2.query.cpu_features_add.addFeature(flag.f());
}
break;
}
}
mlib.lib = b.addStaticLibrary(.{
.name = mlib.name,
.target = target2,
.optimize = optimize,
});
const elib = mlib.lib;
initLibConfig(target, elib);
var flags = std.ArrayList([]const u8).init(allocator);
defer flags.deinit();
try flags.appendSlice(base_flags);
for (mlib.sources) |path| {
const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ src_path, path });
elib.addCSourceFiles(.{
.files = &.{full_path},
.flags = flags.items,
});
}
lib.linkLibrary(elib);
}
// compile generic library code
var walker = try src_dir.walk(allocator);
files: while (try walker.next()) |entry| {
var flags = std.ArrayList([]const u8).init(allocator);
defer flags.deinit();
try flags.appendSlice(base_flags);
while (try walker.next()) |entry| {
const name = entry.basename;
if (mem.endsWith(u8, name, ".c")) {
for (mlibs) |mlib| {
for (mlib.sources) |path| {
if (mem.eql(u8, entry.path, path)) continue :files;
}
}
const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ src_path, entry.path });
lib.addCSourceFiles(.{
.files = &.{full_path},
.flags = flags.items,
.flags = flags,
});
} else if (mem.endsWith(u8, name, ".S")) {
const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ src_path, entry.path });

View File

@ -27,12 +27,13 @@
<Content Include="ChangeLog" PackagePath="" />
<Content Include="runtimes/win-x64/native/libsodium.dll" PackagePath="runtimes/win-x64/native/" />
<Content Include="runtimes/win-x86/native/libsodium.dll" PackagePath="runtimes/win-x86/native/" />
<Content Include="runtimes/win-arm64/native/libsodium.dll" PackagePath="runtimes/win-arm64/native/" />
<Content Include="runtimes/linux-x64/native/libsodium.so" PackagePath="runtimes/linux-x64/native/" />
<Content Include="runtimes/linux-arm/native/libsodium.so" PackagePath="runtimes/linux-arm/native/" />
<Content Include="runtimes/linux-arm64/native/libsodium.so" PackagePath="runtimes/linux-arm64/native/" />
<Content Include="runtimes/linux-musl-x64/native/libsodium.so" PackagePath="runtimes/linux-musl-x64/native/" />
<Content Include="runtimes/linux-musl-arm/native/libsodium.so" PackagePath="runtimes/linux-musl-arm/native/" />
<Content Include="runtimes/linux-musl-arm64/native/libsodium.so" PackagePath="runtimes/linux-musl-arm64/native/" />
<Content Include="runtimes/linux-musl-x64/native/libsodium.a" PackagePath="runtimes/linux-musl-x64/native/" />
<Content Include="runtimes/linux-musl-arm/native/libsodium.a" PackagePath="runtimes/linux-musl-arm/native/" />
<Content Include="runtimes/linux-musl-arm64/native/libsodium.a" PackagePath="runtimes/linux-musl-arm64/native/" />
<Content Include="runtimes/osx-x64/native/libsodium.dylib" PackagePath="runtimes/osx-x64/native/" />
<Content Include="runtimes/osx-arm64/native/libsodium.dylib" PackagePath="runtimes/osx-arm64/native/" />
</ItemGroup>