From 14666da73f4c1cf4b018d793d9a84d37496e00d8 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 9 Jan 2024 15:16:29 -0800 Subject: [PATCH] clean up build (includes two fixes for arm 32 bit) --- .gitea/workflows/build.yaml | 42 ++++++++++--------- build.zig | 83 +++++++++++++++++++++++++++---------- src/aws.zig | 2 +- src/xml_shaper.zig | 2 +- 4 files changed, 86 insertions(+), 43 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index f6053b9..55e470b 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -22,24 +22,28 @@ jobs: # # However, arm64/linux isn't quite fully tier 1 yet, so this is more of a # TODO: https://github.com/ziglang/zig/issues/2443 - - run: wget -q https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz - - run: tar x -C /usr/local -f zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz - - run: ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig - - run: zig build test --verbose - - run: zig build --verbose -Dtarget=arm-linux - - run: zig build -Dtarget=x86_64-windows - - run: zig build -Dtarget=aarch64-linux - - run: zig build -Dtarget=riscv64-linux - - run: zig build -Dtarget=x86_64-macos - - run: zig build -Dtarget=aarch64-macos - - run: ( cd example && zig build ) # Make sure example builds + - name: Install zig + run: | + wget -q https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz + tar x -C /usr/local -f zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz + ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig + - name: Run tests + run: zig build test --verbose + - name: Build example + run: ( cd example && zig build ) # Make sure example builds # Zig package manager expects everything to be inside a directory in the archive, # which it then strips out on download. So we need to shove everything inside a directory # the way GitHub/Gitea does for repo archives # # Also, zig tar process doesn't handle gnu format for long names, nor does it seam to - # handle posix long name semantics cleanly either. Let's try ustar - - run: tar -czf ${{ runner.temp }}/${{ github.sha }}-with-models.tar.gz --format ustar --exclude 'zig-*' --transform 's,^,${{ github.sha }}/,' * + # handle posix long name semantics cleanly either. ustar works. This + # should be using git archive, but we need our generated code to be part of it + - name: Package source code with generated models + run: | + tar -czf ${{ runner.temp }}/${{ github.sha }}-with-models.tar.gz \ + --format ustar \ + --exclude 'zig-*' \ + --transform 's,^,${{ github.sha }}/,' * # - name: Sign # id: sign # uses: https://git.lerch.org/lobo/action-hsm-sign@v1 @@ -57,13 +61,11 @@ jobs: # - run: | # echo "Signature 1 should be ./foo.sig: ${{ steps.sign.outputs.SIG_1 }}" # - run: echo "URL of foo (1) is ${{ steps.sign.outputs.URL_1 }}" - - name: Upload - uses: actions/upload-artifact@v3 - with: - name: ${{ github.sha }}-with-models.tar.gz - path: '${{ runner.temp }}/${{ github.sha }}-with-models.tar.gz' - - name: Publish - run: 'curl --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} --upload-file ${{ runner.temp }}/${{ github.sha }}-with-models.tar.gz https://git.lerch.org/api/packages/lobo/generic/aws-sdk-with-models/${{ github.sha }}/${{ github.sha }}-with-models.tar.gz' + - name: Publish source code with generated models + run: | + curl --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ + --upload-file ${{ runner.temp }}/${{ github.sha }}-with-models.tar.gz \ + https://git.lerch.org/api/packages/lobo/generic/aws-sdk-with-models/${{ github.sha }}/${{ github.sha }}-with-models.tar.gz - name: Notify uses: https://git.lerch.org/lobo/action-notify-ntfy@v2 if: always() diff --git a/build.zig b/build.zig index 15f6936..5081721 100644 --- a/build.zig +++ b/build.zig @@ -8,6 +8,42 @@ const models_hash: ?[]const u8 = "1220a414719bff14c9362fb1c695e3346fa12ec2e728ba const models_subdir = "codegen/sdk-codegen/aws-models/"; // note will probably not work on windows const models_dir = "p" ++ std.fs.path.sep_str ++ (models_hash orelse "") ++ std.fs.path.sep_str ++ models_subdir; +const test_targets = [_]std.zig.CrossTarget{ + .{}, // native + .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + }, + .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + }, + .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + }, + .{ + .cpu_arch = .arm, + .os_tag = .linux, + }, + .{ + .cpu_arch = .x86_64, + .os_tag = .windows, + }, + .{ + .cpu_arch = .aarch64, + .os_tag = .macos, + }, + .{ + .cpu_arch = .x86_64, + .os_tag = .macos, + }, + // .{ + // .cpu_arch = .wasm32, + // .os_tag = .wasi, + // }, +}; + pub fn build(b: *Builder) !void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which @@ -82,27 +118,10 @@ pub fn build(b: *Builder) !void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - // Creates a step for unit testing. This only builds the test executable - // but does not run it. - const unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/aws.zig" }, - .target = target, - .optimize = optimize, - }); - unit_tests.addModule("smithy", smithy_dep.module("smithy")); - - const run_unit_tests = b.addRunArtifact(unit_tests); - - // Similar to creating the run step earlier, this exposes a `test` step to - // the `zig build --help` menu, providing a way for the user to request - // running the unit tests. - const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&run_unit_tests.step); - const fm = b.step("fetch", "Fetch model files"); var fetch_step = FetchStep.create(b, models_url, models_hash); fm.dependOn(&fetch_step.step); - { + const gen_step = blk: { const cg = b.step("gen", "Generate zig service code from smithy models"); const cg_exe = b.addExecutable(.{ @@ -139,10 +158,32 @@ pub fn build(b: *Builder) !void { // later about warning on manual changes... cg.dependOn(&cg_cmd.step); - exe.step.dependOn(cg); - unit_tests.step.dependOn(cg); - } + break :blk cg; + }; + exe.step.dependOn(gen_step); + + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. + const test_step = b.step("test", "Run unit tests"); + + for (test_targets) |t| { + // Creates a step for unit testing. This only builds the test executable + // but does not run it. + const unit_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/aws.zig" }, + .target = t, + .optimize = optimize, + }); + unit_tests.addModule("smithy", smithy_dep.module("smithy")); + unit_tests.step.dependOn(gen_step); + + const run_unit_tests = b.addRunArtifact(unit_tests); + run_unit_tests.skip_foreign_checks = true; + + test_step.dependOn(&run_unit_tests.step); + } b.installArtifact(exe); } const FetchStep = struct { diff --git a/src/aws.zig b/src/aws.zig index f688f7f..fcf2bbb 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -1433,7 +1433,7 @@ fn processRequest(options: *TestOptions, server: *std.http.Server) !void { options.requests_processed += 1; if (res.request.content_length) |l| - options.request_body = try res.reader().readAllAlloc(options.allocator, @as(usize, l)) + options.request_body = try res.reader().readAllAlloc(options.allocator, @as(usize, @intCast(l))) else options.request_body = try options.allocator.dupe(u8, ""); options.request_method = res.request.method; diff --git a/src/xml_shaper.zig b/src/xml_shaper.zig index f1b4d51..fd51594 100644 --- a/src/xml_shaper.zig +++ b/src/xml_shaper.zig @@ -367,7 +367,7 @@ pub fn fuzzyEqual(a: []const u8, b: []const u8, options: xml.PredicateOptions) ! } fn normalize(val: []u8) []u8 { - var underscores: u64 = 0; + var underscores: usize = 0; for (val, 0..) |ch, i| { if (ch == '_') { underscores = underscores + 1;