Skip to content

Commit

Permalink
Merge pull request dlang#458 from CyberShadow/pull-20230430-062515
Browse files Browse the repository at this point in the history
rdmd: Support -shared in the same way as -lib

Signed-off-by: Nicholas Wilson <[email protected]>
Merged-on-behalf-of: Vladimir Panteleev <[email protected]>
  • Loading branch information
dlang-bot authored May 1, 2023
2 parents 02365fa + c950a65 commit dfe32a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog/rdmd_shared.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rdmd supports `-shared`

rdmd now understands DMD's `-shared` switch, and sets the default output file name appropriately (`.dll`, `.so`, or `.dylib` depending on the platform), in the same way as `-lib`.
20 changes: 15 additions & 5 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ version (Posix)
enum objExt = ".o";
enum binExt = "";
enum libExt = ".a";
version (OSX)
enum dllExt = ".dylib";
else
enum dllExt = ".so";
enum altDirSeparator = "";
}
else version (Windows)
{
enum objExt = ".obj";
enum binExt = ".exe";
enum libExt = ".lib";
enum dllExt = ".dll";
enum altDirSeparator = "/";
}
else
Expand Down Expand Up @@ -242,10 +247,15 @@ int main(string[] args)

bool obj = compilerFlags.canFind("-c");
bool lib = compilerFlags.canFind("-lib");
string outExt = lib ? libExt : obj ? objExt : binExt;
bool dll = compilerFlags.canFind("-shared");
string outExt =
dll ? dllExt :
lib ? libExt :
obj ? objExt :
binExt;

// Assume --build-only for -c and -lib.
buildOnly |= obj || lib;
// Assume --build-only for -c / -lib / -shared.
buildOnly |= obj || lib || dll;

// --build-only implies the user would like a binary in the program's directory
if (buildOnly && !exe.ptr)
Expand Down Expand Up @@ -360,7 +370,7 @@ size_t indexOfProgram(string[] args)
{
auto arg = args[i];
if (!arg.startsWith('-', '@') &&
!arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") &&
!arg.endsWith(".obj", ".o", ".lib", ".a", ".dll", ".so", ".dylib", ".def", ".map", ".res") &&
args[i - 1] != "--eval")
{
return i;
Expand Down Expand Up @@ -627,7 +637,7 @@ private string[string] getDependencies(string rootModule, string workDir,
string[] names = [libName ~ ".lib"];
else
{
string[] names = ["lib" ~ libName ~ ".a", "lib" ~ libName ~ ".so"];
string[] names = ["lib" ~ libName ~ ".a", "lib" ~ libName ~ ".so", "lib" ~ libName ~ ".dylib"];
dirs ~= ["/lib", "/usr/lib"];
}
foreach (dir; dirs)
Expand Down

0 comments on commit dfe32a6

Please sign in to comment.