exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
15.01k stars 517 forks source link

PATH_MAX undefined building the llvm-17 branch #504

Closed marioroy closed 9 months ago

marioroy commented 10 months ago

There are three errors on Linux building the llvm-17 branch.

/data1/codon-17/codon/parser/common.cpp:177:19: error: use of undeclared identifier 'PATH_MAX'
  177 |       char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX];
      |                   ^
/data1/codon-17/codon/parser/common.cpp:177:44: error: use of undeclared identifier 'PATH_MAX'
  177 |       char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX];
      |                                            ^
/data1/codon-17/codon/parser/common.cpp:182:17: error: use of undeclared identifier 'PATH_MAX'
  182 |       char path[PATH_MAX];
      |                 ^
3 errors generated.

I added the <climits> include line in codon/parser/common.cpp for the build to succeed.

diff --git a/codon/parser/common.cpp b/codon/parser/common.cpp
index 88a250a..5290944 100644
--- a/codon/parser/common.cpp
+++ b/codon/parser/common.cpp
@@ -3,6 +3,7 @@
 #include "common.h"

 #include <cinttypes>
+#include <climits>
 #include <string>
 #include <vector>
marioroy commented 9 months ago

Ping...

I tried the latest llvm-17 branch commit da65536ef12f1976a78f46d614ddcc2e47066d39 without the above patch. The build fails on Clear Linux.

FAILED: CMakeFiles/codonc.dir/codon/parser/common.cpp.o 

... codon/parser/common.cpp:176:19: error: use of undeclared identifier 'PATH_MAX'
  176 |       char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX];
      |                   ^
... codon/parser/common.cpp:176:44: error: use of undeclared identifier 'PATH_MAX'
  176 |       char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX];
      |                                            ^
... codon/parser/common.cpp:181:17: error: use of undeclared identifier 'PATH_MAX'
  181 |       char path[PATH_MAX];
      |                 ^
3 errors generated.

CMake Error at build/cmake_install.cmake:88 (file):
  file INSTALL cannot find "build/libcodonc.so": No such file or directory.

Adding the line #include <climits> to codon/parser/common.cpp resolves the issue, allowing the build to succeed. The following is how I build codon.

#!/bin/bash
# build_codon-17.sh

# git clone --depth 1 -b llvm-17 https://github.com/exaloop/codon codon-17
# cd codon-17

# Add include line to codon/parser/common.cpp
# #include <climits>;

unset CFLAGS
unset CXXFLAGS

export CC=clang
export CXX=clang++

rm -fr build
cmake -S . -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_DIR=../llvm-17/install/lib/cmake/llvm \
    -DCMAKE_C_COMPILER=${CC} \
    -DCMAKE_CXX_COMPILER=${CXX} \
    -DCODON_GPU=ON

cmake --build build --config Release && \
cmake --install build --prefix=install

For the llvm dependency, I built using the codon-17 branch.

#!/bin/bash
# build_llvm-17.sh

# git clone --depth 1 -b codon-17 https://github.com/exaloop/llvm-project llvm-17

unset CFLAGS
unset CXXFLAGS

export CC=clang
export CXX=clang++

rm -fr llvm-17/build
cmake -S llvm-17/llvm -B llvm-17/build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_INCLUDE_TESTS=OFF \
    -DLLVM_ENABLE_RTTI=ON \
    -DLLVM_ENABLE_ZLIB=OFF \
    -DLLVM_ENABLE_TERMINFO=OFF \
    -DLLVM_TARGETS_TO_BUILD="AMDGPU;NVPTX;WebAssembly;X86"

cmake --build llvm-17/build && \
cmake --install llvm-17/build --prefix=llvm-17/install
arshajii commented 9 months ago

Hi @marioroy, I've added this include to the llvm-17 branch. Let me know if there are any other issues.