Skip to content

Commit a0fa9a3

Browse files
dzhidzhoevlabath
andauthored
[LLDB][test] Update Makefile.rules to support Windows host+Linux target (#99266)
These changes aim 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 pass. Chocolatey make is recommended to be used since it is maintained better than GnuWin32 mentioned here https://lldb.llvm.org/resources/build.html#windows (latest GnuWin32 release is dated by 2010) and helps to avoid problems with building tests (for example, GnuWin32 make doesn't support long paths and there are some other failures with building for Linux with it). Co-authored-by: Pavel Labath <[email protected]>
1 parent 295e4f4 commit a0fa9a3

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

+43-25
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,26 @@ $(error "C compiler is not specified. Please run tests through lldb-dotest or li
112112
endif
113113

114114
#----------------------------------------------------------------------
115-
# Handle SDKROOT on Darwin
115+
# Handle SDKROOT for the cross platform builds.
116116
#----------------------------------------------------------------------
117117

118118
ifeq "$(OS)" "Darwin"
119119
ifeq "$(SDKROOT)" ""
120120
# We haven't otherwise set the SDKROOT, so set it now to macosx
121121
SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path)
122122
endif
123+
SYSROOT_FLAGS := -isysroot "$(SDKROOT)"
124+
GCC_TOOLCHAIN_FLAGS :=
125+
else
126+
ifneq "$(SDKROOT)" ""
127+
SYSROOT_FLAGS := --sysroot "$(SDKROOT)"
128+
GCC_TOOLCHAIN_FLAGS := --gcc-toolchain="$(SDKROOT)/usr"
129+
else
130+
# Do not set up these options if SDKROOT was not specified.
131+
# This is a regular build in that case (or Android).
132+
SYSROOT_FLAGS :=
133+
GCC_TOOLCHAIN_FLAGS :=
134+
endif
123135
endif
124136

125137
#----------------------------------------------------------------------
@@ -210,20 +222,15 @@ endif
210222
DEBUG_INFO_FLAG ?= -g
211223

212224
CFLAGS ?= $(DEBUG_INFO_FLAG) -O0
213-
214-
ifeq "$(OS)" "Darwin"
215-
ifneq "$(SDKROOT)" ""
216-
CFLAGS += -isysroot "$(SDKROOT)"
217-
endif
218-
endif
225+
CFLAGS += $(SYSROOT_FLAGS)
219226

220227
ifeq "$(OS)" "Darwin"
221228
CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES)
222229
else
223230
CFLAGS += $(ARCHFLAG)$(ARCH)
224231
endif
225-
CFLAGS += -I$(LLDB_BASE_DIR)include -I$(LLDB_OBJ_ROOT)/include
226232

233+
CFLAGS += -I$(LLDB_BASE_DIR)/include -I$(LLDB_OBJ_ROOT)/include
227234
CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR)
228235

229236
ifndef NO_TEST_COMMON_H
@@ -234,9 +241,9 @@ CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS)
234241

235242
# Use this one if you want to build one part of the result without debug information:
236243
ifeq "$(OS)" "Darwin"
237-
CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)"
244+
CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS)
238245
else
239-
CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS)
246+
CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) $(SYSROOT_FLAGS)
240247
endif
241248

242249
ifeq "$(MAKE_DWO)" "YES"
@@ -267,7 +274,9 @@ endif
267274
CFLAGS += $(CFLAGS_EXTRAS)
268275
CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
269276
LD = $(CC)
270-
LDFLAGS ?= $(CFLAGS)
277+
# Copy common options to the linker flags (dwarf, arch. & etc).
278+
# Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc).
279+
LDFLAGS += $(CFLAGS)
271280
LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS)
272281
ifeq (,$(filter $(OS), Windows_NT Android Darwin))
273282
ifneq (,$(filter YES,$(ENABLE_THREADS)))
@@ -378,11 +387,26 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
378387
endif
379388
endif
380389

390+
ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB)))
391+
# If no explicit C++ library request was made, but we have paths to a custom libcxx, use
392+
# them. Otherwise, use the system library by default.
393+
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
394+
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
395+
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
396+
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
397+
endif
398+
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
399+
else
400+
USE_SYSTEM_STDLIB := 1
401+
endif
402+
endif
403+
381404
ifeq (1,$(USE_LIBSTDCPP))
382405
# Clang requires an extra flag: -stdlib=libstdc++
383406
ifneq (,$(findstring clang,$(CC)))
384-
CXXFLAGS += -stdlib=libstdc++
385-
LDFLAGS += -stdlib=libstdc++
407+
# Force clang looking for the gcc's headers at specific rootfs folder.
408+
CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
409+
LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
386410
endif
387411
endif
388412

@@ -416,21 +440,15 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
416440
endif
417441
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
418442
LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
443+
else
444+
ifneq (,$(findstring clang,$(CC)))
445+
# Force clang looking for the gcc's headers at specific rootfs folder.
446+
CXXFLAGS += $(GCC_TOOLCHAIN_FLAGS)
447+
LDFLAGS += $(GCC_TOOLCHAIN_FLAGS)
448+
endif
419449
endif
420450
endif
421451

422-
# If no explicit request was made, but we have paths to a custom libcxx, use
423-
# them.
424-
ifeq ($(or $(USE_LIBSTDCPP), $(USE_LIBCPP), $(USE_SYSTEM_STDLIB)),)
425-
ifneq ($(and $(LIBCPP_INCLUDE_DIR), $(LIBCPP_LIBRARY_DIR)),)
426-
CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(LIBCPP_INCLUDE_DIR)
427-
ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
428-
CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
429-
endif
430-
LDFLAGS += -L$(LIBCPP_LIBRARY_DIR) -Wl,-rpath,$(LIBCPP_LIBRARY_DIR) -lc++
431-
endif
432-
endif
433-
434452
#----------------------------------------------------------------------
435453
# Additional system libraries
436454
#----------------------------------------------------------------------

0 commit comments

Comments
 (0)