Compare commits

...

12 Commits

Author SHA1 Message Date
e98d64f39c
update build.zig and README 2021-06-30 09:37:14 -07:00
3c9f91c012
rework servicemodel to avoid comptime_string @import
This method was in violation of the accepted proposal
https://github.com/ziglang/zig/issues/2206
and disallowed in the compiler as of adc2aed,
now in 0.8.0.
2021-06-30 09:21:08 -07:00
dcfefa4072
address zig changes in awshttp. zig 15a030ef3 or newer needed
There are two recent changes in zig that effect awshttp.

1. cf65ab8 disallows unused variables. Fair enough and backward
compatible.
2. https://github.com/ziglang/zig/issues/2115#issuecomment-827968279

This comment resulted in a backward incompatible change to use the
underlying value from a C enum rather than its symbol. This reduces
edge cases in the compiler. Ultimately we may want awshttp to define
zig enums that mirror the C enums, but for now I've commented the
definitions of the C enums used.
2021-06-30 09:14:28 -07:00
de41b456d3
address unused variable in generated metaInfo function 2021-06-30 09:12:34 -07:00
267e72051d
make services direct imports/pub const in generated service manifest 2021-06-30 09:11:53 -07:00
9c3be78d9f
address new compilation errors introduced in zig cf65ab8 2021-06-30 09:10:08 -07:00
ad7aa96678
use new smithy package in generated code 2021-06-30 09:07:35 -07:00
ac07c9300f
extract smithy to separate package 2021-06-30 09:05:21 -07:00
22e39dd6e1
allow for spaces in the name to be "handled" (ignored) 2021-06-29 17:19:34 -07:00
ae7ecb1179
update gitignore for codegen 2021-06-29 17:10:52 -07:00
aa5b46c046
move codegen out of src - we will handle differently 2021-06-29 17:10:01 -07:00
7dc8e0e938
get all json tests passing with updated zig 0.9.0 (current master)
Key changes:

1. Remove all unused variables (see zig commit cf65ab8)
2. Remove tests requiring other files
3. Specify enum type when providing specific enum values (see zig
commits around 507a8096d)
2021-06-29 14:50:21 -07:00
284 changed files with 518 additions and 228 deletions

6
.gitignore vendored
View File

@ -1,7 +1,9 @@
.cache
zig-cache
src/codegen/models/*.zig
src/codegen/codegen
codegen/models/*.zig
codegen/codegen
*.tgz
service_manifest.zig
demo
src/models/
smithy/zig-out/

View File

@ -1,23 +1,17 @@
# AWS SDK for Zig
Ok, so it's not actually an SDK (yet). Right now this is SDK supports sts
get-caller-identity action only. Why? Because it's one of the easiest to
support, so I started there. From here, the next major step is to codegen
the types necessary to support the various services. Currently this code is
dynamically generating the sts types so we are somewhat codegen ready, but
current comptime limitations might trip us up. The advantage of comptime is
that only types actually used would be generated vs the whole surface area
of AWS. That said, with most of the heavy lifting now coded, the addition
of the request/response types, even if all of them are added, should not
balloon the size beyond "reasonable". Of course this still needs to be be seen.
Ok, so it's not actually an SDK (yet). Right now the SDK should support
any "query-based" operation and probably EC2, though this isn't tested yet.
Total service count should be around 18 services supported. If you use an
unsupported service, you'll get a compile error.
This is my first serious zig effort, so please issue a PR if the code isn't
"ziggy" or if there's a better way.
This is designed to be built statically using the `aws_c_*` libraries, so
we inherit a lot of the goodness of the work going on there. Implementing
get-caller-identity with all dependencies statically linked gives us a stripped
executable size of 5.3M for x86_linux (which is all that's tested at the moment).
we inherit a lot of the goodness of the work going on there. Current
executable size is 10.3M, about half of which is due to the SSL library.
This is for x86_linux (which is all that's tested at the moment).
## Building
@ -31,12 +25,15 @@ I'm also hoping/expecting AWS to factor out that library sometime in
the future.
Once that's done, you'll have an alpine image with all dependencies ready
to go and zig 0.7.1 installed. The build.zig currently relies on
[this PR to allow stripping -static](https://github.com/ziglang/zig/pull/8248),
so either:
to go and zig master installed. There are some build-related things still
broken in 0.8.0 and hopefully 0.8.1 will address those and we can be on
a standard release.
* Modify build.zig, then strip (or not) after the fact
* Install make and use the included Makefile
* `zig build` should work. It will build the code generation project, run
the code generation, then build the main project with the generated code.
* Install make and use the included Makefile. Going this path should be fine
with zig 0.8.0 release, but code generation has not been added to the
Makefile yet (ever?), so you'll be on your own for that.
## Running
@ -96,7 +93,7 @@ TODO List:
* ✓ Implement codegen for services with xml structures (using Smithy models)
* ✓ Implement codegen for others (using Smithy models)
* Switch to aws-c-cal upstream once [PR for full static musl build support is merged](https://github.com/awslabs/aws-c-cal/pull/89) (see Dockerfile)
* Remove compiler 0.7.1 shims when 0.8.0 is released
* Move to compiler on tagged release (hopefully 0.8.1)
(new 2021-05-29. I will proceed in this order unless I get other requests)
* ✓ Implement [AWS query protocol](https://awslabs.github.io/smithy/1.0/spec/aws/aws-query-protocol.html). This is the protocol in use by sts.getcalleridentity. Total service count 18
* Implement [AWS Json 1.0 protocol](https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_0-protocol.html). Includes dynamodb. Total service count 18
@ -106,7 +103,6 @@ TODO List:
Compiler wishlist/watchlist:
* Fix the weirdness we see with comptime type generation (see aws.zig around line 135)
* ~~[Allow declarations for comptime type generation](https://github.com/ziglang/zig/issues/6709)~~
This is no longer as important. The primary issue was in the return value, but

View File

@ -1,7 +1,8 @@
// const std = @import("std");
const std = @import("std");
const builtin = @import("builtin");
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
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
// means any target is allowed, and the default is native. Other options
@ -13,20 +14,45 @@ pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("demo", "src/main.zig");
// TODO: Generate src/models.zig
// https://github.com/ziglang/zig/issues/855
exe.addPackagePath("smithy", "smithy/src/smithy.zig");
// TODO: Support > linux
// TODO: Get a better cache in place
if (std.builtin.os.tag == .linux) {
const codegen = b.step("gen", "Generate zig service code from smithy models");
codegen.dependOn(&b.addSystemCommand(&.{ "/bin/sh", "-c", "cd codegen && zig build" }).step);
codegen.dependOn(&b.addSystemCommand(&.{
"/bin/sh", "-c",
\\ mkdir -p src/models/ && \
\\ [ -f src/models/service_manifest.zig ] || \
\\ ( cd codegen/models && ../codegen *.json && mv *.zig ../../src/models )
}).step);
b.getInstallStep().dependOn(codegen);
}
exe.addCSourceFile("src/bitfield-workaround.c", &[_][]const u8{"-std=c99"});
exe.addIncludeDir("./src/");
exe.addIncludeDir("/usr/local/include");
exe.addObjectFile("/usr/local/lib64/libs2n.a");
exe.addObjectFile("/usr/local/lib64/libcrypto.a");
exe.addObjectFile("/usr/local/lib64/libssl.a");
exe.addObjectFile("/usr/local/lib64/libaws-c-auth.a");
exe.addObjectFile("/usr/local/lib64/libaws-c-cal.a");
exe.addObjectFile("/usr/local/lib64/libaws-c-common.a");
exe.addObjectFile("/usr/local/lib64/libaws-c-compression.a");
exe.addObjectFile("/usr/local/lib64/libaws-c-http.a");
exe.addObjectFile("/usr/local/lib64/libaws-c-io.a");
const c_include_dirs = .{
"./src/",
"/usr/local/include",
};
inline for (c_include_dirs) |dir|
exe.addIncludeDir(dir);
const dependent_objects = .{
"/usr/local/lib64/libs2n.a",
"/usr/local/lib64/libcrypto.a",
"/usr/local/lib64/libssl.a",
"/usr/local/lib64/libaws-c-auth.a",
"/usr/local/lib64/libaws-c-cal.a",
"/usr/local/lib64/libaws-c-common.a",
"/usr/local/lib64/libaws-c-compression.a",
"/usr/local/lib64/libaws-c-http.a",
"/usr/local/lib64/libaws-c-io.a",
};
inline for (dependent_objects) |obj|
exe.addObjectFile(obj);
exe.linkSystemLibrary("c");
exe.setTarget(target);
exe.setBuildMode(mode);
@ -36,9 +62,14 @@ pub fn build(b: *Builder) void {
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.113+05b5e49bc.tar.xz
// exe.override_dest_dir = .{ .Custom = ".." };
exe.override_dest_dir = .{ .custom = ".." };
// Static linkage flag was nonfunctional until 2b2efa24d0855
// Did not notice this until 2021-06-28, and that nightly is:
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.321+15a030ef3.tar.xz
exe.linkage = .static;
exe.strip = true;
const is_strip = b.option(bool, "strip", "strip exe") orelse true;
exe.strip = !is_strip;
exe.install();
const run_cmd = exe.run();
@ -49,4 +80,20 @@ pub fn build(b: *Builder) void {
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const test_step = b.step("test", "Run library tests");
var build_dir = try std.fs.openDirAbsolute(b.build_root, .{});
defer build_dir.close();
var src_dir = try build_dir.openDir("src", .{ .iterate = true });
defer src_dir.close();
var iterator = src_dir.iterate();
while (try iterator.next()) |entry| {
if (std.mem.endsWith(u8, entry.name, ".zig")) {
const name = try std.fmt.allocPrint(b.allocator, "src/{s}", .{entry.name});
defer b.allocator.free(name);
const t = b.addTest(name);
t.setBuildMode(mode);
test_step.dependOn(&t.step);
}
}
}

59
codegen/build.zig Normal file
View File

@ -0,0 +1,59 @@
const std = @import("std");
pub fn build(b: *std.build.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
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("codegen", "src/main.zig");
exe.addPackagePath("smithy", "../smithy/src/smithy.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
// This line works as of c5d412268
// Earliest nightly is 05b5e49bc on 2021-06-12
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.113+05b5e49bc.tar.xz
// exe.override_dest_dir = .{ .Custom = ".." };
exe.override_dest_dir = .{ .custom = ".." };
// Static linkage flag was nonfunctional until 2b2efa24d0855
// Did not notice this until 2021-06-28, and that nightly is:
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.321+15a030ef3.tar.xz
exe.linkage = .static;
const is_strip = b.option(bool, "strip", "strip exe") orelse true;
exe.strip = !is_strip;
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const test_step = b.step("test", "Run library tests");
var build_dir = try std.fs.openDirAbsolute(b.build_root, .{});
defer build_dir.close();
var src_dir = try build_dir.openDir("src", .{ .iterate = true });
defer src_dir.close();
var iterator = src_dir.iterate();
while (try iterator.next()) |entry| {
if (std.mem.endsWith(u8, entry.name, ".zig") and
!std.mem.eql(u8, entry.name, "main.zig"))
{
const name = try std.fmt.allocPrint(b.allocator, "src/{s}", .{entry.name});
defer b.allocator.free(name);
const t = b.addTest(name);
t.setBuildMode(mode);
test_step.dependOn(&t.step);
}
}
}

Some files were not shown because too many files have changed in this diff Show More