From 8bbcf6821a0c8221b84de8d40e47d1d86755ad92 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 Feb 2024 21:09:20 -0800 Subject: [PATCH] pkg: remove unused files, add highway API to get targets --- pkg/highway/bridge.cpp | 9 +++++++ pkg/highway/build.zig | 1 + pkg/highway/main.zig | 57 ++++++++++++++++++++++++++++++++++++++++++ pkg/simdutf/build.zig | 38 +++++++++++----------------- pkg/simdutf/main.zig | 0 pkg/utfcpp/build.zig | 38 +++++++++++----------------- pkg/utfcpp/main.zig | 0 7 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 pkg/highway/bridge.cpp delete mode 100644 pkg/simdutf/main.zig delete mode 100644 pkg/utfcpp/main.zig diff --git a/pkg/highway/bridge.cpp b/pkg/highway/bridge.cpp new file mode 100644 index 000000000..1e86c4934 --- /dev/null +++ b/pkg/highway/bridge.cpp @@ -0,0 +1,9 @@ +#include +#include + +extern "C" { + +int64_t hwy_supported_targets() { + return HWY_SUPPORTED_TARGETS; +} +} diff --git a/pkg/highway/build.zig b/pkg/highway/build.zig index 47625a572..1b5157572 100644 --- a/pkg/highway/build.zig +++ b/pkg/highway/build.zig @@ -71,6 +71,7 @@ pub fn build(b: *std.Build) !void { }); } + lib.addCSourceFiles(.{ .flags = flags.items, .files = &.{"bridge.cpp"} }); lib.addCSourceFiles(.{ .dependency = upstream, .flags = flags.items, diff --git a/pkg/highway/main.zig b/pkg/highway/main.zig index e69de29bb..95ba6cda8 100644 --- a/pkg/highway/main.zig +++ b/pkg/highway/main.zig @@ -0,0 +1,57 @@ +extern "c" fn hwy_supported_targets() i64; + +pub const Targets = packed struct(i64) { + // x86_64 + _reserved: u4 = 0, + avx3_spr: bool = false, + _reserved_5: u1 = 0, + avx3_zen4: bool = false, + avx3_dl: bool = false, + avx3: bool = false, + avx2: bool = false, + _reserved_10: u1 = 0, + sse4: bool = false, + ssse3: bool = false, + _reserved_13: u1 = 0, // SSE3 reserved + sse2: bool = false, + _reserved_15_23: u9 = 0, + + // aarch64 + sve2_128: bool = false, + sve_256: bool = false, + sve2: bool = false, + sve: bool = false, + neon: bool = false, + neon_without_aes: bool = false, + _reserved_30_36: u6 = 0, + + // risc-v + rvv: bool = false, + _reserved_38_46: u9 = 0, + + // IBM Power + ppc10: bool = false, + ppc9: bool = false, + ppc8: bool = false, + z15: bool = false, + z14: bool = false, + _reserved_52_57: u6 = 0, + + // WebAssembly + wasm_emu256: bool = false, + wasm: bool = false, + _reserved_60_61: u2 = 0, + + // Emulation + emu128: bool = false, + scalar: bool = false, + _reserved_63: u1 = 0, +}; + +pub fn supported_targets() Targets { + return @bitCast(hwy_supported_targets()); +} + +test { + _ = supported_targets(); +} diff --git a/pkg/simdutf/build.zig b/pkg/simdutf/build.zig index 9ab1881b8..479713ca2 100644 --- a/pkg/simdutf/build.zig +++ b/pkg/simdutf/build.zig @@ -4,12 +4,6 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const module = b.addModule("simdutf", .{ - .root_source_file = .{ .path = "main.zig" }, - .target = target, - .optimize = optimize, - }); - const lib = b.addStaticLibrary(.{ .name = "simdutf", .target = target, @@ -17,12 +11,10 @@ pub fn build(b: *std.Build) !void { }); lib.linkLibCpp(); lib.addIncludePath(.{ .path = "vendor" }); - module.addIncludePath(.{ .path = "vendor" }); if (target.result.isDarwin()) { const apple_sdk = @import("apple_sdk"); try apple_sdk.addPaths(b, &lib.root_module); - try apple_sdk.addPaths(b, module); } var flags = std.ArrayList([]const u8).init(b.allocator); @@ -44,19 +36,19 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); - { - const test_exe = b.addTest(.{ - .name = "test", - .root_source_file = .{ .path = "main.zig" }, - .target = target, - .optimize = optimize, - }); - test_exe.linkLibrary(lib); - - var it = module.import_table.iterator(); - while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*); - const tests_run = b.addRunArtifact(test_exe); - const test_step = b.step("test", "Run tests"); - test_step.dependOn(&tests_run.step); - } + // { + // const test_exe = b.addTest(.{ + // .name = "test", + // .root_source_file = .{ .path = "main.zig" }, + // .target = target, + // .optimize = optimize, + // }); + // test_exe.linkLibrary(lib); + // + // var it = module.import_table.iterator(); + // while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*); + // const tests_run = b.addRunArtifact(test_exe); + // const test_step = b.step("test", "Run tests"); + // test_step.dependOn(&tests_run.step); + // } } diff --git a/pkg/simdutf/main.zig b/pkg/simdutf/main.zig deleted file mode 100644 index e69de29bb..000000000 diff --git a/pkg/utfcpp/build.zig b/pkg/utfcpp/build.zig index 3776675a6..a68631851 100644 --- a/pkg/utfcpp/build.zig +++ b/pkg/utfcpp/build.zig @@ -6,12 +6,6 @@ pub fn build(b: *std.Build) !void { const upstream = b.dependency("utfcpp", .{}); - const module = b.addModule("utfcpp", .{ - .root_source_file = .{ .path = "main.zig" }, - .target = target, - .optimize = optimize, - }); - const lib = b.addStaticLibrary(.{ .name = "utfcpp", .target = target, @@ -19,12 +13,10 @@ pub fn build(b: *std.Build) !void { }); lib.linkLibCpp(); lib.addIncludePath(upstream.path("")); - module.addIncludePath(upstream.path("")); if (target.result.isDarwin()) { const apple_sdk = @import("apple_sdk"); try apple_sdk.addPaths(b, &lib.root_module); - try apple_sdk.addPaths(b, module); } var flags = std.ArrayList([]const u8).init(b.allocator); @@ -44,19 +36,19 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); - { - const test_exe = b.addTest(.{ - .name = "test", - .root_source_file = .{ .path = "main.zig" }, - .target = target, - .optimize = optimize, - }); - test_exe.linkLibrary(lib); - - var it = module.import_table.iterator(); - while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*); - const tests_run = b.addRunArtifact(test_exe); - const test_step = b.step("test", "Run tests"); - test_step.dependOn(&tests_run.step); - } + // { + // const test_exe = b.addTest(.{ + // .name = "test", + // .root_source_file = .{ .path = "main.zig" }, + // .target = target, + // .optimize = optimize, + // }); + // test_exe.linkLibrary(lib); + // + // var it = module.import_table.iterator(); + // while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*); + // const tests_run = b.addRunArtifact(test_exe); + // const test_step = b.step("test", "Run tests"); + // test_step.dependOn(&tests_run.step); + // } } diff --git a/pkg/utfcpp/main.zig b/pkg/utfcpp/main.zig deleted file mode 100644 index e69de29bb..000000000