75 Commits

Author SHA1 Message Date
928a10e880
deps: update nats.c to 3.9.3 2025-03-13 22:11:30 -06:00
fbd6e7af0c
all: update for zig 0.14.0
Support for earlier zig versions has been dropped.
2025-03-13 21:24:37 -06:00
3b5412b035
deps: update nats.c to 3.9.1
This also brings in libressl-portable 4.0.0.
2024-12-05 22:59:28 -07:00
ccf0f504a1
deps: update nats.c to 3.8.2+1
This fixes building with current zig 0.14-dev due to updating the
transitive libsodium dependency.
2024-10-14 22:02:49 -06:00
c82911682e
thunk: rework handling of userdata
A number of cases were not handled properly: even though optional
userdata was allowed, the handling would cause unreachable to be
reached if null handles were actually passed. Also, being able to use
void to specify "no userdata please" is useful; however, in this case
we do have to still pass NULL to the C library calls.

The casting logic has been pulled out to some helper functions, which
make it more consistent. Some mediocre additional test coverage has
been added as well.
2024-10-01 23:55:04 -07:00
68a98232a1
thunk: add 0.14-dev compatibility shim
Various type definitions in std.builtin got renamed to avoid field/decl
collisions as was required for the implementation of decl literals.
Since this is the only thing busted, shim it and retain cross-version
support for now.
2024-09-15 21:08:40 -07:00
5c340bef56
deps: use allyourcodebase build wrappers instead of vendored deps
This updates the nats.c library version to 3.8.2 and the libressl
version to 3.9.2. It's more build system than ever.
2024-09-15 21:05:53 -07:00
74bbe30d0a
all: update for zig-0.13
This is mainly updates to the build system, but there were a couple of
stdlib changes for the tests. The build system does include handling
more properly now as well, I think. It has fewer hacks, at least.
2024-06-18 20:44:26 -07:00
ff3782ce27
build: update for zig-0.12.0 2024-05-12 23:44:56 -07:00
f742ee1a85
build.zig.zon: match the project name 2024-04-06 15:35:19 -07:00
7db55e9ac9
subscription: fix setCompletionCallback
This was not being tested, and it was really broken. Now it is being
tested and it is no longer broken.
2024-04-06 15:34:38 -07:00
73fccb4662
all: allow passing more types of pointers as callback userdata
By performing more pointer casting gymnastics, additional types of
pointer can be supported. For example, now const qualified pointers
can be passed through thanks to the use of constCast. Also, having
explicit ptrCast allows nested pointers (e.g. a pointer to a slice,
such as `*[]const u8`) to be passed as userdata as well (the compiler
refuses to coerce a pointer to a pointer to `?*anyopaque` for some
reason, I guess because maybe it's ambiguous somehow?) Hopefully this
extra casting does not appreciably reduce the compiler's ability to
catch real bugs (for example, on a 64-bit machine, ptrCast can convert
a *u64 into a **u64 because there is no alignment change).

Also, the `volatile` pointer specifier is still not supported.
`allowzero` pointers probably also have a problem. Those are both
extreme edge cases, however.

This was intended to work before but did not due to an oversight.
Specifically, because the userdata pointers are stored as ?*anyopaque,
which does *not* have the const qualifier, they must have their const
qualifiers also removed. This is safe because the thunk guarantees
that the consumer code never sees the non-const version of the
pointer, and the nats library itself does nothing except pass the
pointer through to the user callback.

The tests have been updated to ensure this case works. The examples
still use a mutable userdata pointer to show that that case also
works. More tests could be added for the sake of increased rigor, but
I don't think it adds much.
2024-04-06 15:34:38 -07:00
42d0b24710
thunk: fix slightly confusing compile errors
The error messages not on the slice detection code path should not be
talking about slices.
2024-04-06 15:01:03 -07:00
b17a3fba6c
readme: update zig support status 2024-01-15 16:30:26 -08:00
4124b912eb
build: update for zig-0.12.0-dev.2208+4debd4338
Incorporate various build API changes. Hopefully there won't be any
other major API changes before the 0.12.0 release.
2024-01-15 16:23:45 -08:00
3462b3cdb6
all: don't automatically convert userdata types to pointer types
One of the things I have done a better job of internalizing while
working with zig over the last few months is that the less magic that
exists, the better. In the case of parameterized functions, this means
that it is much better to restrict the range of types that are
permitted to be passed than to perform type manipulation. In other
words, it's more confusing to see a function that is parameterized
with `SomeType` taking a pointer to that type than having it be
parameterized directly to take the pointer. Obviously there are
exceptions to this rule, like std.mem.eql taking slices of its
parameterized type.

In fact, this new approach fixes some edge cases. Null userdata may now
be passed in, since the user can now actually specify an optional
pointer type (e.g. `?*void` may be used to provide always-null
userdata). Additionally, a pointer to a constant value can now be
passed in, which wasn't possible before (this could have been worked
around by use of constCast and being careful, but that's an
exceedingly bad option compared to having the type system work for
you).
2024-01-01 15:20:06 -08:00
b28a91b97f
tests: add shell script for generating keys
This may be useful later.
2023-11-07 22:55:08 -08:00
c6764fcf60
readme: some minor updates 2023-11-07 20:54:59 -08:00
c18e1eb237
deps: update libressl to 3.8.2 2023-11-07 20:54:00 -08:00
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