diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 82cba79..d2d7049 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,5 +1,6 @@ name: AWS-Zig Build on: + workflow_dispatch: push: branches: - 'master' @@ -17,11 +18,17 @@ jobs: - name: Check out repository code uses: actions/checkout@v4 - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 + uses: https://github.com/mlugg/setup-zig@v1.2.1 with: version: 0.14.0 + - name: Restore Zig caches + uses: https://github.com/Hanaasagi/zig-action-cache@3954aae427f8b05914e08dfd79f15e1f2e435929 + - name: Run smoke test + run: zig build smoke-test --verbose - name: Run tests - run: zig build test --verbose + run: zig build test --verbose --summary all + - name: Run tests (release mode) + run: zig build test -Doptimize=ReleaseSafe --verbose # Zig build scripts don't have the ability to import depenedencies directly # (https://github.com/ziglang/zig/issues/18164). We can allow downstream # build scripts to import aws with a few tweaks, but we can't @import("src/aws.zig") @@ -66,7 +73,7 @@ jobs: # - run: echo "URL of foo (1) is ${{ steps.sign.outputs.URL_1 }}" - name: Publish source code with generated models run: | - curl --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ + curl -s --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: Build example diff --git a/.gitea/workflows/zig-mach.yaml b/.gitea/workflows/zig-mach.yaml index 12c3903..5232cb9 100644 --- a/.gitea/workflows/zig-mach.yaml +++ b/.gitea/workflows/zig-mach.yaml @@ -26,15 +26,19 @@ jobs: with: ref: zig-mach - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 + uses: https://github.com/mlugg/setup-zig@v1.2.1 with: version: mach-latest + - name: Restore Zig caches + uses: https://github.com/Hanaasagi/zig-action-cache@3954aae427f8b05914e08dfd79f15e1f2e435929 - name: Run gen run: zig build gen --verbose - name: Run smoke test run: zig build smoke-test --verbose - name: Run full tests - run: zig build test --verbose + run: zig build test --verbose --summary all + - name: Run tests (release mode) + run: zig build test -Doptimize=ReleaseSafe --verbose # 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 @@ -67,7 +71,7 @@ jobs: # - run: echo "URL of foo (1) is ${{ steps.sign.outputs.URL_1 }}" - name: Publish source code with generated models run: | - curl --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ + curl -s --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ --upload-file ${{ runner.temp }}/${{ github.sha }}${{ env.PKG_PREFIX }}-with-models.tar.gz \ https://git.lerch.org/api/packages/lobo/generic/aws-sdk-with-models/${{ github.sha }}/${{ github.sha }}${{ env.PKG_PREFIX }}-with-models.tar.gz - name: Build example diff --git a/.gitea/workflows/zig-nightly.yaml b/.gitea/workflows/zig-nightly.yaml index e97917e..7a60a04 100644 --- a/.gitea/workflows/zig-nightly.yaml +++ b/.gitea/workflows/zig-nightly.yaml @@ -26,11 +26,17 @@ jobs: with: ref: zig-develop - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 + uses: https://github.com/mlugg/setup-zig@v1.2.1 with: version: master - - name: Run tests - run: zig build test --verbose + - name: Restore Zig caches + uses: https://github.com/Hanaasagi/zig-action-cache@3954aae427f8b05914e08dfd79f15e1f2e435929 + - name: Run smoke test + run: zig build smoke-test --verbose + - name: Run full tests + run: zig build test --verbose --summary all + - name: Run tests (release mode) + run: zig build test -Doptimize=ReleaseSafe --verbose # 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 @@ -63,7 +69,7 @@ jobs: # - run: echo "URL of foo (1) is ${{ steps.sign.outputs.URL_1 }}" - name: Publish source code with generated models run: | - curl --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ + curl -s --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ --upload-file ${{ runner.temp }}/${{ github.sha }}${{ env.PKG_PREFIX }}-with-models.tar.gz \ https://git.lerch.org/api/packages/lobo/generic/aws-sdk-with-models/${{ github.sha }}/${{ github.sha }}${{ env.PKG_PREFIX }}-with-models.tar.gz - name: Build example diff --git a/.gitea/workflows/zig-previous.yaml b/.gitea/workflows/zig-previous.yaml index 1bc831f..20375ac 100644 --- a/.gitea/workflows/zig-previous.yaml +++ b/.gitea/workflows/zig-previous.yaml @@ -20,11 +20,18 @@ jobs: with: ref: zig-0.13 - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 + uses: https://github.com/mlugg/setup-zig@v1.2.1 with: version: 0.13.0 - - name: Run tests - run: zig build test --verbose + - name: Restore Zig caches + uses: https://github.com/Hanaasagi/zig-action-cache@3954aae427f8b05914e08dfd79f15e1f2e435929 + - name: Run smoke test + run: zig build smoke-test --verbose + - name: Run full tests + run: zig build test --verbose --summary all + # Release mode fix not backported to 0.13.0 code + #- name: Run tests (release mode) + # run: zig build test -Doptimize=ReleaseSafe --verbose # Zig build scripts don't have the ability to import depenedencies directly # (https://github.com/ziglang/zig/issues/18164). We can allow downstream # build scripts to import aws with a few tweaks, but we can't @import("src/aws.zig") @@ -69,7 +76,7 @@ jobs: # - run: echo "URL of foo (1) is ${{ steps.sign.outputs.URL_1 }}" - name: Publish source code with generated models run: | - curl --user ${{ github.actor }}:${{ secrets.PACKAGE_PUSH }} \ + curl -s --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: Build example diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 313e87b..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Current zig version build -on: - push: - branches: - - 'master' -jobs: - build-amd64: - runs-on: ubuntu-latest - if: ${{ github.env.GITEA_ACTIONS != 'true' }} - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 - with: - version: 0.14.0 - - name: Run tests - run: zig build test -Dbroken-windows --verbose # Github runners try to run the windows tests despite disabling foreign checks - - name: Build example - run: ( cd example && zig build ) # Make sure example builds diff --git a/.github/workflows/zig-mach.yaml b/.github/workflows/zig-mach.yaml deleted file mode 100644 index 0d7e65e..0000000 --- a/.github/workflows/zig-mach.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Latest mach nominated zig version build -on: - push: - branches: - - 'zig-mach*' -jobs: - build-zig-mach-latest: - runs-on: ubuntu-latest - if: ${{ github.env.GITEA_ACTIONS != 'true' }} - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 - with: - version: mach-latest - - name: Run tests - run: zig build test -Dbroken-windows --verbose - - name: Build example - run: ( cd example && zig build ) # Make sure example builds diff --git a/.github/workflows/zig-nightly.yaml b/.github/workflows/zig-nightly.yaml deleted file mode 100644 index 772f6b4..0000000 --- a/.github/workflows/zig-nightly.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Nightly zig version Build -on: - push: - branches: - - 'zig-develop*' -jobs: - build-zig-nightly: - runs-on: ubuntu-latest - if: ${{ github.env.GITEA_ACTIONS != 'true' }} - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 - with: - version: master - - name: Run tests - run: zig build test -Dbroken-windows --verbose - - name: Build example - run: ( cd example && zig build ) # Make sure example builds diff --git a/.github/workflows/zig-previous.yaml b/.github/workflows/zig-previous.yaml deleted file mode 100644 index e6f8096..0000000 --- a/.github/workflows/zig-previous.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Previous zig version Build -on: - push: - branches: - - 'zig-0.13' -jobs: - build-amd64: - runs-on: ubuntu-latest - if: ${{ github.env.GITEA_ACTIONS != 'true' }} - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Setup Zig - uses: mlugg/setup-zig@v1.2.1 - with: - version: 0.13.0 - - name: Run tests - run: zig build test -Dbroken-windows --verbose # Github runners try to run the windows tests despite disabling foreign checks - - name: Build example - run: ( cd example && zig build ) # Make sure example builds diff --git a/example/build.zig.zon b/example/build.zig.zon index 3eb0dd7..a4053f6 100644 --- a/example/build.zig.zon +++ b/example/build.zig.zon @@ -6,8 +6,8 @@ .dependencies = .{ .aws = .{ - .url = "https://git.lerch.org/api/packages/lobo/generic/aws-sdk-with-models/8ac7aa47f728b8ab4bb857d2ec016fe362e3f3c3/8ac7aa47f728b8ab4bb857d2ec016fe362e3f3c3nightly-zig-with-models.tar.gz", - .hash = "aws-0.0.1-SbsFcJ6ACQBrABo_x6CvbSEdieo2TXPnDlANQLAkDfdD", + .url = "https://git.lerch.org/api/packages/lobo/generic/aws-sdk-with-models/7a6086447c1249b0e5b5b5f3873d2f7932bea56d/7a6086447c1249b0e5b5b5f3873d2f7932bea56d-with-models.tar.gz", + .hash = "aws-0.0.1-SbsFcGN_CQCBjurpc2GEMw4c_qAkGu6KpuVnLBLY4L4q", }, }, } diff --git a/src/aws.zig b/src/aws.zig index 2738a1e..d0db16e 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -688,7 +688,6 @@ pub fn Request(comptime request_action: anytype) type { fn ParsedJsonData(comptime T: type) type { return struct { - raw_response_parsed: bool, parsed_response_ptr: *T, allocator: std.mem.Allocator, @@ -697,8 +696,7 @@ pub fn Request(comptime request_action: anytype) type { pub fn deinit(self: MySelf) void { // This feels like it should result in a use after free, but it // seems to be working? - if (self.raw_response_parsed) - self.allocator.destroy(self.parsed_response_ptr); + self.allocator.destroy(self.parsed_response_ptr); } }; } @@ -713,11 +711,13 @@ pub fn Request(comptime request_action: anytype) type { std.mem.eql(u8, key, action.action_name ++ "Response") or std.mem.eql(u8, key, action.action_name ++ "Result") or isOtherNormalResponse(response_types.NormalResponse, key); - var raw_response_parsed = false; var stream = json.TokenStream.init(data); const parsed_response_ptr = blk: { - if (!response_types.isRawPossible or found_normal_json_response) - break :blk &(json.parse(response_types.NormalResponse, &stream, parser_options) catch |e| { + const ptr = try options.client.allocator.create(response_types.NormalResponse); + errdefer options.client.allocator.destroy(ptr); + + if (!response_types.isRawPossible or found_normal_json_response) { + ptr.* = (json.parse(response_types.NormalResponse, &stream, parser_options) catch |e| { log.err( \\Call successful, but unexpected response from service. \\This could be the result of a bug or a stale set of code generated @@ -733,10 +733,10 @@ pub fn Request(comptime request_action: anytype) type { return e; }); + break :blk ptr; + } + log.debug("Appears server has provided a raw response", .{}); - raw_response_parsed = true; - const ptr = try options.client.allocator.create(response_types.NormalResponse); - errdefer options.client.allocator.destroy(ptr); @field(ptr.*, std.meta.fields(action.Response)[0].name) = json.parse(response_types.RawResponse, &stream, parser_options) catch |e| { log.err( @@ -756,8 +756,7 @@ pub fn Request(comptime request_action: anytype) type { break :blk ptr; }; return ParsedJsonData(response_types.NormalResponse){ - .raw_response_parsed = raw_response_parsed, - .parsed_response_ptr = @constCast(parsed_response_ptr), //TODO: why doesn't changing const->var above fix this? + .parsed_response_ptr = parsed_response_ptr, .allocator = options.client.allocator, }; } @@ -1702,7 +1701,7 @@ const TestSetup = struct { request_options: TestOptions, server_thread: std.Thread = undefined, creds: aws_auth.Credentials = undefined, - client: *Client = undefined, + client: Client = undefined, started: bool = false, const Self = @This(); @@ -1738,8 +1737,8 @@ const TestSetup = struct { null, ); aws_creds.static_credentials = self.creds; - var client = Client.init(self.allocator, .{}); - self.client = &client; + const client = Client.init(self.allocator, .{}); + self.client = client; return .{ .region = "us-west-2", .client = client,