GenrikhFetischev / async_uws

It's async http and websocket rust server built on top of uWebSockets
7 stars 2 forks source link

feat: reduce manual configuration for frictionless usage #3

Open YassinEldeeb opened 10 months ago

YassinEldeeb commented 10 months ago

This is a followup issue for #2

Issue Description

Currently, users of the async_uws crate must manually install and configure system dependencies such as libuv, OpenSSL, and the appropriate C++ standard libraries. This process is not only cumbersome but also error-prone, leading to a steep usage curve and potential frustration, particularly on macOS where the system libraries differ from the Linux defaults.

Also, for open source libraries depending on this, it forces CI and other users to also deal with these system dependencies issues.

Potential Improvements

Automated Dependency Management: Implement a build workflow to automatically download, build, and link against the correct version of libuv and other dependencies.

Static Linking of Bundled Libraries: Include the source of libuv within the crate and statically link it during the build process, removing the need for users to have libuv installed on their systems.

Conditional Compilation: Enhance the build.rs script to conditionally compile and link dependencies based on the target OS and architecture, ensuring that the correct libraries and flags are used.

Documentation: Update the README and documentation to provide clear guidance on the build process, and include steps to troubleshoot common build errors. I have done that, but I don't feel good about users dealing with OS specific configuration. Check #4

CI/CD Pipeline: Set up a CI/CD pipeline to pre-compile and test the library across different platforms, ensuring the build script works as intended in various environments.

Goals

The ultimate goal of these improvements is to make async_uws as accessible as possible, much like uWebsockets.js, by minimizing the friction for new users to get started, regardless of their operating system. By abstracting away the complexities of the build and installation process, we can lower the barrier to entry and welcome more of the rust community to the incredible performance of uWS.

Would love to discuss more with you @GenrikhFetischev!

artokun commented 10 months ago

Here are the steps I took to get it building on both MacM1 and Linux

Mac

brew install zlib
brew install libuv
brew install openssl

Also add these to your .zshrc or .bashrc:

export OPENSSL_INCLUDE_DIR=$(brew --prefix openssl)/include
export DEP_OPENSSL_INCLUDE=$(brew --prefix openssl)/include
export OPENSSL_LIB_DIR=$(brew --prefix openssl)/lib
export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH
export CPATH=/opt/homebrew/include:$CPATH

Linux

sudo apt-get update
sudo apt-get install zlib1g-dev
sudo apt-get install libuv1-dev
sudo apt-get install libssl-dev
sudo apt-get install libcrypto++-dev
GenrikhFetischev commented 10 months ago

Hello @YassinEldeeb!

Firstly, thanks for sharing your ideas; I think your suggestions are reasonable. Actually, I had thoughts very similar to yours and planned to start with a more proper readme, but thanks to you, it's already done.

Speaking of shipping all the necessary dependencies with the crate - I agree, it could be a good option. To discuss that possibility, let me share a bit about the dependencies hierarchy here. I've built libuwebsockets-sys crate, which is bindings to uWebSocket C API. Then, on top of libuwebsockets-sys, I've made uwebsockets_rs - an HTTP/WebSocket server (without async runtime) that provides almost exactly the same API as the original uWebSockets. Finally, this package, async_uws, is written on top of uwebsocket_rs.

Crate libuwebsocket-sys provides the feature uws_vendored which makes it build the uWebSockets library and link it.

Probably, libuwebsockets-sys could expand or uwebsockets_rs could have the list of features and provide vendored libuv, crypto, etc., rather than doing it right in async_uws.

ramiroaisen commented 2 months ago

Here are the steps I took to get it building on both MacM1 and Linux

Mac

brew install zlib
brew install libuv
brew install openssl

Also add these to your .zshrc or .bashrc:

export OPENSSL_INCLUDE_DIR=$(brew --prefix openssl)/include
export DEP_OPENSSL_INCLUDE=$(brew --prefix openssl)/include
export OPENSSL_LIB_DIR=$(brew --prefix openssl)/lib
export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH
export CPATH=/opt/homebrew/include:$CPATH

Linux

sudo apt-get update
sudo apt-get install zlib1g-dev
sudo apt-get install libuv1-dev
sudo apt-get install libssl-dev
sudo apt-get install libcrypto++-dev

Any ideas of the necesary packages for RPM based distros? trying to compile in fedora 39, I couldn't find some of the packages