-
-
Notifications
You must be signed in to change notification settings - Fork 268
Better support building the runtime separately [mod] #4752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For custom commands that require a built ldc2 specify only an absolute path to compiler binary, not the target name. This is because cmake handles file paths and target dependencies differently. In the case of a target dependency the dependency doesn't actually apply to the `add_custom_command`, it only affects future targets. As an example, we want to built libruntime.a from a D file foo.d. What we need to describe is: 1. compile foo.o from foo.d (depends on LDC) 2. archive libruntime.a from foo.o If we use ${LDC_EXE} as a dependency (only the target name) cmake would generate: 1. compile foo.o from foo.d 2. archive libruntime.a from foo.o (depends on LDC) Using an absolute path for the LDC dependency does what we want it to do. Signed-off-by: Andrei Horodniceanu <[email protected]>
Signed-off-by: Andrei Horodniceanu <[email protected]>
Signed-off-by: Andrei Horodniceanu <[email protected]>
D_EXTRA_FLAGS is the intended way to pass flags like -m32 to ldc so make sure that its value is respected during the druntime tests. Signed-off-by: Andrei Horodniceanu <[email protected]>
…ke-based integration tests]
Look good. With the last commit we respect Other objectives that we may want to achieve, mostly taken from the discussion in the previous PR. 1. respect configure-time CC and CXXThe current makefiles will use the default values from the environment when the tests are run for the C and C++ compiler, basically ignoring what cmake found, or was configured with. This could be fixed by calling make with 2. (why we can't) use CC to pass argumentsWhile gmake should cope with CC being a command and arguments ( We have no easy way to fix this as changing the driver code is not feasible so we can only declare a separate variable to hold the arguments of This story only applies to The current code in cmake is closest to using 3. divergence of the makefiles from the standard way of passing flagsThis is mostly an issue with the makefiles but I think it is still worth discussing as changing the makefiles can benefit us by simplifying the logic we need to carry out. This is how a make rule for compiling a C program should look like: https://www.gnu.org/prep/standards/html_node/Command-Variables.html#Command-Variables foo.o: foo.c
$(CC) -c $(CPPFLAGS) $(target_specific_flags) $(CFLAGS) $< We don't use foo.o: foo.c
$(CC) $(CC_ARGS) -c $(target_specific_flags) $(CFLAGS) $< What is important in the above command:
Note that it's also acceptable to have: MY_FLAGS = -Imy_dir -DFOO_BAR $(CFLAGS)
foo.o: foo.c
$(CC) $(CC_ARGS) -c $(MY_FLAGS) $< as this is leads to the same command being run. How does the current makefiles handle these flags:
What I propose as a fix1 should be straightforward. So long as there is a 2 depends on how we want to pass the flags. If we decide to pass $(CC) $(CC_ARGS) -c $(target_specific_flags) $(CFLAGS) $< we may not need to implement 3 is the hardest as what I see as the proper solution would require, significantly, rewriting the makefiles. If we want to go with a bandage solution we should at least introduce variables for specifying arbitrary flags, separate from all the variables that are currently in use and make sure that their values are respected in all invocations of the corresponding compiler. In short, I would prefer if
CFLAGS .
|
Perfect, that's what I wanted in the first place (and good to include CXX too), but was afraid of breaking your use case of test-time CC env variable. But you're okay with that in #4743 (comment), perfect.
Wrt. LDC on Windows not supporting a CC env var with flags - I don't think that'd be a deal breaker. E.g., the current proposal here converts the CMake semicolon-separated lists to space-separated lists via a char-replace, so flags containing spaces aren't quoted and would (likely) break the commands. I think it's fine to focus on Posix first, especially wrt. separate runtime builds and extra target-specific flags and wanting to run the druntime integration tests, on Windows.
Yeah that's probably an upstream discussion, but I don't see it as a problem. The actual test Makefiles simply want to use a single combined
Edit:
|
…tion tests] To propagate the C[++] compilers at CMake configure-time to test-time.
runtime/CMakeLists.txt
Outdated
cmake_minimum_required(VERSION 3.4.3) | ||
project(runtime C ASM CXX) # CXX for integration tests only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, ${CMAKE_CXX_COMPILER}
was empty for a separate runtime build.
FWIW, I've tested this with bin/ldc-build-runtime --ldcSrcDir=$PWD/../ldc --ninja --dFlags="-mtriple;my-triple" --cFlags="-target;my-triple"
and looking at ldc-build-runtime.tmp/CTestTestfile.cmake
:
add_test(druntime-test-aa-debug "/usr/bin/gmake" "-C" "/home/mkinkelin/dev/ldc/runtime/druntime/test/aa" "ROOT=/home/mkinkelin/dev/ninja-ldc/ldc-build-runtime.tmp/druntime-test-aa-debug" "DMD=" "BUILD=debug" "SHARED=1" "CC=/usr/bin/cc" "CXX=/usr/bin/c++" "DRUNTIME=/home/mkinkelin/dev/ninja-ldc/ldc-build-runtime.tmp/lib/libdruntime-ldc-debug.a" "DRUNTIMESO=/home/mkinkelin/dev/ninja-ldc/ldc-build-runtime.tmp/lib/libdruntime-ldc-debug-shared.so" "CFLAGS_BASE=-target my-triple -Wall -Wl,-rpath,/home/mkinkelin/dev/ninja-ldc/ldc-build-runtime.tmp/lib" "DFLAGS_BASE=-mtriple my-triple" "LINKDL=-L-ldl")
DMD
is empty, ldc-build-runtime
defines LDC_EXE_FULL
, but not LDMD_EXE_FULL
; will fix. Edit: Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this,
${CMAKE_CXX_COMPILER}
was empty for a separate runtime build.
Yeah, that's expected. We need need the CXX
language to be added to the project if we use a C++ compiler, even if only during the tests.
FWIW, I've tested this with
bin/ldc-build-runtime --ldcSrcDir=$PWD/../ldc --ninja --dFlags="-mtriple;my-triple" --cFlags="-target;my-triple"
and looking atldc-build-runtime.tmp/CTestTestfile.cmake
:
My build + tests worked fine as well.
Oh god, now hitting that super-weird CMAKE_C_COMPILER issue on Apple (some deeply nested |
Lovely. The only thing I got from the discussion is that The windows tests are also failing:
From a quick glance over the ms docs I think this is fixable. It seems I can't directly make a suggestion https://github.com/orgs/community/discussions/9099: diff --git a/runtime/druntime/test/shared/Makefile b/runtime/druntime/test/shared/Makefile
index 0ba78e6ff9..1c40a7dd91 100644
--- a/runtime/druntime/test/shared/Makefile
+++ b/runtime/druntime/test/shared/Makefile
@@ -139,16 +139,16 @@ else
endif
$(ROOT)/linkD$(DOTEXE): $(SRC)/linkD.c $(ROOT)/lib$(DOTDLL) $(DRUNTIMESO)
- $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/[email protected],) $< $(ROOT)/lib$(DOTIMPLIB) $(CC_EXTRAS)
+ $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/Fo$(ROOT)/,) $< $(ROOT)/lib$(DOTIMPLIB) $(CC_EXTRAS)
$(ROOT)/linkDR$(DOTEXE): $(SRC)/linkDR.c $(ROOT)/lib$(DOTDLL) $(DRUNTIMESO)
- $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/[email protected],) $< $(DRUNTIME_IMPLIB) $(CC_EXTRAS)
+ $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/Fo$(ROOT)/,) $< $(DRUNTIME_IMPLIB) $(CC_EXTRAS)
$(ROOT)/loadDR$(DOTEXE): $(SRC)/loadDR.c $(ROOT)/lib$(DOTDLL) $(DRUNTIMESO)
- $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/[email protected],) $< $(CC_EXTRAS)
+ $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/Fo$(ROOT)/,) $< $(CC_EXTRAS)
$(ROOT)/host$(DOTEXE): $(SRC)/host.c $(ROOT)/plugin1$(DOTDLL) $(ROOT)/plugin2$(DOTDLL)
- $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/[email protected],) $< $(CC_EXTRAS)
+ $(QUIET)$(CC) $(CFLAGS) $(CC_OUTFLAG)$@ $(if $(findstring $(OS),windows),/Fo$(ROOT)/,) $< $(CC_EXTRAS)
$(ROOT)/liblinkdep$(DOTDLL): $(ROOT)/lib$(DOTDLL)
$(ROOT)/liblinkdep$(DOTDLL): DFLAGS+=-L$(ROOT)/lib$(DOTIMPLIB) |
If we can get the tests to pass I think these changes are pretty much everything that we need and that we can do simply (we're only ignoring |
Sigh, this seems like a silly ldc/.github/actions/helper-build-ldc/action.yml Lines 58 to 59 in 1f0c36e
Thanks for looking into a workaround. Unfortunately this is in upstream... |
bc1cfe5
to
074c388
Compare
extra_cmake_flags: >- | ||
-DBUILD_LTO_LIBS=ON | ||
-DRT_CFLAGS=-m32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, this is pretty similar to the Gentoo situation: the CFLAGS env variable used to set up 64-bit clang-cl as C compiler only applies at CMake config-time, affecting the CMake default flags and making it to the builds:
ldc/.github/actions/1-setup/action.yml
Lines 165 to 172 in 1f0c36e
- name: 'Windows x86: Make CMake configure 64-bit clang-cl for 32-bit code emission' | |
if: runner.os == 'Windows' && inputs.arch == 'x86' | |
shell: bash | |
run: | | |
set -eux | |
echo "CFLAGS=-m32" >> $GITHUB_ENV | |
echo "CXXFLAGS=-m32" >> $GITHUB_ENV | |
echo "ASMFLAGS=-m32" >> $GITHUB_ENV |
But now with clang-cl
as druntime integration test CC, that -m32
isn't forwarded, and we need to pass it in via RT_CFLAGS explicitly.
[This worked fine with default Microsoft cl
C compiler from the environment (PATH), which diverges (with different executables in different dirs) across x64 and x86. clang-cl doesn't infer the bitness from the environment apparently.]
Based on #4743.