summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)AuthorFilesLines
2023-08-30unit-wasm 0.2.0v0.2.0Andrew Clayton7-8/+8
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-30API-{C,Rust}.md: Note which version new functions were addedAndrew Clayton2-0/+10
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-30README.md: Update for missing mention of rust-hello-worldAndrew Clayton1-1/+2
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-30README.md: Add a link to API-Rust.mdAndrew Clayton1-1/+7
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-30examples/rust: Update for new API additionsAndrew Clayton2-7/+3
Update the echo-request and upload-reflector examples for the new uwr_http_add_header_content_type() and uwr_http_add_header_content_len() functions. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29examples/rust: Reduce the scope of an unsafe block in echo-requestAndrew Clayton1-3/+1
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29Rust/rusty: Make use of uwr_get_http_total_content_sent()Andrew Clayton1-1/+1
When the uwr_get_http_content_str() function, which returns the request body content as a string, was added it used uwr_get_http_content_len() to determine the length of the returned string (the request body content is not null-terminated). This could potentially in some circumstances return too much data if the request was split over multiple calls into the Wasm module and uwr_get_http_content_str() was called before all the data had actually been received. Instead use the newly introduced uwr_get_http_total_content_sent() function to determine the amount of data to return in the string as it currently stands. Fixes: bf968c9 ("Rust/rusty: Add uwr_get_http_content_str()") Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29Rust/rusty: Add a wrapper for luw_get_http_total_content_sent()Andrew Clayton2-0/+15
This returns the total amount of content that the Wasm module has received so far. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29Rust/rusty: Re-order some functions more logicallyAndrew Clayton1-8/+8
This may not matter in rust (if you use a function before the compiler has seen a definition for it), but anyway in preparation for adding a uwr_get_http_total_content_sent() function, put the content length related functions before the functions that return the content. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29libunit-wasm: Add a luw_get_http_total_content_sent() functionAndrew Clayton3-0/+18
This function returns the total amount of content that the Wasm module has received so far. This will be used in the rusty API's uwr_get_http_content_str() function which returns the body content as a string. Due to the body content not being null-terminated we need to know how much data to use for the string, for which we are currently using uwr_get_http_content_len(), which could in some cases return too much if a request is being split over multiple calls the module. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29examples/rust: Fix building of the hello world demoAndrew Clayton1-2/+2
When I renamed it from minimal to hello-world, it stopped being built due to the make target name being the same as the directory name (hello-world). Rename the make target to rust-hello-world which also matches the naming of the rest of the targets. Fixes: 656c036 ("examples/rust: Add a minimal hello world rust example") Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29examples/rust: Add a minimal hello world rust exampleAndrew Clayton5-3/+90
This is about the smallest it can be. Its Unit application config would look like "applications": { "rust-hello-world": { "type": "wasm", "module": "/path/to/unit-wasm/examples/rust/hello-world/target/wasm32-wasi/debug/rust_hello_world.wasm", "request_handler": "uwr_request_handler", "malloc_handler": "luw_malloc_handler", "free_handler": "luw_free_handler" } } Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29Rust/rusty: Add a couple of convenience functionsAndrew Clayton2-0/+45
This adds the following convenience functions for adding HTTP response headers, Content-Type & Content-length uwr_http_add_header_content_type(ctx: *mut luw_ctx_t, ctype: &str); uwr_http_add_header_content_len(ctx: *mut luw_ctx_t); These are perhaps the two most common headers so it makes sense to reduce the effort to adding them. E.g before uwr_http_add_header(&ctx, "Content-Type", "text/plain"); uwr_http_add_header( ctx, "Content-Length", &format!("{}", uwr_get_response_data_size(ctx)), ); after uwr_http_add_header_content_type(ctx, "text/plain"); uwr_http_add_header_content_len(ctx); Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29Rust/rusty: Add uwr_get_http_content_str()Andrew Clayton2-0/+21
This function is like uwr_get_http_content() except that it returns a Rust str. This is more convenient if you want to operate on the body content within Rust. It's worth noting that uwr_get_http_content() returns a non null terminated buffer which makes it tricky to work with in Rust. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29API-Rust.md: Add a note about luw_ vs uwr_ namingAndrew Clayton1-0/+16
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29Rust/rusty: Run rusty.rs through rustfmtAndrew Clayton1-6/+5
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29API-Rust.md: Tweak the uwr_http_add_header() exampleAndrew Clayton1-1/+1
Use uwr_get_response_data_size() instead of uwr_get_http_content_len() for the Content-Length, this is more appropriate as this will give the length of the response data rather than the request data. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28examples/rust: Update unit-wasm dependency versionAndrew Clayton2-2/+2
luw_http_add_header() no longer takes an idx argument. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Rust/unit-wasm: Version 0.1.2Andrew Clayton1-1/+1
luw_http_add_header() no longer takes an idx argument. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Rust/unit-wasm-sys: Version 0.1.4Andrew Clayton2-2/+2
luw_http_add_header() no longer takes an idx argument. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Rust/unit-wasm-sys: Re-generate the bindings on changes to unit-wasm.hAndrew Clayton1-1/+1
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28API-C.md: Fix a broken fragment linkAndrew Clayton1-1/+1
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28API-Rust.md: Add a Rust 'rusty' API documentAndrew Clayton1-0/+885
This was done by 'cp API-C.md API-Rust.md' and then adjusted as necessary. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Rust/rusty: Make a bunch of functions take ctx as constAndrew Clayton1-8/+8
The various uwr_get_ functions should take the context pointer as a const. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28libunit-wasm: Pass ctx into luw_http_hdr_get_value() as constAndrew Clayton4-5/+6
Technically the context pointer can be passed in const even though we then un-const it passing it to the luw_foreach_http_hdr() macro. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28libunit-wasm: Remove the idx argument from luw_http_add_header()Andrew Clayton8-19/+28
This was used to specify the index of the response header being added, starting at 0 and incrementing by one for each header. Instead of having the programmer specify this, track it internally. We add an extra check in luw_http_add_header() to make sure we aren't trying to add more headers than we said with luw_http_init_headers(), if we are, simply return. This updates the API-C.md and the various examples and 'rusty' API wrapper. Suggested-by: Liam Crilly <liam@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Revert "Adding echo Request with body Parsing"Andrew Clayton3-203/+0
This reverts commit 011c3ba3f7bc466a04101f81d4f6186001b7aad4. This was committed in error... Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Adding echo Request with body ParsingTimo Stark3-0/+203
2023-08-26README.md: Significant re-workingAndrew Clayton1-115/+141
This adds a new 'Setup a Suitable Environment' section that replaces the 'Getting Started' section and it's subsections. This provides a more comprehensive guide to setting up a suitable environment on some specific systems (currently Fedora/CentOS/RHEL etc & Debian/Ubuntu). Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26Makefile: Update the WASI_SYSROOT default descriptionAndrew Clayton1-1/+1
This now varies if your using Fedora or FreeBSD and have the right package installed. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26github/workflows: Simplify installation of libclang_rt.builtins-wasm32.aAndrew Clayton1-1/+1
Rather than using and rpm(8) and grep(1) to find the location to store the libclang_rt.builtins-wasm32.a file use clangs -print-runtime-dir option and strip the last component. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26examples/rust: Update unit-wasm dependency versionAndrew Clayton2-2/+2
This is for the new 'rusty' API. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26Rust/unit-wasm: Version 0.1.1Andrew Clayton1-1/+1
Bump the version for the 'rusty' API. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26Rust/unit-wasm-sys: Version 0.1.3Andrew Clayton2-2/+2
Bump the version for the 'rusty' API. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26examples/rust: Bump the versionsAndrew Clayton2-2/+2
Seeing as these are now using the 'rusty' API bump their versions to 0.2.0 Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26libunit-wasm: Fix rust buildAndrew Clayton3-3/+3
The rust build failed when trying to publish new crates, although for some reason it didn't fail before that, due to the luw_srb_flags_t enums generated by bindgen being 32 bit unsigned integers and the flags argument to luw_set_req_buf() being an unsigned long (which is 64 bits on my system) and thus producing a type mismatch error. Rather than fight with rust just make the flags argument an unsigned int, 32 bits is more than enough for this anyway. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26Rust/unit-wasm-sys: Don't require the wasi-sysrootAndrew Clayton1-3/+0
When I added the luw_http_hdr_get_value() function I needed to include strings.h, unfortunately I added it to unit-wasm.h instead of libunit-wasm.c This then meant that we needed to point bindgen/clang, for generating the bindings, to the wasi-sysroot for the strings.h file. I guess this is a system dependant include or something and when we use the wasm32-wasi target in clang it uses a paired down include search path list, none of which have strings.h This then had the knock on effect of requiring to inform cargo build of the wasi-sysroot path. Now that we put strings.h in the right place, we don't need the wasi-sysroot when building the rust stuff. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26libunit-wasm: Include strings.h in the right fileAndrew Clayton2-1/+1
When I added the luw_http_hdr_get_value() function I needed to include strings.h, unfortunately I added it to unit-wasm.h instead of libunit-wasm.c This had the undesirable effect of requiring the wasi-sysroot when building the rust stuff for generating the libunit-wasm rust bindings. By including strings.h in the right file we get rid of that requirement which a subsequent commit will take care of. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26Rust/unit-wasm-sys: Remove reference to wrapper.h from build.rsAndrew Clayton1-1/+0
There is no wrapper.h in the repository. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26Rust/unit-wasm-sys: Run build.rs through rustfmtAndrew Clayton1-3/+4
This in preparation for some upcoming changes. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25README.md: Update the README and config exampleAndrew Clayton2-15/+15
This takes into account the recent porting of the Rust demo applications to the new 'rusty' wrappers. The updates relate to the function handler names, the ones provided by the application now use the uwr_ prefix, the malloc and free handlers are still using the luw_ prefix as the applications aren't providing their own versions of those, the ones from libunit-wasm will be used. This is a useful demonstration of a number of things, but ultimately that you can call these handlers anything you want. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25Rust: Port the Rust Wasm demos to the new 'rusty' wrappersAndrew Clayton2-239/+137
rusty is a thin wrapper over the generated libunit-wasm bindings to provide a more native rust like interface. This gets rid of all the casting and ugly string handling. It massively reduces the amount of unsafe {} blocks needed, though some still are... All in all this provides a nice code cleanup. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25Rust: Add a nicer wrapper around the libunit-wasm bindingsAndrew Clayton5-0/+225
This adds a nice wrapper (aka rusty) around the generated libunit-wasm bindings. This should provide a more native rust like experience with the following benefits - No casting. So no things like 'as *mut c_void' - Native rust strings. So no things like '.as_ptr() as *const c_char' - Better ctx initialisation. Filed initialisation is now hidden away - Great reduction in the amount of unsafe {} blocks required - Generally more compact There are also some new macros - C2S!() converts a CStr to a Str - S2C!() converts a formatted Str to a Cstr using format!() - uwr_write_str!() a wrapper around luw_mem_writep_data and format!() This wrapper uses a uwr (Unit Wasm Rust) prefix under a 'rusty' namespace. The luw_http_hdr_iter() function proved tricky to wrap and the callback function still takes C style arguments due to the fact that this function is called from the libunit-wasm C library. The provided wrapper simply means we can use this without having to use an unsafe {} block around it in application code. Similarly with other functions that technically didn't need to be wrapped, wrapping them means that the unsafe {} blocks are hidden away. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25Rust: Don't disable dead code warningsAndrew Clayton1-1/+0
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25Rust/unit-wasm-sys: Bump the version of the crateAndrew Clayton2-2/+2
unit-wasm-sys 0.1.2 Might as well do this now before the code changes and we bump the version again. This version was published to crates.io Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25README, conf: Use correct Rust echo-request nameAndrew Clayton2-6/+6
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-24libunit-wasm: Remove left over prototype from unit-wasm.hAndrew Clayton1-1/+0
There was a luw_destroy_ctx() function at one point and its prototype was still in the header file... Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-24libunit-wasm: Put LUW_SRB_FLAGS_ALL in the enumAndrew Clayton2-4/+6
No reason why this needed to be a separate #define. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-23github/workflows: No need to download the wasi-sysrootAndrew Clayton1-3/+2
The wasi-sysroot is now packaged by Fedora in the wasi-libc-devel & wasi-libc-static packages (just installing wasi-libc-devel should bring in the other if needed). We also no longer need bindgen-cli as we are building the rust stuff from within the build.rs files. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-23shared.mk: Ensure WASI_SYSROOT is exported to the environmentAndrew Clayton1-0/+2
If you don't have WASI_SYSROOT set in the shell and you don't specify it in the make command, then make will try and find the wasi-sysroot in some known locations and then set the WASI_SYSROOT accordingly. However in this case (no shell variable and not specified in the make command) then when it comes to building the rust stuff, cargo build fails when trying to generate the bindings as it needs the wasi-sysroot but doesn't pick it up from the shell environment. Fix this by exporting WASI_SYSROOT from shared.mk Signed-off-by: Andrew Clayton <a.clayton@nginx.com>