Skip to content

Commit

Permalink
Implement preBuildCommands in pure D
Browse files Browse the repository at this point in the history
This makes it easier to be portable across Windows and Posix.
  • Loading branch information
jacob-carlborg committed Jun 27, 2023
1 parent 99654f4 commit eb4b384
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions configure.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ struct Options
*/
bool staticallyLinkBinary = false;

/// Only generate configuration if needed.
bool ifNeeded = false;

/// The path to the LLVM/Clang library directory.
string llvmLibPath ()
{
Expand Down Expand Up @@ -414,6 +417,9 @@ private:
}
}

/// The name of the file where the configuration is written.
enum configPath = "linker_flags.txt";

/**
* This mixin template contains shared logic to generate the actual
* configuration.
Expand All @@ -422,9 +428,6 @@ mixin template BaseConfigurator()
{
private
{
/// The name of the file where the configuration is written.
enum configPath = "linker_flags.txt";

/// The options that were the result of parsing the command line flags.
Options options;

Expand Down Expand Up @@ -677,13 +680,16 @@ void main(string[] args)
{
auto options = parseArguments(args);

if (!options.help)
{
if (options.staticallyLinkClang)
StaticConfigurator(options, DefaultConfig()).generateConfig();
else
DynamicConfigurator(options, DefaultConfig()).generateConfig();
}
if (options.help)
return;

if (options.ifNeeded && exists(configPath))
return;

if (options.staticallyLinkClang)
StaticConfigurator(options, DefaultConfig()).generateConfig();
else
DynamicConfigurator(options, DefaultConfig()).generateConfig();
}

private:
Expand All @@ -707,7 +713,8 @@ Options parseArguments(string[] args)
"llvm-path", "The path to the LLVM/Clang root directory.", &options.llvmPath,
// "ncurses-lib-path", "The path to the ncurses library.", &options.ncursesLibPath,
"statically-link-clang", "Statically link libclang. Defaults to no.", &options.staticallyLinkClang,
"statically-link-binary", "Completely statically link the binary. Defaults to no.", &options.staticallyLinkBinary
"statically-link-binary", "Completely statically link the binary. Defaults to no.", &options.staticallyLinkBinary,
"if-needed", "Only generate the configuration if needed. Defaults to no.", &options.ifNeeded
);

version (OSX)
Expand Down
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"preGenerateCommands-windows": ["$PACKAGE_DIR/tools/generate_version.bat"],

"preBuildCommands": [
"(! [ -s linker_flags.txt ] && ./configure) || true"
"$DC -run configure.d --if-needed"
],

"lflags": ["@$PACKAGE_DIR/linker_flags.txt"],
Expand Down

0 comments on commit eb4b384

Please sign in to comment.