dlang / tools

Ancillary tools for the D programming language compiler

Home Page:http://dlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RDMD should use platform shared library file extension for file name if `-shared` is used

AndrejMitrovic opened this issue · comments

commented
module source;

import core.sys.windows.windef;

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) nothrow {
    return 0;
}
> rdmd -shared --build-only source.d

$ dir
> 2022-11-22  02:45 PM            80,896 source.exe

--chatty shows that RDMD used -of to specify a file name with an .exe extension:

spawn ["C:\Apps\DMD\dmd2\windows\bin\dmd.exe", "-shared", "-of.\source.exe.tmp", "-odC:\Users\\AppData\Local\Temp\.rdmd\rdmd-source.d-2F65A2D92BA75097EBFECC7FE8CC5156\objs", "-I.", "source.d"]
stat C:\Users<user>\AppData\Local\Temp.rdmd\rdmd-source.d-2F65A2D92BA75097EBFECC7FE8CC5156\objs
rmdirRecurse C:\Users<user>\AppData\Local\Temp.rdmd\rdmd-source.d-2F65A2D92BA75097EBFECC7FE8CC5156\objs
mv .\source.exe.tmp .\source.exe

Using -of manually is a workaround. But I think RDMD should try to be more intelligent about the default output file name based on whether -shared is passed in or not.

Please try this patch:

From 0b0c1d5e1973da30910a52f88022f79479fca7dc Mon Sep 17 00:00:00 2001
From: Vladimir Panteleev <git@cy.md>
Date: Sun, 30 Apr 2023 06:25:17 +0000
Subject: [PATCH] rdmd: Support -shared in the same way as -lib

---
 rdmd.d | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/rdmd.d b/rdmd.d
index d02cacc..5eeb373 100755
--- a/rdmd.d
+++ b/rdmd.d
@@ -27,6 +27,7 @@ version (Posix)
     enum objExt = ".o";
     enum binExt = "";
     enum libExt = ".a";
+    enum dllExt = ".so";
     enum altDirSeparator = "";
 }
 else version (Windows)
@@ -34,6 +35,7 @@ else version (Windows)
     enum objExt = ".obj";
     enum binExt = ".exe";
     enum libExt = ".lib";
+    enum dllExt = ".dll";
     enum altDirSeparator = "/";
 }
 else
@@ -242,10 +244,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)
@@ -360,7 +367,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", ".def", ".map", ".res") &&
                 args[i - 1] != "--eval")
         {
             return i;
-- 
2.40.0
commented

Seems to do the trick!

@CyberShadow could you PR this?

OK, here it is: #458