Dplug icon indicating copy to clipboard operation
Dplug copied to clipboard

Going nurt

Open p0nce opened this issue 8 months ago • 2 comments

Probably would fix #912 , the other benefits being:

  • a lack of #912 in the future, this was always a bit fishy ever since we left druntume uninitialized in 2016, however the new druntime hook itself with the C runtime in a way we can't avoid in a shared lib
  • [x] possibly less binary size => yes

p0nce avatar Apr 01 '25 15:04 p0nce

Current nurt is >= LDC 1.38, which would work ok probably (EDIT: and very hard to bring support for earlier compilers)

=> Must be possible, of course, to build the same plugin with and without nurt

p0nce avatar Apr 01 '25 16:04 p0nce

OK, got a first executable that print hello world.

Final executable must have the hookset dependency, and should also coerce the right subConfiguration it seems, else DUB will try (and fail) to create a nurt.dll

    "dependencies": 
    {
        "nurt": ">=0.1.4 <2.0.0",
        "numem": ">=0.2.0",
        "numem:hookset-libc": ">=0.2.0"
    },
 

    "subConfigurations": {
        "nurt": "ldc-static"
    }

main.d

import core.stdc.stdio;
import core.stdc.stdlib;

void main(string[] args) 
{ 
    printf("Hello\n");
}

Calling core.stdc stuff seems to work ok, but defeat a bit the portability goal of nurt. Still as a first step it's kinda useful to remove all traces of druntime and Phobos.

That hello world builds fast and is only 142kb!

p0nce avatar Apr 02 '25 11:04 p0nce

Nowadays, nurt can be disabled until only nurt is used.

Transition will go down as follow:

    1. Dplug and libraries start depending on ~~nurt~~ nulib, which becomes a dependency of most things in dplug.
    1. Transition period
    1. Individual project can depend and enable nurt

p0nce avatar Nov 17 '25 12:11 p0nce

Trying to do a regular executable with nurt, there is a crash in audioformats at stream destruction it seems. => OK, it was the use of emplace/destroy

p0nce avatar Nov 18 '25 09:11 p0nce

Better understanding now of the plan.

Image

p0nce avatar Nov 19 '25 14:11 p0nce

  • [x] extern(C++) classes don't build with nogc_trydelete, the FLP client is an extern(C++) class that was allocated with malloc not the C++ runtime, but numem want to do it differently. And it's not C++ but Delphi interface. Do we need this extern(C++), probably yes, and can we emplace it like before?
    • [ ] It works when constructed by the C++ runtime, on Windows. Which was unexpected. Still, we may need in the future to call nogc_construct for emplace. mallocNew will provide that distinction :) not sure what else in Dplug uses extern(C++) like that, probably nothing when making new extern(C++) objects, or call a separate function.
  • [x] Need to check the Linux build order since allegedly numem would need a special link order to work. Need to check a working program on Linux. (with both dub and redub). "Redub solves circular linker issues while dub does not", I'm told. => not seeing that, instead it's redub that has a few difficulties with numem. In my tests using redub wasn't necessary, but Luna told otherwise... 🤔
  • [ ] Evaluate carefully each use of exp/pow/log/exp2/log10/log2/ldexp, since Phobos has its own implementation with unknown precision characteristics, it's a bad practice to rely on that though it's perfectly possible that it sounds different or even better... annoying task

p0nce avatar Nov 19 '25 15:11 p0nce

~~I think it's going to be way smoother than expected.~~ We only have to transition to numem, wait until eliminating old stuff, and then enable nurt.

p0nce avatar Nov 20 '25 15:11 p0nce

  • [x] Adding nurt+numem+nulib is adding 5 packages, which is a bit much. :/ Only adding numem+nurt would be a perhaps leaner, since they all depend on libc anyway for the foreseeable future.
  • [x] Is nulib working on macOS? The sub-package dependency is seemingly gone. => not using it
  • [x] redub can't build dplug:vst2 for now (envvar stuff)
  • [x] redub can't build plugins in Windows (fixed)
  • [x] Give access to --breadth flag from dplug-build
  • [x] adapt dplug-build heuristic to find the binary that redub output => no need
  • [x] remove Ddoc warning from dplug:x11
  • [x] remove Ddoc warning from wren-port
  • [x] can build existing DPlug plugins with redub on Linux => OK
  • [x] can build DPlug plugin + numem on Linux => not OK in --final, error. =>Fix and PR in numem
  • [x] Check built plugins with dub and redub => both works on Linux, stripped size OK
  • [x] numem working on macOS within a plug-in, no issue with redub there either, stripped size OK

p0nce avatar Nov 24 '25 09:11 p0nce