Commit Graph

56 Commits

Author SHA1 Message Date
99daf922fd build: enable building protobuf-c and streaming support
This is a simple enough change. However, there are no tests for the
streaming functionality, and I need to decide if I want to actually
try to write bindings for them.
2023-11-06 22:32:22 -08:00
7794532fb4 tests: fix for 3.7.0
Well, at least it seems the update worked.
2023-11-06 22:30:57 -08:00
ff13f5e621 deps: vendor protobuf-c runtime library v1.4.1
1. I'm not using git-subrepo for this because most of the protobuf-c
   git repository is for the protocol buffers compiler integration,
   which we do not need because nats.c already has the generated files
   in its source tree.

2. The protobuf-c runtime library is pretty simple, so maintaining its
   build process should be quite straightforward. It seems stable as
   well, which should simplify the maintenance burden.

3. Not having streaming support is the last major nats.c feature
   missing from this project (as far as I am aware). Building this
   functionality into the library, even if a nice zig API is missing
   (as it is with jetStream as well), can still allow a determined
   user to wrap and use the functionality while benefitting from the
   zig build system and package manager, which is a win.
2023-10-14 18:25:01 -07:00
41fbdf886b git subrepo pull --branch=v3.7.0 deps/nats.c
subrepo:
  subdir:   "deps/nats.c"
  merged:   "5d057f6"
upstream:
  origin:   "https://github.com/nats-io/nats.c.git"
  branch:   "v3.7.0"
  commit:   "5d057f6"
git-subrepo:
  version:  "0.4.6"
  commit:   "affc4c01a"
2023-10-14 13:22:13 -07:00
136ef10775 readme: fix build.zig example
As it turns out, it is important to link the C library also.
2023-09-10 13:00:40 -07:00
0b7b5e4f54 deps: update to LibreSSL v3.8.1 2023-09-03 18:50:09 -07:00
d95cbe83e1 tests.util: fix some error edge cases and autogenerate server url
I was originally going to have this generate a random token by default,
but I don't think it matters. the bigger thing would perhaps be to
manage the listen port to avoid conflicts, but this isn't currently a
problem, so I will pretend it won't ever be a problem.
2023-09-03 17:34:29 -07:00
a53b32204d tests: add subscription method coverage
This resulted in some minor binding fixes. In theory, all the main
wrapped API endpoints are now covered.
2023-09-03 16:28:00 -07:00
373616f234 tests.message: improve API coverage 2023-09-03 16:14:37 -07:00
6dc50530f1 message: a bit of cleanup around header iterators 2023-09-03 16:13:58 -07:00
d72463ee76 readme: add status section
Once the Subscription and Message tests have been fleshed out, this
will go into maintenance mode, since I've pretty much accomplished
everything I wanted to accomplish with it.
2023-09-02 22:15:03 -07:00
dfb6d10277 connection: add additional tests and fix various bindings
If you think these unit tests look crappy, that's because they are.
Actual behavioral tests are pretty much exclusively relying on the
underlying C library being well-tested, so all these tests are really
trying to do is ref the bindings in our endpoints to make sure there
aren't any compilation issues with them. Obviously this is making a
difference, since a variety of issues have been found and addressed as
a result.
2023-09-02 21:56:40 -07:00
d541e1e759 readme: update for current project state 2023-09-02 17:31:59 -07:00
67cb801f54 tests.connection: add basic encrypted connection tests
Since I went to the effort of getting this to build with LibreSSL, it
makes sense to check that it works. And it seems to. There's nothing
special about the certificates added, except that they don't expire
for 100 years, which is hopefully long enough that nothing will matter
any more. They get baked into the test executable, since this was the
best way I could figure out to be able to consistently load them
during runtime, since they're stored relative to the source, not
necessarily relative to the working directory in use when the test
executable is run.

This required some augmentation to the test server launcher which will
make it easier to add additional flags to it in the future, if that
becomes necessary.
2023-09-02 17:12:00 -07:00
b453ec3d92 all: add missing copyright headers
Tests are CC0/public domain because there's no reason for them not to
be. Examples are also CC0/public domain, but this may be a little bit
weird because they are largely straightforward ports of examples from
nats.c which carry the Apache license. However, I personally wrote
them against the zig bindings and I doubt anyone will end up in a
court of law due to their software containing uselessly trivial
example code.
2023-09-02 15:04:46 -07:00
29966dc838 build: link LibreSSL for SSL support
I don't have a single clue in heck if this actually works, but it at
least does compile. At some point I will probably add a test or two to
find out how broken this is.
2023-08-31 23:50:28 -07:00
741af6f976 connection.ConnectionOptions: fix a lot of issues
Various copypasta and typing errors around the thunks, some other
copypasta errors, etc. Also add a test which hits a decent chunk of
the API surface of ConnectionOptions, which is how these issues were
caught in the first place. This is an ugly test, but it has clearly
served its purpose.
2023-08-28 22:46:14 -07:00
142021bfd3 connection: make callback thunks pass userdata as first parameter
This makes the thunks compatible with standard struct methods, which
seems desirable.
2023-08-28 21:50:58 -07:00
ee803168a3 tests.connection: test auth varieties
Also fix password auth in the nats-server launcher.
2023-08-28 21:27:59 -07:00
cba76ae724 tests.message: clean up a little bit 2023-08-27 18:11:34 -07:00
1c3e5ff538 tests: add basic connection test
I created a utility class to spawn a NATS server. This assumes it is
installed and in PATH, which should be easy enough to accomplish for a
CI environment. The current approach will not work with parallel
tests, but that's not a practical reality, so this route should be
fine for the time being. It might be nice to spawn a default server at
the beginning of testing and tear it down at the end, to save waiting
for the startup/shutdown time in many individual tests. This makes me
wonder: if I initialize a server in the beginning of the `test` block
in main that imports the other modules, does that scope stay live
while the "child" tests are running? My default guess would be
probably not, but that would be very convenient, so I might try it out
and see.
2023-08-27 18:11:34 -07:00
d3d5849f55 build test: install unit tests binary
I've gotten tired of trying to find this in the cache dir, since the
build system does not rerun it once it is cached. Also sometimes the
build runner does weird things to the output.
2023-08-27 18:11:34 -07:00
4cf5049882 tests: add top level function tests
These are mostly just tests to make sure the wrappers function as
written, rather than testing for any specific output. This commit
demonstrates the simple value of actually referencing the various
wrapper functions, as a variety of really basic compilation errors
were caught and addressed.
2023-08-27 18:11:34 -07:00
226d678e68 examples: make request_reply slightly more interesting 2023-08-24 20:23:19 -07:00
0dac8402cf thunks: also aligncast userdata
This is probably the sort of thing that I wouldn't actually think of
having explicit test coverage for if I hadn't accidentally ran across
it while fiddling. I will compensate for this easily by not actually
writing tests at all.
2023-08-24 20:23:19 -07:00
2e06f44aa8 examples: add pub_bytes
This was the point that I realized there's no reason to have the string
variants of the publishing methods. But also there's not really much
point in porting the other getting-started examples, since we've
covered all their functionality in the existing examples
(actually, this one is redundant too, but I have already done it, so
it's getting grandfathered in).

Porting some of the more interesting examples might be a good idea, but
those have a weird argument parser that I don't really want to port
(even though it is very simple in the way that it works). For the most
part, I think writing unit tests will do a better of flexing the
bindings.
2023-08-23 22:35:27 -07:00
af788a0536 nats: export Status
There's not much of a reason this should be used externally, but I also
favor having things be exported rather than not exported. There will
probably be more opening up of the other imports here in the future.
2023-08-23 22:28:44 -07:00
65ab46f714 connection: eliminate String method variants
After contemplating this for a little bit, there's no point in exposing
these separately from the plain variants. Even nats.c internally calls
its plain variants after calling `strlen` on the input. Zig benefits
from having nicer pointer types than C, so we get "string" handling
for free from the fact that the standard variants take slices anyway.
2023-08-23 22:27:33 -07:00
1256feb7ef examples: always build in debug mode
There's no reason I can think of for these to be optimized.
2023-08-23 22:25:36 -07:00
18205a5533 examples: add statistics to request_reply
I should probably write some tests instead.
2023-08-23 22:18:45 -07:00
3816f32101 statistics: fix a remarkably bungled wrapper
keyboards are hard.
2023-08-23 22:18:03 -07:00
b101e0acd2 message: more iterators, less problems
This seems like a pretty nice way to do this, since it lets us produce
the sliced version of each value rather than the somewhat janky many
pointer.
2023-08-23 22:03:25 -07:00
ebd3e64111 examples: port header example to zig
This looks a lot nicer than its c counterpart, in my opinion.
2023-08-23 01:05:37 -07:00
3e5840bd84 message: fix header method types and add header iterator
As I ascertained from reading the code, nats.c does in fact let you set
message headers with null values. However, the library segfaults if
you try to actually send such a message over the wire. So we just
forbid it with stricter typing and assume it's not possible for
someone to send us a message containing headers with a null value as
well.
2023-08-23 01:03:29 -07:00
48962f27d9 add examples and integrate into build
I suppose the next step will be to translate the C examples into their
zig counterparts. This is also good dog food.
2023-08-21 23:51:58 -07:00
40d898a55e tests: start building tests in separate directory
This approach seems nice, and as a bonus it makes it easier to run the
tests through the module interface rather than by importing the
sources directly, which I think is a good dog food approach.
2023-08-21 23:31:46 -07:00
ef185bc975 build: convert to being a module 2023-08-21 23:30:31 -07:00
9a4c80861c connection: finish wrapping connection methods
I believe the standard API surface is now completely wrapped, ignoring
whatever cool copy-paste errors or other mistakes I introduced which
are currently undetectable due to lazy analysis and lack of test
coverage. Cool.
2023-08-19 19:00:15 -07:00
39edf12d34 connection.ConnectionOptions: finish hooking up callbacks
This was kind of tedious, but there were some interesting choices to be
made with regards to how the callback signatures should be adapted,
especially in the few cases that heavily use out-params in C. Ignoring
the lack of test coverage, this puts us pretty close to having the
entire basic API wrapped.
2023-08-19 17:15:29 -07:00
3ff894cc0d keep thunkening
There are a lot of callbacks to wrap. This is a sloppy commit that
almost certainly needs fixes.
2023-08-18 23:01:33 -07:00
2e1a5579b9 connection: mostly wrap the connection options API
There are a several options that set up callbacks that I did not wrap
in this first pass because I need to decide on whether or not it makes
sense to move the various thunks into a common location. There's one
that could be shared between the subscriptions and here due to having
the same signature, but I'm not sure there are any others that would
really benefit from cross-file sharing.
2023-08-17 23:46:08 -07:00
4a7635fa7b nats-c.build.zig: fix cross-compiling from Linux
There is a case-sensitivity issue here. The Windows documentation calls
the library Ws2_32, but the mingw cross-compilation on Linux fails
unless it is called `ws3_32`. For some reason, both work on macOS. I
have not tried on Windows, but I assume this will probably work there
due to everything being extremely insensitive (case-wise) on Windows.
2023-08-16 23:30:04 -07:00
3cf173c923 nats: wrap a couple of loose functions
These are probably not useful at all at the moment, but they were
trivial to do.
2023-08-16 21:33:02 -07:00
3ced6db69d message: play around with unit testing
I think I am probably going to move unit tests to a separate
directory/file structure. This will allow me to add a bunch of utility
functions that don't get analyzed for the library compilation and also
avoid testing-only imports in the main modules.
2023-08-15 22:23:35 -07:00
970d274593 nats: fix typo'd C api call 2023-08-15 22:23:35 -07:00
55690ced02 subscription: wrap all basic API calls
Hopefully I am not missing anything here. Will need to comb through the
public API to make sure no calls are missing.
2023-08-15 22:23:35 -07:00
94a428139d message: wrap all basic API calls
The streaming API is not wrapped because we do not build nats.c with
the necessary libraries. The jetstream API is not wrapped because I am
extremely lazy and it's outside of the minimum viable scope at the
moment. It can happen after the other basic APIs have been wrapped.
2023-08-15 22:23:35 -07:00
b55dfe0732 subscription: remove dangling old implementation
Missed this before the commit train left the station.
2023-08-15 20:11:57 -07:00
79a45fd2e3 git subrepo clone (merge) --branch=v3.6.1 https://github.com/nats-io/nats.c.git deps/nats.c
subrepo:
  subdir:   "deps/nats.c"
  merged:   "66cec7f"
upstream:
  origin:   "https://github.com/nats-io/nats.c.git"
  branch:   "v3.6.1"
  commit:   "66cec7f"
git-subrepo:
  version:  "0.4.6"
  commit:   "b8b46501e"
2023-08-15 00:21:33 -07:00
5bc936a09f deps: remove nats.c submodule
I'm going to try out git-subrepo. The main reason for this is that
github's autogenerated tarballs do not include submodules. And
github's autogenerated tarballs are the easiest way to integrate into
the zig package manager. Since git-subrepo checks the files into the
tree directly, new tarballs should include this dependency code.
2023-08-15 00:16:05 -07:00