Skip to content

Commit

Permalink
Use dynamic libraries only on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthaTi committed Sep 26, 2024
1 parent 0898440 commit f914e54
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:

- name: Compile tour
shell: bash
run: $DUB build :tour -v
run: $DUB build :tour
if: matrix.dc != 'ldc-1.28.1'

- name: Test moduleView
shell: bash
run: $DUB test :module-view
run: $DUB test :module-view -d Fluid_BuildMessages
if: matrix.dc != 'ldc-1.28.1'
47 changes: 13 additions & 34 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
],
"configurations": [
{
"name": "default",
"targetType": "staticLibrary"
},
{
"name": "dynamic",
"name": "linux-dynamic",
"platforms": [
"linux"
],
"targetType": "dynamicLibrary",
"dflags-posix-dmd": [
"-defaultlib=libphobos2.so"
],
"dflags-ldc": [
"--link-defaultlib-shared"
],
"libs-windows": [
"LIBCMT"
]
},
{
"name": "default",
"targetType": "staticLibrary"
},
{
"name": "source",
"targetType": "sourceLibrary"
Expand Down Expand Up @@ -140,36 +140,15 @@
"source/fluid/module_view.d"
],
"sourcePaths": [],
"subConfigurations": {
"fluid": "dynamic"
},
"configurations": [
{
"name": "linux-dynamic",
"platforms": [
"linux"
],
"targetType": "staticLibrary",
"dflags-posix-dmd": [
"-defaultlib=libphobos2.so"
],
"dflags-ldc": [
"--link-defaultlib-shared"
]
},
{
"name": "static",
"targetType": "staticLibrary",
"preRunCommands-windows": [
"ldd build/fluid-module-view-test-static.exe"
]
}
],
"targetPath": "build",
"targetType": "library",
"versions": [
"Fluid_ModuleView"
]
],
"environments": {
"BINDBC_FREETYPE_PACKAGE_DIR": "$BINDBC_FREETYPE_PACKAGE_DIR",
"BINDBC_LOADER_PACKAGE_DIR": "$BINDBC_LOADER_PACKAGE_DIR"
}
}
],
"targetPath": "build"
Expand Down
58 changes: 46 additions & 12 deletions source/fluid/module_view.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ static ~this() @system {

}

static immutable string[] fluidImportPaths;

shared static this() {

import std.path;
import std.process;

fluidImportPaths = [
"source",
"../source",
environment.get("BINDBC_FREETYPE_PACKAGE_DIR").buildPath("source"),
environment.get("BINDBC_LOADER_PACKAGE_DIR").buildPath("source"),
];
}

/// Provides information about the companion D compiler to use for evaluating examples.
struct DlangCompiler {

Expand All @@ -106,12 +121,12 @@ struct DlangCompiler {
/// ditto
int frontendPatch;

/// Import paths to pass to the compiler.
const(string)[] importPaths;

/// ditto
enum frontendMajor = 2;

/// Import paths to pass to the compiler.
string[] importPaths;

/// Returns true if this entry points to a valid compiler.
bool opCast(T : bool)() const {

Expand Down Expand Up @@ -148,7 +163,7 @@ struct DlangCompiler {
// Found a compatible compiler
if (auto match = process.output.matchFirst(pattern)) {

return DlangCompiler(Type.dmd, name, match[1].to!int, match[2].to!int);
return DlangCompiler(Type.dmd, name, match[1].to!int, match[2].to!int, fluidImportPaths);

}

Expand Down Expand Up @@ -178,7 +193,7 @@ struct DlangCompiler {
// Found a compatible compiler
if (auto match = process.output.matchFirst(pattern)) {

return DlangCompiler(Type.ldc, name, match[1].to!int, match[2].to!int);
return DlangCompiler(Type.ldc, name, match[1].to!int, match[2].to!int, fluidImportPaths);

}

Expand Down Expand Up @@ -287,6 +302,29 @@ struct DlangCompiler {

}

/// Extra, platform-specific flags needed to build a shared library.
string[] extraFlags() const {

import std.file : thisExePath;
import std.path : dirName;

// TODO This shouldn't actually pull Fluid unless specified explicitly

version (Windows) {

return [
"LIBCMT.lib",
"fluid.lib",
"-L/LIBPATH:" ~ thisExePath.dirName,
];

}

else
return null;

}

/// Compile a shared library from given source file.
///
/// TODO make this async
Expand Down Expand Up @@ -315,7 +353,9 @@ struct DlangCompiler {
else
outputPath = path.setExtension(".so");

auto cmdline = [executable, sharedLibraryFlag, unittestFlag, path, "-of=" ~ outputPath] ~ importPathsFlag;
auto cmdline = [executable, sharedLibraryFlag, unittestFlag, path, "-of=" ~ outputPath]
~ importPathsFlag
~ extraFlags;

debug (Fluid_BuildMessages) {
import std.stdio;
Expand Down Expand Up @@ -670,12 +710,6 @@ private bindbc.SharedLib runSharedLibrary(string path) @system {

// Configure the compiler
auto compiler = DlangCompiler.findAny();
compiler.importPaths ~= [
"source",
"../source",
expandTilde("~/.dub/packages/bindbc-freetype/1.1.1/bindbc-freetype/source"),
expandTilde("~/.dub/packages/bindbc-loader/1.1.5/bindbc-loader/source"),
];

// Compile the pogram
string outputPath;
Expand Down
7 changes: 0 additions & 7 deletions tour/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,6 @@ Space render(Chapter chapter)() @trusted {
import fluid.module_view;

auto compiler = DlangCompiler.findAny();
compiler.importPaths ~= [
"source",
"../source",
expandTilde("~/.dub/packages/bindbc-freetype/1.1.1/bindbc-freetype/source"),
expandTilde("~/.dub/packages/bindbc-loader/1.1.5/bindbc-loader/source"),
];
// TODO figure out the correct freetype path (or vendor)

return moduleViewFile(
.layout!"fill",
Expand Down

0 comments on commit f914e54

Please sign in to comment.