logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS Twitter


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Third-party Modules View previous topic :: View next topic
Reply to topic   Topic: Introducing mod_wasm
Author
gzurl



Joined: 13 Dec 2022
Posts: 6

PostPosted: Tue 13 Dec '22 17:55    Post subject: Introducing mod_wasm Reply with quote

Download on the VS17 download page

Hello Apache Lounge folks!
I’m Jesús González, and I am part of VMware’s Wasm Labs, a group focused on creating open-source tools for WebAssembly (Wasm).

We have created mod_wasm, an Apache module for running WebAssembly binaries inside httpd, and we are working with the ASF to contribute it upstream.

In our GitHub repo https://github.com/vmware-labs/mod_wasm you can find a quick demo for both Python and PHP Wasm binaries.

The hello_wasm demo is as simple as:
Code:
LoadModule wasm_module modules/mod_wasm.so

<Location /hello-wasm>
  SetHandler wasm-handler
  WasmModule /var/www/modules/hello_wasm.wasm
</Location>


We would need your help to ensure mod_wasm can also run on Windows.
Could you please point us in the right direction? We are still figuring out whether a module like mod_wasm (with a Rust dependency) can run directly on Windows (as a .so) or if it would require a special build.

Cheers!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7169
Location: Germany, Next to Hamburg

PostPosted: Wed 14 Dec '22 10:12    Post subject: Reply with quote

Hello Jesús,
since it is a single C file you may take a look at how mod_log_rotate is compiled against the binaries from ApacheLounge https://github.com/JBlond/mod_log_rotate/blob/master/build.md

if there is still a question please ask again.
Back to top
gzurl



Joined: 13 Dec 2022
Posts: 6

PostPosted: Fri 16 Dec '22 0:54    Post subject: Reply with quote

Thanks for your feedback, James!
The insight about mod_log_rotate was very useful Very Happy

I managed to add the missing parts in the example and build both libraries mod_wasm.so and wasm_runtime.dll. They worked perfectly under the httpd-2.4.54-win64-VS17 provided by Apache Lounge Cool

Compile (mod_wasm.c --> mod_wasm.obj):
Code:
"c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo /MD /O2 /LD /W3 -DWIN32 -D_WIN32 -I%APACHE%\include -I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\um" -I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\shared" -I"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include" -I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\ucrt" -I"%WASM_RUNTIME%\include" /c /Fomod_wasm.obj mod_wasm.c

Link (mod_wasm.obj --> mod_wasm.so):
Code:
"c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe" "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x64\kernel32.lib" "%APACHE%\lib\libhttpd.lib" "%APACHE%\lib\libapr-1.lib" "%APACHE%\lib\libaprutil-1.lib" "%WASM_RUNTIME%\target\release\wasm_runtime.dll.lib" /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\ucrt\x64" /nologo /subsystem:windows /dll /out:mod_wasm.so mod_wasm.obj


We would be extremely happy if you decide to include mod_wasm for Windows in your Download section Mr. Green

Thanks!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7169
Location: Germany, Next to Hamburg

PostPosted: Fri 16 Dec '22 9:19    Post subject: Reply with quote

it would be nice if you could add the windows compiling steps to https://github.com/vmware-labs/mod_wasm/tree/main/mod_wasm
Back to top
Xing



Joined: 26 Oct 2005
Posts: 49

PostPosted: Fri 16 Dec '22 9:45    Post subject: Reply with quote

How to build wasm_runtime.dll ?
Back to top
gzurl



Joined: 13 Dec 2022
Posts: 6

PostPosted: Fri 16 Dec '22 13:23    Post subject: Reply with quote

Hi,

@James, nice feedback. Windows build instructions are now included at https://github.com/vmware-labs/mod_wasm/tree/main/mod_wasm

@Xing, Rust will automatically target the host platform. You can find detailed instructions here: https://github.com/vmware-labs/mod_wasm/tree/main/wasm_runtime

Hope this helps!
Back to top
Xing



Joined: 26 Oct 2005
Posts: 49

PostPosted: Sat 17 Dec '22 11:37    Post subject: Reply with quote

Followed the steps at https://github.com/vmware-labs/mod_wasm/tree/main/wasm_runtime

All fine with cargo install cbindgen.

Changed to the wasm_runtime folder.

Then what to do ? make all not recognized as command.
Back to top
Xing



Joined: 26 Oct 2005
Posts: 49

PostPosted: Sat 17 Dec '22 12:20    Post subject: Reply with quote

Ah builds the .dll

In x64 command prompt (vcvarsall.bat).

Changed to the wasm_runtime folder.

did only: cargo build --release

And surprise there is a wasm_runtime.dll in folder wasm_runtime\target\release
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2986
Location: Hilversum, NL, EU

PostPosted: Sat 17 Dec '22 15:11    Post subject: Reply with quote

Thanks! Xing for the pointers.

Jesus, is cargo build --release the good way to get the .dll ?

Was able to build.

Using Visual Studio 2022 Professional, in the compile/link above you are using community.

Tested with Hello Wasm ( https://github.com/vmware-labs/mod_wasm/tree/main/examples )

LoadModule wasm_module modules/mod_wasm.so
<Location /hello-wasm>
SetHandler wasm-handler
WasmModule C:\Apache24\modules/hello_wasm.wasm
</Location>

And get in de Browser : Hello, Wasm! @stdout
and in the Apache error.log : Hello, Wasm! @stderr

Have not yet figured out how to test with PHP ?
Back to top
gzurl



Joined: 13 Dec 2022
Posts: 6

PostPosted: Sat 17 Dec '22 23:24    Post subject: Reply with quote

Yes, as @Xing pointed out, running `cargo build --release` will generate the `wasm_runtime.dll` dependency needed to run mod_wasm.
The `make all` command (assuming Make is present), will in addition generate the C bindings from Rust using the cbindgen package. We are providing those bindings in the mod_wasm repo (`wasm_runtime.h`) so that is why executing just `cargo build --release` is enough.

@Steffen, I do believe both Visual Studio 2022 Professional and Community can be used. The key is to ensure dependencies are met (i.e.: MSVC C++ x64/x86 build tools and Windows SDK).
Regarding the examples you tried, `hello_wasm` worked as expected. For PHP, I identified an unexpected behavior and we are looking into it. It seems more related to the PHP Wasm build rather than mod_wasm itself. We'll keep you updated.

In the meantime, I'd suggest trying the Python examples instead with the following Apache configuration and this Python Wasm build: https://github.com/tiran/cpython-wasm-test/releases/download/v3.11.0/Python-3.11.0-wasm32-wasi-16.zip

Code:
<Location /http-request-viewer>   
        SetHandler wasm-handler
        WasmModule C:\mod_wasm-main\examples\wasm_modules\Python-3.11.0-wasm32-wasi-16\python.wasm
        WasmMapDir / C:\mod_wasm-main\examples\wasm_modules\Python-3.11.0-wasm32-wasi-16
        WasmMapDir /opt C:/mod_wasm-main/examples/wasm_modules
        WasmEnv    PYTHONHOME /opt/Python-3.11.0-wasm32-wasi-16/lib/python3.11
        WasmEnv    PYTHONPATH /opt/Python-3.11.0-wasm32-wasi-16/lib/python3.11
        WasmArg    /opt/python-scripts/http_request_viewer.py
        WasmEnableCGI On
    </Location>


Of course, you can modify all those directories at your convenience. Just make sure that both `PYTHONHOME` and `PYTHONPATH` point to the Python 3.11 libraries, and `WasmArg` contains the Python script to be run whose directory is contained in a `WasmMapDir` directive. I did try several Python scripts with mod_wasm in Windows successfully.

Looking forward to your feedback!
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2986
Location: Hilversum, NL, EU

PostPosted: Sun 18 Dec '22 15:27    Post subject: Reply with quote

When others want to test/use :

On the VS17 Download page.

Please comment !


Last edited by Steffen on Thu 22 Dec '22 10:52; edited 1 time in total
Back to top
gzurl



Joined: 13 Dec 2022
Posts: 6

PostPosted: Tue 20 Dec '22 21:00    Post subject: Reply with quote

Steffen,

Just tested your build and it worked for me! Mr. Green


Thanks!
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 2986
Location: Hilversum, NL, EU

PostPosted: Thu 22 Dec '22 10:58    Post subject: Reply with quote

Added to te VS17 download page https://www.apachelounge.com/download/
Back to top
gzurl



Joined: 13 Dec 2022
Posts: 6

PostPosted: Thu 22 Dec '22 13:21    Post subject: Reply with quote

These are great news! Thanks!

@Steffen, how do you want us to notify Apache Lounge for new mod_wasm releases? New topic in the forum with the new features/fixes?
Back to top
Beltran



Joined: 27 Jun 2013
Posts: 3
Location: Spain

PostPosted: Mon 16 Jan '23 19:14    Post subject: Reply with quote

Hi @Steffen, would be possible to have the mod_wasm extension for VS16? Thanks
Back to top
admin
Site Admin


Joined: 15 Oct 2005
Posts: 656

PostPosted: Mon 16 Jan '23 19:25    Post subject: Reply with quote

The VS17 version is compatible with VS16.
Back to top


Reply to topic   Topic: Introducing mod_wasm View previous topic :: View next topic
Post new topic   Forum Index -> Third-party Modules