fluent / fluent-bit

Fast and Lightweight Logs and Metrics processor for Linux, BSD, OSX and Windows
https://fluentbit.io
Apache License 2.0
5.71k stars 1.56k forks source link

Unable to build `flb-wamrc` #7580

Open andresperezl opened 1 year ago

andresperezl commented 1 year ago

Bug Report

Describe the bug Failing to build fluent-bit with flb-wamrc, with cmake .. -DFLB_WAMRC=On, after running make I see this error:

make[2]: *** No rule to make target '/usr/lib/llvm-14/lib/libMLIRSupportIndentedOstream.a', needed by 'bin/flb-wamrc'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:7775: src/wamrc/CMakeFiles/flb-wamrc-bin.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

To Reproduce

Expected behavior

It should successfully built the fluent-bit and flb-wamrc binaries

Screenshots

Your Environment

Additional context

patrick-stephens commented 1 year ago

@cosmo0920 I presume some extra dependencies or config is required here? It looks like @andresperezl that this is not enabled by default: https://github.com/fluent/fluent-bit/blob/1d366594a889624ec3003819fe18588aac3f17cd/CMakeLists.txt#L143

I'm a little confused though by your target - you mention WSL2 and Ubuntu 22 so it would be good to clarify? We probably want to reproduce with the containerised builds for Ubuntu 22 just to control all dependencies and make it easier to reproduce too: https://github.com/fluent/fluent-bit/blob/1d366594a889624ec3003819fe18588aac3f17cd/packaging/distros/ubuntu/Dockerfile#L100-L109

If you edit that Dockerfile to add in the extra flag (or modify CMakeLists.txt to default it on) then it's just a call to build like so: ./packaging/build.sh -d ubuntu/22.04

andresperezl commented 1 year ago

you mention WSL2 and Ubuntu 22 so it would be good to clarify?

WSL2 as in Windows Subsystem for Linux ver. 2, using Ubuntu 22 as the OS.

It looks like @andresperezl that this is not enabled by default:

Shouldn't the -DFLB_WAMRC=On option that I'm passing, enable it when running cmake?

patrick-stephens commented 1 year ago

Shouldn't the -DFLB_WAMRC=On option that I'm passing, enable it when running cmake?

It will do yes when you directly build it.

I was talking about reproducing it via the official packaging process we use for Ubuntu 22 though which is containerised - it will make it easier to figure out issues for me certainly (I have no WSL2 access or details of the delta in dependencies or otherwise between Ubuntu 22 on that and the version we build with).

andresperezl commented 1 year ago

I ran the ./packaging/build.sh -d ubuntu/22.04 script first without any modifications to double check that it will pass in my system and it did.

Then I modified the Dockerfile with:

diff --git a/packaging/distros/ubuntu/Dockerfile b/packaging/distros/ubuntu/Dockerfile
index 40272f8fc..dd874b12a 100644
--- a/packaging/distros/ubuntu/Dockerfile
+++ b/packaging/distros/ubuntu/Dockerfile
@@ -104,7 +104,7 @@ ENV DEBIAN_FRONTEND noninteractive
 RUN apt-get update && \
     apt-get install -y curl ca-certificates build-essential libsystemd-dev \
     cmake make bash wget unzip nano vim valgrind dh-make flex bison \
-    libpq-dev postgresql-server-dev-all libpq5 \
+    libpq-dev postgresql-server-dev-all libpq5 llvm \
     libsasl2-2 libsasl2-dev openssl libssl-dev libssl3 libyaml-dev pkg-config zlib1g-dev && \
     apt-get install -y --reinstall lsb-base lsb-release

@@ -146,6 +146,7 @@ ARG FLB_OUT_KAFKA=On
 ARG FLB_OUT_PGSQL=On
 ARG FLB_JEMALLOC=On
 ARG FLB_CHUNK_TRACE=On
+ARG FLB_WAMRC=On

 ENV CFLAGS=$CFLAGS
 RUN cmake -DCMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" \
@@ -159,6 +160,7 @@ RUN cmake -DCMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" \
     -DFLB_NIGHTLY_BUILD="$FLB_NIGHTLY_BUILD" \
     -DFLB_JEMALLOC="${FLB_JEMALLOC}" \
     -DFLB_CHUNK_TRACE="${FLB_CHUNK_TRACE}" \
+    -DFLB_WAMRC="${FLB_WAMRC}" \
     ../

 VOLUME [ "/output" ]

Added the llvm package that is needed according to the docs, with unsuccessful results:

+ docker run -v /[redacted]/fluent-bit/packaging/packages/ubuntu/22.04/2023-06-19-08_57_23/:/output flb-ubuntu/22.04
+ echo 'Could not compile using image flb-ubuntu/22.04'
Could not compile using image flb-ubuntu/22.04
+ exit 1

I manually run the make command within the created image and get the same error:

docker run -ti -v /[redacted]/fluent-bit/packaging/packages/ubuntu/22.04/2023-06-19-09_04_18/:/output flb-ubuntu/22.04 /bin/bash
root@cc2d1fb86a64:/tmp/fluent-bit/build# make -j4
# truncated ...
make[2]: *** No rule to make target '/usr/lib/llvm-14/lib/libMLIRSupportIndentedOstream.a', needed by 'bin/flb-wamrc'.  Stop.
andresperezl commented 1 year ago

I was able to make it work by installing additional missing dependencies:

diff --git a/packaging/distros/ubuntu/Dockerfile b/packaging/distros/ubuntu/Dockerfile
index 40272f8fc..95ff9b0bb 100644
--- a/packaging/distros/ubuntu/Dockerfile
+++ b/packaging/distros/ubuntu/Dockerfile
@@ -105,6 +105,7 @@ RUN apt-get update && \
     apt-get install -y curl ca-certificates build-essential libsystemd-dev \
     cmake make bash wget unzip nano vim valgrind dh-make flex bison \
     libpq-dev postgresql-server-dev-all libpq5 \
+    llvm libmlir-14-dev libclang-common-14-dev libedit-dev libpfm4-dev \
     libsasl2-2 libsasl2-dev openssl libssl-dev libssl3 libyaml-dev pkg-config zlib1g-dev && \
     apt-get install -y --reinstall lsb-base lsb-release

@@ -146,6 +147,7 @@ ARG FLB_OUT_KAFKA=On
 ARG FLB_OUT_PGSQL=On
 ARG FLB_JEMALLOC=On
 ARG FLB_CHUNK_TRACE=On
+ARG FLB_WAMRC=On

 ENV CFLAGS=$CFLAGS
 RUN cmake -DCMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" \
@@ -159,6 +161,7 @@ RUN cmake -DCMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" \
     -DFLB_NIGHTLY_BUILD="$FLB_NIGHTLY_BUILD" \
     -DFLB_JEMALLOC="${FLB_JEMALLOC}" \
     -DFLB_CHUNK_TRACE="${FLB_CHUNK_TRACE}" \
+    -DFLB_WAMRC="${FLB_WAMRC}" \
     ../

 VOLUME [ "/output" ]

And the content of the generated .deb file:

drwxr-xr-x root/root         0 2023-06-19 11:12 ./etc/
drwxr-xr-x root/root         0 2023-06-19 11:12 ./etc/fluent-bit/
-rw-r--r-- root/root      2444 2023-06-15 13:27 ./etc/fluent-bit/fluent-bit.conf
-rw-r--r-- root/root      5508 2023-06-15 13:27 ./etc/fluent-bit/parsers.conf
-rw-r--r-- root/root        45 2023-06-15 13:27 ./etc/fluent-bit/plugins.conf
drwxr-xr-x root/root         0 2023-06-19 11:12 ./lib/
drwxr-xr-x root/root         0 2023-06-19 11:12 ./lib/fluent-bit/
-rw-r--r-- root/root  44937376 2023-06-19 11:12 ./lib/fluent-bit/libfluent-bit.so
drwxr-xr-x root/root         0 2023-06-19 11:12 ./lib/systemd/
drwxr-xr-x root/root         0 2023-06-19 11:12 ./lib/systemd/system/
-rw-r--r-- root/root       360 2023-06-19 11:08 ./lib/systemd/system/fluent-bit.service
drwxr-xr-x root/root         0 2023-06-19 11:12 ./opt/
drwxr-xr-x root/root         0 2023-06-19 11:12 ./opt/fluent-bit/
drwxr-xr-x root/root         0 2023-06-19 11:12 ./opt/fluent-bit/bin/
-rwxr-xr-x root/root 108610520 2023-06-19 11:10 ./opt/fluent-bit/bin/flb-wamrc
-rwxr-xr-x root/root  44870040 2023-06-19 11:11 ./opt/fluent-bit/bin/fluent-bit
patrick-stephens commented 1 year ago

Great, please submit a PR if you can so we can add them.

andresperezl commented 1 year ago

I started with the docs update at https://github.com/fluent/fluent-bit-docs/pull/1136, is that enough? Or do you want to change the packaging scripts as well to include flb-wamrc by default when building fluent-bit ?

cosmo0920 commented 1 year ago

Thanks for registering the doc PR. Yes, users have to install additional dependencies to build flb-wamrc that is an optimizer ahead of time compiler for Wasm programs. Should we add configurations and dependencies in Dockerfiles for package creations, @patrick-stephens ?

patrick-stephens commented 1 year ago

Probably not until we actually enable it by default but we could put it all on a single PR to have ready and help people.

We could add dependencies to the package building containers now as it won't impact the final deliverables but not the container as it'll mean extra libraries for no reason.

cosmo0920 commented 1 year ago

Okey. I understand. It makes sense for now.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the exempt-stale label.