dub icon indicating copy to clipboard operation
dub copied to clipboard

Compilation for library type doesn't work when dub project contains "mainSourceFile"

Open ryuukk opened this issue 3 years ago • 4 comments

System information

  • dub version: 1.29.1
  • OS Platform and distribution: Windows 10
  • compiler version v2.100.1

Bug Description

Compilation doesn't work, dmd will not report problems

How to reproduce?

{
    "name": "dll",
    "targetType": "dynamicLibrary",
    "mainSourceFile": "src/dllmain.d",
    "sourcePaths": [
        "src" ,
    ],
    "importPaths": [
        "src",
    ],
    "dflags": [
        "-betterC",
    ],
}
import core.sys.windows.windows;
import core.stdc.stdio;

sdsdsfdfdf

extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
{
    return true;
}

Expected Behavior

It should complain about sdsdsfdfdf

Solution

The solution was to remove the "mainSourceFile" from the dub.json file

ryuukk avatar Sep 03 '22 15:09 ryuukk

Same behavior with staticLibrary yes?

rikkimax avatar Sep 03 '22 15:09 rikkimax

Same with "staticLibrary", and same with "library"

ryuukk avatar Sep 03 '22 15:09 ryuukk

Ok, so a check some place is missing an exception for shared libraries.

rikkimax avatar Sep 03 '22 15:09 rikkimax

https://github.com/dlang/dub/blob/fe09137708faac9f334eb08ab7d18ec9c2bd6b5c/source/dub/generators/generator.d#L310

Change that goto to a break and it should work.

rikkimax avatar Sep 03 '22 15:09 rikkimax

mainSourceFile is excluded by default in libraries. We should probably warn / error if there is a mainSourceFile in a library configuration.

Geod24 avatar Dec 05 '22 13:12 Geod24