As the ISAB team embarked on building a new module, they discovered valuable insights into how NGINX works and how to integrate it with Rust. This achievement was not without challenges, as NGINX documentation is primarily focused on modules written in C. Nonetheless, the team's perseverance in figuring out how to write an NGINX module in Rust yielded fruitful results.
The ISAB team made heavy use of code from the nginx-rs project, which facilitated the handling of buffers and memory pools. However, creating a complete NGINX module in Rust requires a long process that goes beyond the scope of this blog post. Nonetheless, there are several key bits worth mentioning that make the entire endeavor possible.
One critical aspect of building NGINX modules in Rust is understanding how NGINX works. Specifically, NGINX modules operate as dynamic libraries that can be loaded into NGINX at runtime. Therefore, an NGINX module needs to define several functions that NGINX calls when loading the module.
Another crucial component is understanding how to get NGINX to talk to Rust. The ISAB team achieved this by leveraging Rust's foreign function interface (FFI), which allows Rust code to be called from C code. By using the FFI, the ISAB team was able to call Rust code from NGINX, enabling seamless integration of Rust functionality within NGINX.
Finally, the handling of buffers and memory pools is another critical aspect of building NGINX modules in Rust. The team utilized the nginx-rs codebase, which provided an interface for dealing with memory pools and buffers, making it easier to manage memory in a way that works with NGINX.
In conclusion, the ISAB team's journey in building an NGINX module in Rust was full of valuable insights into how to integrate Rust and NGINX. By leveraging the nginx-rs codebase, utilizing Rust's FFI, and understanding how NGINX works, the team successfully built a new module. The ISAB team hopes that their experiences and insights can help other developers tackle similar challenges in the future.