Fix issues with configuring flex during build on MacOS (#8412)

This commit is contained in:
Kaleb Barrett
2026-09-19 13:34:30 -04:00
committed by GitHub
parent b0b4714a9d
commit 8fbfc82cc2
5 changed files with 50 additions and 13 deletions
+30 -1
View File
@@ -93,7 +93,36 @@ if(OBJCACHE_ENABLED)
endif()
find_package(BISON)
find_package(FLEX)
# Prefer the header installed with the selected generator, including through
# symlinks such as Homebrew's bin/flex. Explicit cache entries take precedence.
find_program(
FLEX_EXECUTABLE
NAMES flex win-flex win_flex
DOC "Path to the flex executable"
)
if(NOT FLEX_EXECUTABLE)
message(
FATAL_ERROR
"Cannot find Flex; set FLEX_EXECUTABLE to its executable path"
)
endif()
get_filename_component(flex_real_executable "${FLEX_EXECUTABLE}" REALPATH)
get_filename_component(flex_bin_dir "${flex_real_executable}" DIRECTORY)
find_path(
FLEX_INCLUDE_DIR
FlexLexer.h
PATHS "${flex_bin_dir}/../include" "${flex_bin_dir}"
NO_DEFAULT_PATH
DOC "Path to the flex headers"
)
find_path(FLEX_INCLUDE_DIR FlexLexer.h)
if(NOT FLEX_INCLUDE_DIR)
message(
FATAL_ERROR
"Cannot find FlexLexer.h; set FLEX_INCLUDE_DIR to its directory"
)
endif()
mark_as_advanced(FLEX_EXECUTABLE FLEX_INCLUDE_DIR)
# Build
#set_property(GLOBAL PROPERTY JOB_POOLS one_job=1)
+7
View File
@@ -79,6 +79,13 @@ fi
if [ "$OPT_LIGHT_DEBUG" = 1 ]; then
CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-light-debug"
fi
if [ "$(uname -s)" = Darwin ]; then
# Force the use of the Homebrew flex over the one included as part of the
# Apple SDK that's preinstalled on the MacOS Github Action runners.
FLEX_PREFIX=$(brew --prefix flex)
export LEX="$FLEX_PREFIX/bin/flex"
export CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-I$FLEX_PREFIX/include"
fi
autoconf
./configure $CONFIGURE_ARGS CXX="$CXX"
+12
View File
@@ -264,6 +264,7 @@ fi
python3_version=$($PYTHON3 --version | head -1)
AC_MSG_RESULT([$PYTHON3 --version = $python3_version])
AC_ARG_VAR([LEX], [Flex executable])
AC_CHECK_PROG(LEX,flex,flex)
if test "x$LEX" = "x" ; then
AC_MSG_ERROR([Cannot find "flex" in your PATH, please install it])
@@ -271,6 +272,17 @@ fi
flex_version=$($LEX --version | head -1)
AC_MSG_RESULT([$LEX --version = $flex_version])
# Use the header installed with the selected generator.
flex_include=$($PYTHON3 -c '
import pathlib
import shutil
import sys
print(pathlib.Path(shutil.which(sys.argv@<:@1@:>@) or sys.argv@<:@1@:>@).resolve().parent.parent / "include")
' "$LEX")
if test -f "$flex_include/FlexLexer.h"; then
CPPFLAGS="$CPPFLAGS -I$flex_include"
fi
AC_CHECK_PROG(YACC,bison,bison)
if test "x$YACC" = "x" ; then
AC_MSG_ERROR([Cannot find "bison" in your PATH, please install it])
+1 -1
View File
@@ -28,7 +28,7 @@ Quick Install
and install.
#. For build on Windows using MSVC set environment variable WIN_FLEX_BISON
to install directory. For build on Windows/Linux/OS-X using ninja set
the environment variable FLEX_INCLUDE to the directory containing
the CMake variable FLEX_INCLUDE_DIR to the directory containing
FlexLexer.h and ensure that flex/bison is available within the PATH.
To obtain Verilator sources download
-11
View File
@@ -14,7 +14,6 @@
import re
import sys
import platform
for line in sys.stdin:
# Fix flex 2.6.1 warning
@@ -48,14 +47,4 @@ for line in sys.stdin:
line = re.sub(r'(#line \d+ ".*)_pretmp', r'\1', line)
# Fix 'register' storage class specifier is deprecated and incompatible with C++17
line = re.sub(r'register ', '', line)
# Change int to size_t on LexerInput/LexerOutput when using macOS Tahoe
if platform.system() == "Darwin":
try:
osv = platform.mac_ver()[0] # Example "26.2"
if len(osv) > 2 and osv[2] == "." and int(osv[:2]) >= 26:
if "::LexerInput(" in line or "::LexerOutput(" in line:
line = re.sub(r'int ', r'size_t ', line)
except IndexError as e:
print(f"Unexpected index error {e}")
print(line, end='')