iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.85k stars 614 forks source link

Can't compile iree within conda environment: "error: expected parameter declarator" #17660

Open chudur-budur opened 5 months ago

chudur-budur commented 5 months ago

What happened?

I don't have admin access to the machine that I am working on. Therefore I was trying to build iree through conda environment.

I am compiling like this:

# Configure
cmake -G Ninja -B ../iree-build/ -S . \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DIREE_ENABLE_ASSERTIONS=ON \
    -DIREE_ENABLE_SPLIT_DWARF=ON \
    -DIREE_ENABLE_THIN_ARCHIVES=ON \
    -DCMAKE_C_COMPILER=$(which clang) \
    -DCMAKE_CXX_COMPILER=$(which clang++) \
    -DIREE_ENABLE_LLD=ON \
    -DIREE_TARGET_BACKEND_CUDA=OFF \
    -DIREE_HAL_DRIVER_CUDA=OFF

# Build
cmake --build ../iree-build/

But I am getting this error:

[192/7581] Building C object runtime/src/iree/base/CMakeFiles/iree_base_base.objects.dir/bitfield.c.o
FAILED: runtime/src/iree/base/CMakeFiles/iree_base_base.objects.dir/bitfield.c.o
/localdisk/$USER/opt/miniforge3/envs/iree-build/bin/clang  -I/localdisk/$USER/iree -I/localdisk/$USER/iree-build -I/localdisk/$USER/iree/runtime/src -I/localdisk/$USER/iree-build/runtime/src -O2 -g   -gsplit-dwarf -ggnu-pubnames -std=gnu11 -fPIC -fvisibility=hidden -Werror -Wall -Wno-error=deprecated-declarations -Wno-ambiguous-member-template -Wno-char-subscripts -Wno-extern-c-compat -Wno-gnu-alignof-expression -Wno-gnu-variable-sized-type-not-at-end -Wno-ignored-optimization-argument -Wno-invalid-offsetof -Wno-invalid-source-encoding -Wno-mismatched-tags -Wno-pointer-sign -Wno-reserved-user-defined-literal -Wno-return-type-c-linkage -Wno-self-assign-overloaded -Wno-sign-compare -Wno-signed-unsigned-wchar -Wno-strict-overflow -Wno-trigraphs -Wno-unknown-pragmas -Wno-unknown-warning-option -Wno-unused-command-line-argument -Wno-unused-const-variable -Wno-unused-function -Wno-unused-local-typedef -Wno-unused-private-field -Wno-user-defined-warnings -Wno-missing-braces -Wctad-maybe-unsupported -Wfloat-overflow-conversion -Wfloat-zero-conversion -Wfor-loop-analysis -Wformat-security -Wgnu-redeclared-enum -Wimplicit-fallthrough -Winfinite-recursion -Wliteral-conversion -Wnon-virtual-dtor -Woverloaded-virtual -Wpointer-arith -Wself-assign -Wstring-conversion -Wtautological-overlap-compare -Wthread-safety -Wthread-safety-beta -Wunused-comparison -Wvla -fno-lax-vector-conversions -fno-omit-frame-pointer -fmacro-prefix-map=/localdisk/$USER/iree=iree -pthread -MD -MT runtime/src/iree/base/CMakeFiles/iree_base_base.objects.dir/bitfield.c.o -MF runtime/src/iree/base/CMakeFiles/iree_base_base.objects.dir/bitfield.c.o.d -o runtime/src/iree/base/CMakeFiles/iree_base_base.objects.dir/bitfield.c.o -c /localdisk/$USER/iree/runtime/src/iree/base/bitfield.c
In file included from /localdisk/$USER/iree/runtime/src/iree/base/bitfield.c:7:
In file included from /localdisk/$USER/iree/runtime/src/iree/base/bitfield.h:11:
In file included from /localdisk/$USER/iree/runtime/src/iree/base/string_builder.h:13:
In file included from /localdisk/$USER/iree/runtime/src/iree/base/allocator.h:14:
/localdisk/$USER/iree/runtime/src/iree/base/alignment.h:35:15: error: expected parameter declarator
   35 | static_assert(sizeof(void*) == sizeof(uintptr_t),
      |               ^
/localdisk/$USER/iree/runtime/src/iree/base/alignment.h:35:15: error: expected ')'
/localdisk/$USER/iree/runtime/src/iree/base/alignment.h:35:14: note: to match this '('
   35 | static_assert(sizeof(void*) == sizeof(uintptr_t),
      |              ^
/localdisk/$USER/iree/runtime/src/iree/base/alignment.h:35:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
   35 | static_assert(sizeof(void*) == sizeof(uintptr_t),
      | ^
      | int
3 errors generated.

Steps to reproduce your issue

Setup a conda/mamba env

> mamba create -n iree-build python=3.11
> mamba activate iree-build

Install compiler

> mamba install -c conda-forge clangxx lld libgcc-devel_linux-64 cmake ninja 

List packages

> mamba list
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
binutils_impl_linux-64    2.40                 ha1999f0_3    conda-forge
bzip2                     1.0.8                hd590300_5    conda-forge
c-ares                    1.28.1               hd590300_0    conda-forge
ca-certificates           2024.6.2             hbcca054_0    conda-forge
clang                     18.1.7          default_h90ac42e_0    conda-forge
clang-18                  18.1.7          default_h9bb3924_0    conda-forge
clangxx                   18.1.7          default_h127d8a8_0    conda-forge
cmake                     3.29.5               hcafd917_0    conda-forge
icu                       73.2                 h59595ed_0    conda-forge
kernel-headers_linux-64   2.6.32              he073ed8_17    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.21.2               h659d440_0    conda-forge
ld_impl_linux-64          2.40                 hf3520f5_3    conda-forge
libclang-cpp18.1          18.1.7          default_h9bb3924_0    conda-forge
libcurl                   8.8.0                hca28451_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 hd590300_2    conda-forge
libexpat                  2.6.2                h59595ed_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-devel_linux-64     13.2.0             hdb50d1a_108    conda-forge
libgcc-ng                 13.2.0               h77fa898_8    conda-forge
libgomp                   13.2.0               h77fa898_8    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
libllvm18                 18.1.7               hb77312f_0    conda-forge
libnghttp2                1.58.0               h47da74e_1    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libsqlite                 3.46.0               hde9e2c9_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx-devel_linux-64  13.2.0             hdb50d1a_108    conda-forge
libstdcxx-ng              13.2.0               hc0a3c3a_8    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libuv                     1.48.0               hd590300_0    conda-forge
libxcrypt                 4.4.36               hd590300_1    conda-forge
libxml2                   2.12.7               hc051c1a_1    conda-forge
libzlib                   1.3.1                h4ab18f5_1    conda-forge
lld                       18.1.7               h67e2958_0    conda-forge
ncurses                   6.5                  h59595ed_0    conda-forge
ninja                     1.12.1               h297d8ca_0    conda-forge
openssl                   3.3.1                h4ab18f5_0    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
python                    3.11.9          hb806964_0_cpython    conda-forge
readline                  8.2                  h8228510_1    conda-forge
rhash                     1.4.4                hd590300_0    conda-forge
setuptools                70.0.0             pyhd8ed1ab_0    conda-forge
sysroot_linux-64          2.12                he073ed8_17    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zstd                      1.5.6                ha6fb4c9_0    conda-forge

Configure and compile

> cd iree
> mkdir ../iree-build
> cmake -G Ninja -B ../iree-build/ -S . \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DIREE_ENABLE_ASSERTIONS=ON \
    -DIREE_ENABLE_SPLIT_DWARF=ON \
    -DIREE_ENABLE_THIN_ARCHIVES=ON \
    -DCMAKE_C_COMPILER=$(which clang) \
    -DCMAKE_CXX_COMPILER=$(which clang++) \
    -DIREE_ENABLE_LLD=ON \
    -DIREE_TARGET_BACKEND_CUDA=OFF \
    -DIREE_HAL_DRIVER_CUDA=OFF

> cmake --build ../iree-build/

What component(s) does this issue relate to?

Other

Version information

831da7c

Additional context

No response

stellaraccident commented 5 months ago

At a guess, this is either related to the c compiler version used or the standard library that comes with your OS.

I don't know anything about conda. Can you please confirm clang --version with the clang and clang++ binary you are passing to configure. Also your OS.

It seems likely that something about system headers on your system is causing assert.h to not be available in this source file. For a quick fix, you can try adding #include <assert.h> to alignment.h. It is possible that on other systems it is being picked up transitively. If that fixes it, we can just land that change.

See: https://en.cppreference.com/w/c/language/_Static_assert

chudur-budur commented 5 months ago

At a guess, this is either related to the c compiler version used or the standard library that comes with your OS.

gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I don't know anything about conda. Can you please confirm clang --version with the clang and clang++ binary you are passing to configure. Also your OS.

clang --version
clang version 18.1.7 (https://github.com/conda-forge/clangdev-feedstock 1b91969d0c6b64ef555f9c04fc02d7758335f4b3)
Target: x86_64-conda-linux-gnu
Thread model: posix
InstalledDir: /localdisk/$USER/opt/miniforge3/envs/iree-build/bin
Configuration file: /localdisk/$USER/opt/miniforge3/envs/iree-build/bin/x86_64-conda-linux-gnu-clang.cfg
clang++ --version
clang version 18.1.7 (https://github.com/conda-forge/clangdev-feedstock 1b91969d0c6b64ef555f9c04fc02d7758335f4b3)
Target: x86_64-conda-linux-gnu
Thread model: posix
InstalledDir: /localdisk/$USER/opt/miniforge3/envs/iree-build/bin
Configuration file: /localdisk/$USER/opt/miniforge3/envs/iree-build/bin/x86_64-conda-linux-gnu-clang++.cfg
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS"

It seems likely that something about system headers on your system is causing assert.h to not be available in this source file. For a quick fix, you can try adding #include <assert.h> to alignment.h. It is possible that on other systems it is being picked up transitively. If that fixes it, we can just land that change.

I just checked, #include <assert.h> is already in runtime/src/iree/base/alignment.h

See: https://en.cppreference.com/w/c/language/_Static_assert

If we look at the compilation command, it's using -std=gnu11, but the above link says static_assert() is supported after C23. So shouldn't we use -std=c23 instead? Or maybe just use _Static_assert() there?

stellaraccident commented 5 months ago

It's tricky: it becomes a keyword in c23 but it's define'd in assert.h until then.

I suspect this is trying to be compatible as both a c and c++ header. This is weird. We compile regularly on both ununtu 22.04 (although CI is older) and clang (an old version on CI but a lot of use of newer). But we probably don't have much/any use of clang 18 yet, and maybe there is a compatibility issue. Someone will need to investigate.

If you want the easy way to unblock immediately, you will likely have better success with GCC or an older version of clang but I'm just guessing until someone can look at this more.

Thanks for the issue report: it seems there is a recent breakage here.

chudur-budur commented 5 months ago

If you want the easy way to unblock immediately, you will likely have better success with GCC or an older version of clang but I'm just guessing until someone can look at this more.

I have tried with older version of clang (15, 16, 17) and getting the same error. I think it's the problem with how conda (or x86_64-conda-linux-gnu package) manages all the c/c++ headers. Maybe I should ditch conda altogether and try it on a fresh system (i.e. docker).