-
-
Notifications
You must be signed in to change notification settings - Fork 268
Support ldc2.conf as a directory #4954
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
base: master
Are you sure you want to change the base?
Conversation
|
||
llvm::sort(configFiles, [](const std::string &a, const std::string &b) { | ||
auto sa = llvm::StringRef(a), sb = llvm::StringRef(b); | ||
return sa.compare_numeric(sb) < 0; |
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.
Thx for the (lot of) work! - This was the 1st thing I was curious about, how to define the order. Such a 'smart' sort with a default number prefix sounds good to me. 👍
The current CI errors suggest an incomplete config for the built (non-installed) compiler. Let me know if you need help. |
Yup. I didn't think of testing that so I guess I did forget about something... It did work when installing so surely it can't be that broken. |
runtime/CMakeLists.txt
Outdated
if(PHOBOS2_DIR) | ||
set(build_defaultlib "phobos2-ldc,druntime-ldc") | ||
else() | ||
set(build_defaultlib "druntime-ldc") | ||
endif() |
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.
Is there any situation in which PHOBOS2_DIR
doesn't exist? To fix the android failures I would need to slightly adjust this and I want to know if I can simplify the code a little bit?
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.
I guess we can drop that special case of a Phobos-less build. I guess the most likely scenario is that someone forgot to initialize the git submodule before running CMake, not intentionally excluding Phobos from the build.
Are those cmake quotes interfering with my command's quotes or is there some other reason it's failing? |
Not sure, I'd need to check locally. In general, using the Edit: I guess the error is earlier, when trying to invoke a .sh script to finalize the |
FYI: instead of many separate small test files, you can use |
Ohh, that looks useful |
You're right:
It seems that cmake is content to let the |
14e8a43
to
f1f7373
Compare
Ok, one test failure for tomorrow me to go through. Other things that I thought of that could be useful:
|
Ah yeah that'd be good.
Hmm; I think the subset of people running tests is way smaller than those just building. And for those druntime integration tests, we set PATH using a hardcoded assumption: Lines 60 to 66 in 3acd761
I still need to check your rationale for switching to explicit triples for the default target. The main problem I saw back then is that there's no clear 1:1 mapping to the normalized triple (the one with the vendor) - e.g. the vendor seems uninteresting for all but Apple targets (and can be anything from empty to Edit: Another example: the (libc) environment. IIRC, one can use the prebuilt Alpine package (targeting |
I don't agree with this point because:
I couldn't find an example of functions having different signatures but for different behavior just pick something from https://wiki.musl-libc.org/functional-differences-from-glibc.html. Here's an example with // b.c
#include <libgen.h>
#include <string.h>
int always_true(void) {
char arr[] = "/lib/foo/";
char *result = basename(arr);
return strcmp(result, "foo") == 0;
} // a.c
#include <unistd.h>
#include <stdio.h>
extern int always_true(void);
int main (int argc, char **argv) {
printf("1 == %d\n", always_true());
} If you compile both of those files on either musl or glibc you get the correct result:
If you compile
With the comment that this behavior in not specified so it can change at anytime (and even break). For this reason, at least when it comes to the cenv part of the triple, it is not safe to normalize it away. I have to think about the version components of the OS and ARCH fields and see if I can draw a conclusion, otherwise
I'll go with your suggestion here. It's not that important to encode the triple, it only makes the code a little shorter and marginally helps |
Yeah I didn't mean to encourage anything like that, just saying that some guys might already use such stuff, regardless of whether by accident or knowing what they are doing. The env can be versioned too - |
Ok, I added back the documentation (though perhaps a little bit too much for a config file) and made the cat portable on windows. Still unsure what to do with the default triple situation, it sounds most reasonable to skip the last commit and keep |
Changed the documentation file to only be installed with the compiler, not with every runtime build. |
3447df9
to
b15cbe9
Compare
Tests passed but I'm looking over the artifacts and checking that the config files aren't broken. The android one seems to be so I'll have to fix it |
3d82ec7
to
3c35ebb
Compare
The android config now looks fine and I've changed it to be a directory in the release artifacts. The test failure is a timeout |
driver/configfile.d
Outdated
- rpath | ||
+/ | ||
void validateSettingNames(const GroupSetting group, const char* filePath) { | ||
static fail(const Setting setting, const char* filePath) { |
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.
[Omitting the return type is rather unusual.]
driver/configfile.d
Outdated
void validateSettingNames(const GroupSetting group, const char* filePath) { | ||
static fail(const Setting setting, const char* filePath) { | ||
string fmt(Setting.Type type) { | ||
import std.traits : EnumMembers; |
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.
We try to avoid using Phobos in the compiler. This should be doable via __traits(allMembers, T)
too.
driver/configfile.d
Outdated
const rpath = findScalarSetting(sections, "rpath"); | ||
this.rpathcstr = rpath.length == 0 ? null : rpath.replacePlaceholders(cfgPaths).toCString.ptr; | ||
if (rpath.length) |
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.
So one cannot unset it anymore with an empty value in a later section?
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.
Fixed this (in the D code as well as the cmake code) and I've added a test case that checks that rpath = ""
resets the rpath.
runtime/CMakeLists.txt
Outdated
|
||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} "${PROJECT_PARENT_DIR}/cmake/Modules") | ||
set(LDC_SOURCE_ROOT "${PROJECT_PARENT_DIR}") |
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.
Seems unused, only defined in 2 locations?
|
||
# Only have either shared or static libs? | ||
# Then explicitly default to linking against them via default LDC switch. | ||
if(${BUILD_SHARED_LIBS} STREQUAL "ON") | ||
set(ADDITIONAL_DEFAULT_LDC_SWITCHES "${ADDITIONAL_DEFAULT_LDC_SWITCHES}\n \"-link-defaultlib-shared\",") |
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.
Okay so no more support for ADDITIONAL_DEFAULT_LDC_SWITCHES
- I did use it in the past sometimes, mainly for workarounds for some CI platforms IIRC. Should possibly be mentioned in the changelog entry.
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.
You can get the same behavior with:
if(ON_DUMMY_PLATFORM)
makeConfSection(NAME "80-fix-platform" SECTION default SWITCHES ${ADDITIONAL_DEFAULT_LDC_SWITCHES})
endif()
or, if doing it in the CI scripts:
cat <<EOF > etc/ldc2.conf/80-fix-platform.conf
....
EOF
I'll mention this in the CHANGELOG
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 not exactly - those were previously part of the switches in the first default
section, so could still be overridden for specific targets later. But yeah, adding a file would be the new way of doing this.]
Edit: Just a matter of choosing a proper order number prefix for the new file, np at all.
Note that I'd be okay with generating the ldc2.conf directory exclusively now via CMake, so no more support for the single file (as part of the CMake build - but still supported by the compiler). There are breaking changes already, such as the now unused *.conf.in files and dropped Not sure how much that would simplify. I can take care of the CI packages, would want to e.g. redo the macOS package configs anyway, now somewhat easier by adding separate files instead of appending multiple sections. |
As in remove the |
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023). | ||
list(APPEND wasm_switches -L--export-dynamic) | ||
|
||
makeConfSection(NAME "40-ldc-wasm" |
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.
I think we should decrease the order of this - these are just some wasm defaults. The main 'problem' is that we disable linking druntime and Phobos via -defaultlib=
- but that actually only applies to naked wasm, not e.g. for emscripten environments, where we would ideally have and link druntime at least.
With the much greater flexibility now, we could add 2 wasm sections, and e.g. restrict the -defaultlib=
(and empty lib-dirs
) to a ^wasm.*-(none|unknown)$
section or so.
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.
[just an idea for a follow-up PR perhaps, not here]
If ldc2.conf is a directory go through each file (directly) inside it, ordered by name and apply the settings in it. It would be similar to appending all the files and treating it like a normal config file. The specific ordering is the one from llvm::StringRef::compare_numeric. The previous behavior was to always error out if ldc2.conf was a directory, being it passed through `-conf` or being automatically picked up. To account for this change the following restrictions that affect config files have been lifted: - at least one section must match the current triple This is undesirable for cross-compile setups in which one config file is dedicated to one triple - both switches and post-switches must be defined This is undesirable for config files that simply append a CLI switch The above have been replaced by a check that all settings represent valid keys (so switches, post-switches etc.) and that they are of the correct type. Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
Exactly. Again, not sure how much that would simplify the code; you already found a way for the portable concat of all files to a single one. But I suspect it'd be worth it to reduce CMake complexity. In case a package maintainer prefers the single file, he/she can presumably insert the |
I'll prepare a PR where I'm switching to |
I've tried to guess-adapt the windows and macos merge actions, let's see what fails |
# 2) arm64 ios config | ||
cp ../ldc2-arm64/etc/ldc2.conf/31-ldc-runtime-lib-ios-arm64.conf . | ||
# 3) x86_64 & arm64 macos | ||
for arch in x86_64 arm64; do |
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.
We should probably remove the 30-ldc-runtime-lib.conf
file - AFAIK, that contains default: …
with the x86_64 macOS libs. The special thing about the macOS universal package is that it's used by 2 compilers - the native x86_64 and native arm64 ones, merged into the universal bin/ldc2
executable. That's why we don't have a clear default
target, and have these x86_64/arm64 sections instead.
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.
Yup, I've accidentally removed the rm
line that I've added while editing the file :(
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.
I'm somewhat unsatisfied with the 30-ldc-runtime
and 31-ldc-runtime
inconsistent naming scheme but I guess I can't do anything unless the triple situation changes
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.
We can tweak the naming scheme anytime. E.g., the current 30 config part is more than just the runtime libs, at least for the iOS configs - when cross-compiling, we normally need to tweak the used C compiler for linking and preprocessing too, either via -gcc
or adding extra -Xcc
flags. So I'd see this as target-specific group, where I think coupling both OS and arch makes sense (i.e., no need for a 30 OS group, and a separate 40 arch group or so).
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.
E.g.:
// leaving space for user pre-init files...
30-compiler.conf: default switches, post-switches (mainly `-defaultlib` and `-I` with bundled druntime/Phobos modules)
50-target.conf: default target settings (lib-dir, rpath, extra switches)
55-target-wasm.conf
55-target-ios-arm64.conf
…
The compiler-rt path would logically belong to the target group, but is only known when building the compiler. We could e.g. create a 70-compiler-rt.conf
as part of the compiler build, appending the compiler-rt libdir for default
(i.e., all targets). So that a user can append a better one earlier in the 50-target group, and/or fix up the section name in 70-compiler-rt.conf
to only apply to the default target (by matching its triple).
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.
Or what would also work: 51-target-compiler-rt.conf
, appending the lib-dir for default
. And the overrides in 55 then reset lib-dirs anyway.
runtime/ldc-build-runtime.d.in
Outdated
@@ -159,7 +160,6 @@ void runCMake() { | |||
"-DLDMD_EXE_FULL=" ~ ldmdExecutable, | |||
"-DDMDFE_MINOR_VERSION=@DMDFE_MINOR_VERSION@", | |||
"-DDMDFE_PATCH_VERSION=@DMDFE_PATCH_VERSION@", | |||
"-DLDC_WITH_LLD=@LDC_WITH_LLD@", | |||
"-DINCLUDE_INSTALL_DIR=@INCLUDE_INSTALL_DIR@", |
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.
I think we don't need this anymore.
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.
yeah, and INCLUDE_INSTALL_DIR
can be taken out of runtime/CMakeLists.txt
since only the compiler uses it.
runtime/ldc-build-runtime.d.in
Outdated
@@ -3,6 +3,7 @@ module ldcBuildRuntime; | |||
import core.stdc.stdlib : exit; | |||
import std.algorithm; | |||
import std.array; | |||
import std.conv; |
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.
[nit: now superfluous]
69cebae
to
d2939e4
Compare
If everything works, possible followups include:
|
When building, always generate separate files for each ldc2.conf section. This allows creating a full ldc2.conf, part by part, without carrying about the statements' order in the cmake file. When installing, `cat` all the configured files and install it as a single ldc2.conf file. Added the CONF_PREF_DIR cmake option for installing the conf files as a directory, without concatenating them. This is useful when building the runtime as a separate project as this setting would allow generating a (partial) ldc2.conf, enough to support the runtime libraries, which could latter be merged with the config generated by the root ldc project to get a fully functional ldc2. This is a requirement when cross-compiling and installing the libraries on another device or when performing multilib builds outside of -DMULTILIB=ON Also add a more detailed documentation about the configuration. Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
Some settings like the default wasm switches or the compiler-rt lib-dir don't have anything to do with the runtime and, on top of that, some are conditioned by build settings that only affect the compiler. Moving them out of the runtime directory improves the support for cross-compiling because, in the scenario, some variables may be unset in the runtime directory as there is no longer a higher-level project to set them. Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
Short summary of changes:
=> easier to configure independent sections of settings
Compiler contains the
-I
includes, wasm flags and compiler-rt libdirRuntime contains phobos&druntime libdir and rpath
=> The runtime and the compiler can now be installed as separate projects without their config files colliding/being skipped
x86_64-.*-linux-gnu
instead of"default"
).=>
ldc-build-runtime
can now install cross-builds alongside their configuration files (it skipped the config previously to avoid overwriting the host one), removing the need for post-install interaction from the user.