Skip to content

libconfig-d#1832

Closed
rtbo wants to merge 18 commits intoldc-developers:masterfrom
rtbo:rtbo-libconfig
Closed

libconfig-d#1832
rtbo wants to merge 18 commits intoldc-developers:masterfrom
rtbo:rtbo-libconfig

Conversation

@rtbo
Copy link
Contributor

@rtbo rtbo commented Oct 15, 2016

Hello

Pull-request according the project ideas page in order to remove dependency on libconfig.
Dependencies are managed by 2 submodules (libconfig-d and Pegged) in a 3rdparty directory, and necessary files are directly compiled in ldc2.o
So it should be transparent for users.

I setup Travis and AppVeyor to build this branch.

Travis reports error when building on OSX: dyld: Library not loaded: /opt/local/lib/libconfig.9.dylib during CMake configure step.
This dylib is not needed anymore (that's quite the purpose, isn't it?) but I can't tell where cmake is pulling this dependency from. Please give me indications.
In AppVeyor ldc emits warning that it can't find default.switches in the config file. I don't know how the config file looks like under windows, but I can remove the warning if it is normal. Otherwise please give me indication of what is wrong. Finally, windows build stops at this error: Error: module md is in file 'std\digest\md.d' which cannot be read. I don't think this is related to this PR, but can be wrong of course.

@kinke
Copy link
Member

kinke commented Oct 15, 2016

Very nice, thanks for doing this.

I can't tell where cmake is pulling this dependency from. Please give me indications.

dyld: Library not loaded: /opt/local/lib/libconfig.9.dylib
  Referenced from: /Users/travis/dlang/ldc-1.0.0/bin/ldmd2
  Reason: image not found

I.e., it's the used D host compiler (LDMD 1.0) which on OSX is apparently linked dynamically against libconfig.

In AppVeyor ldc emits warning that it can't find default.switches in the config file.

That's definitely not what's supposed to be happening. It's also the reason why the imports fail; no -I directories are set (only the ones directly in the command line used by CMake, i.e., -I${RUNTIME_DIR}/src -I${RUNTIME_DIR}/src/gc, Phobos is missing). The config file doesn't really differ on Windows. It's encoded in UTF8 without BOM afaik, but it uses Windows newlines (\r\n - probably done by git automatically). The path to it may use backslashes instead of forward ones on Windows. So I guess one of these 2 Windows specifica is causing the failure.

bool readDataFromConfigFile ( const char * pathcstr,
const char * sectioncstr,
const char * bindircstr,
ConfigData & data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: please use clang-format for C++ sources.


s_vector switches;
std::string pathstr;
ConfigData data;
Copy link
Member

@kinke kinke Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about getting rid of the ConfigData helper struct and implementing ConfigFile partially in D? Apparently all what would need to be done (besides having a D declaration of the (small) struct) is converting ConfigFile to a struct and storing pathstr as C string. readDataFromConfigFile() would become a private method implemented in D.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I wanted to do at the start. I've chosen a safer path that modifies as little code as possible, but I prefer your option.
Any clue on how to call exe_path::getBinDir() from D? (it returns a std::string)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd let read() call it on the C++ side and forward its c_str() to the D method.

@rtbo
Copy link
Contributor Author

rtbo commented Oct 15, 2016

For OSX, I'll reintegrate the brew install libconfig in .travis.yml. It should do the trick.

@dnadlinger
Copy link
Member

Background: On OS X, the binary packages are supposed to contain libconfig, with the rpath suitably adapted. We really need to fix this for 1.0 and the current release, even if it will be obsoleted by this PR.

@rtbo
Copy link
Contributor Author

rtbo commented Oct 16, 2016

It should work now.
AppVeyor still complains about a failed test (std.file-debug)

@kinke
Copy link
Member

kinke commented Oct 17, 2016

I've retriggered AppVeyor. Unfortunately, std.file sometimes fails due to 2-seconds file timestamp granularity (FAT file systems).

3rdparty/libconfig-d/src/config/package.d
3rdparty/libconfig-d/src/config/setting.d
3rdparty/libconfig-d/src/config/util.d
)
Copy link
Member

@kinke kinke Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case those are all modules anyway, I'd prefer something compact and resilient like:

file(GLOB_RECURSE 3RDPARTY_SRC_D
    3rdparty/pegged/*.d
    3rdparty/libconfig-d/src/*.d
)

Oh, I've just seen that you excluded libconfig-d's test.d in this list, but that's only enabled for unittest builds, so it doesn't really count. ;)

Edit: But pegged's pegged/test/tester.d contains a main(). Bad idea for library code; these testing helpers should be moved outside the regular library src tree IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't change it?
Or I glob and explicit remove afterwards what is not needed?
Pegged has a lot of files that we don't need at all, so I would prefer keep it this way.
Another possibility is to make a 3rdparty[.lib][.a] in 3rdparty/CMakeLists.txt

s_vector switches;
const char *pathcstr;
s_iterator switches_b;
s_iterator switches_e;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please initialize them to nullptr here in the header and get rid of the explicit default ctor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

module driver.configfile;


struct ConfigFile
Copy link
Member

@kinke kinke Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extern (C++) - otherwise all fields are off by ptr size (monitor for D classes). Sorry it's a struct.

extern(Windows)
HRESULT SHGetFolderPathA(HWND, int, HANDLE, DWORD, LPSTR);
extern(Windows)
HRESULT SHGetFolderPathW(HWND, int, HANDLE, DWORD, LPWSTR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer only declaring actually used stuff - no *W and only 3 of the enums below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kinke
Copy link
Member

kinke commented Oct 25, 2016

Are there any functional changes due to the C++ -> D transition of almost all of ConfigFile or did you take care to preserve existing behavior?

@rtbo
Copy link
Contributor Author

rtbo commented Oct 26, 2016

Behavior (and C++ interface) should be the same.
I took care to locate ldc2.conf in the same order.

rtbo added 2 commits October 26, 2016 17:04
Avoids a glue C++ func that returns a C string
@kinke kinke mentioned this pull request Nov 7, 2016
@JohanEngelen
Copy link
Member

Is there anything still preventing this from merging?

@kinke
Copy link
Member

kinke commented Nov 17, 2016

I'd merge it if we agree that it should be part of 1.1, otherwise I'd wait (just to simplify bringing branch release-1.1 up to speed, i.e., one less commit to be reverted). If @klickverbot agrees that 1.1 should include all of master except for OSX (and the runtime functions type check, which depends on it). that is. If David is unsure whether other commits are responsible for the spurious Travis OSX failures, I'd tend to branch off a test branch (master with the 2 commits reverted) and trigger the OSX Travis jobs manually at least 20 times or so and see whether it's really just his OSX commit.

@rainers
Copy link
Contributor

rainers commented Nov 18, 2016

I'm a bit late to the discussion, but there is one thing that bugs me: while it is good that we change the implementation of the config file reading to something we can actively fix in case of existing and maybe future problems, it's a bit unfortunate to replace one external dependency with another.
Would it make sense to extract just the parser (e.g. no writing required) into a few files to include directly into the LDC source?

@kinke
Copy link
Member

kinke commented Nov 18, 2016

For me the primary advantages are:

  • no runtime dependency (as opposed to linking libconfig dynamically, which is at least the case for our previous OSX releases)
  • 'built-in' compilation dependencies as submodules (e.g., on Linux we currently require the libconfig-dev package; on Windows the lib needs to be built externally and the path then passed to LDC's CMake etc.)
  • license

@rainers
Copy link
Contributor

rainers commented Nov 18, 2016

I agree, it's a good improvement. It was just a thought when I stumbled over some complaints that implementing an adhoc parser would be pretty simple, especially if we stretch the syntax slightly by reusing the D Lexer, e.g. for number parsing. But as I never got to do it, I must not complain about an alternative implementation ;-)

@JohanEngelen
Copy link
Member

trigger the OSX Travis jobs manually at least 20 times or so and see whether it's really just his OSX commit

Currently doing this for #1817 (LLVM 3.9).

@kinke
Copy link
Member

kinke commented Nov 18, 2016

Currently doing this for #1817 (LLVM 3.9).

@JohanEngelen: I don't understand. That branch is 20 commits behind master and does contain David's OSX commit...

@JohanEngelen
Copy link
Member

JohanEngelen commented Nov 19, 2016

@kinke Should have checked that it contains the OSX stuff... dumb, sorry.
(edit: rebasing for extra testing)

@JohanEngelen
Copy link
Member

Let's move forward on this?

@JohanEngelen
Copy link
Member

Being on a constrained internet connection for some time made me more aware of the size of things. This PR pulls in 2 external submodules, and especially the Pegged repo is quite large and pulls in even more submodules. This will increase git clone time and download size and also our release source archive size, adding a lot of files that we don't need.
I now feel much more for @rainers suggestion of stripping all of it down to a few files. From the CMake script addition, it looks like we would only have to copy 9 .d files into our repo and two license files. (similar to how we include FileCheck and profile-rt, instead of svn checkout their repositories)

@kinke
Copy link
Member

kinke commented Feb 5, 2017

How about we just use a simple JSON file and parse it via std.json or so?

@rtbo
Copy link
Contributor Author

rtbo commented Feb 7, 2017

FWIW:
Not that I want to scuttle my own work, but I tend to agree that JSON would be simpler to handle.
libconfig has nice structuring features, but all we need is to select a set of switches.

This was referenced Feb 18, 2017
@kinke
Copy link
Member

kinke commented Mar 5, 2017

Closing in favor of #2016. Thanks Remi for hanging in there! :)

@kinke kinke closed this Mar 5, 2017
@rtbo rtbo deleted the rtbo-libconfig branch March 7, 2017 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants