https://github.com/dzhidzhoev updated https://github.com/llvm/llvm-project/pull/99266
>From 1d074bad4006134d164e96e21f9105b167212d53 Mon Sep 17 00:00:00 2001 From: Vladislav Dzhidzhoev <vdzhidzh...@accesssoftek.com> Date: Mon, 15 Jul 2024 22:52:40 +0200 Subject: [PATCH] [LLDB][test] Update Makefile.rules to support Windows host+Linux target These changes are aimed to support cross compilation build on Windows host for Linux target for API tests execution. They're not final: changes will follow for refactoring and adjustments to make all tests passing. Chocolatey make is recommended to use, since it is maintained better than GnuWin32 recommended here https://lldb.llvm.org/resources/build.html#codesigning (it was updated last time in 2010) and helps to avoid problems with building tests (for example, GnuWin32 doesn't support long paths and there are some other failures with building for Linux with it). --- .../Python/lldbsuite/test/make/Makefile.rules | 72 ++++++++++++------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules index be3ad684dd736..8d54fc7f3321e 100644 --- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules +++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules @@ -112,7 +112,7 @@ $(error "C compiler is not specified. Please run tests through lldb-dotest or li endif #---------------------------------------------------------------------- -# Handle SDKROOT on Darwin +# Handle SDKROOT for the cross platform builds. #---------------------------------------------------------------------- ifeq "$(OS)" "Darwin" @@ -120,6 +120,18 @@ ifeq "$(OS)" "Darwin" # We haven't otherwise set the SDKROOT, so set it now to macosx SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path) endif + SYSROOT_FLAGS := -isysroot "$(SDKROOT)" + GCC_TOOLCHAIN_FLAGS := +else + ifneq "$(SDKROOT)" "" + SYSROOT_FLAGS := --sysroot "$(SDKROOT)" + GCC_TOOLCHAIN_FLAGS := --gcc-toolchain="$(SDKROOT)/usr" + else + # Do not set up these options if SDKROOT was not specified. + # This is a regular build in that case (or Android). + SYSROOT_FLAGS := + GCC_TOOLCHAIN_FLAGS := + endif endif #---------------------------------------------------------------------- @@ -210,20 +222,15 @@ endif DEBUG_INFO_FLAG ?= -g CFLAGS ?= $(DEBUG_INFO_FLAG) -O0 - -ifeq "$(OS)" "Darwin" - ifneq "$(SDKROOT)" "" - CFLAGS += -isysroot "$(SDKROOT)" - endif -endif +CFLAGS += $(SYSROOT_FLAGS) ifeq "$(OS)" "Darwin" CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) else CFLAGS += $(ARCHFLAG)$(ARCH) endif -CFLAGS += -I$(LLDB_BASE_DIR)include -I$(LLDB_OBJ_ROOT)/include +CFLAGS += -I$(LLDB_BASE_DIR)/include -I$(LLDB_OBJ_ROOT)/include CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR) ifndef NO_TEST_COMMON_H @@ -234,9 +241,9 @@ CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS) # Use this one if you want to build one part of the result without debug information: ifeq "$(OS)" "Darwin" - CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)" + CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS) else - CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) + CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS) endif ifeq "$(MAKE_DWO)" "YES" @@ -267,7 +274,9 @@ endif CFLAGS += $(CFLAGS_EXTRAS) CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS) LD = $(CC) -LDFLAGS ?= $(CFLAGS) +# Copy common options to the linker flags (dwarf, arch. & etc). +# Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc). +LDFLAGS += $(CFLAGS) LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS) ifeq (,$(filter $(OS), Windows_NT Android Darwin)) ifneq (,$(filter YES,$(ENABLE_THREADS))) @@ -378,11 +387,28 @@ ifeq (1, $(USE_SYSTEM_STDLIB)) endif endif +# No C++ library has been specifieed. Use libstdc++ by default. +ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB))) + # If no explicit request was made, but we have paths to a custom libcxx, use + # them. + ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),) + CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR) + ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" "" + CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR) + endif + LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ + # Otherwise no C++ library has been specified. Use stdc++ by default. + else + USE_SYSTEM_STDLIB := 1 + endif +endif + ifeq (1,$(USE_LIBSTDCPP)) # Clang requires an extra flag: -stdlib=libstdc++ ifneq (,$(findstring clang,$(CC))) - CXXFLAGS += -stdlib=libstdc++ - LDFLAGS += -stdlib=libstdc++ + # Force clang looking for the gcc's headers at specific rootfs folder. + CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS) + LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS) endif endif @@ -403,7 +429,7 @@ ifeq (1,$(USE_LIBCPP)) endif ifneq (,$(filter $(OS), FreeBSD Linux NetBSD)) ifneq (,$(LLVM_LIBS_DIR)) - LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR) + LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR) endif endif endif @@ -416,21 +442,15 @@ ifeq (1, $(USE_SYSTEM_STDLIB)) endif CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1 LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++ + else + ifneq (,$(findstring clang,$(CC))) + # Force clang looking for the gcc's headers at specific rootfs folder. + CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS) + LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS) + endif endif endif -# If no explicit request was made, but we have paths to a custom libcxx, use -# them. -ifeq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP), $(USE_SYSTEM_STDLIB)),) - ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),) - CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR) - ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" "" - CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR) - endif - LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++ - endif -endif - #---------------------------------------------------------------------- # Additional system libraries #---------------------------------------------------------------------- _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits