MrcSnm / redub

Alternative implementation of dub, speed and consistency oriented
https://code.dlang.org/packages/redub
MIT License
37 stars 8 forks source link

Crash building #7

Closed kassane closed 6 months ago

kassane commented 10 months ago

Testing Environment

OS: ArchLinux & Windows 11 Arch: x86_64 (zen) Compiler: ldc2-master (1.36.0+)

I tried to run redub during my tests for dub support. But I didn't expect it to fail because it doesn't happen with dub.

redub build ```bash $> LD_LIBRARY_PATH=$PWD/zig-out/lib dub run redub -y -- :clear --compiler=ldc2 Building package redub in /home/kassane/.dub/packages/redub/1.2.13/redub/ Warning Warning ## Warning for package redub ## Warning Warning The following compiler flags have been specified in the package description Warning file. They are handled by DUB and direct use in packages is discouraged. Warning Alternatively, you can set the DFLAGS environment variable to pass custom flags Warning to the compiler, or use one of the suggestions below: Warning Warning debugMode: Call DUB with --build=debug Warning debugInfo: Call DUB with --build=debug Warning Starting Performing "debug" build using ldc2 for x86_64. Up-to-date colorize ~master: target for configuration [library] is up to date. Up-to-date semver ~master: target for configuration [library] is up to date. Up-to-date redub 1.2.13: target for configuration [cli] is up to date. Finished To force a rebuild of up-to-date targets, run again with --force Running ../.dub/packages/redub/1.2.13/redub/build/redub :clear --compiler=ldc2 Dependencies resolved in 22 ms. Build Failure: 'clear [] ' using flags 'ldc2' --enable-color=true --d-version=Have_clear -I/home/kassane/sokol-d/src -c --od=/tmp/.redub --of=/home/kassane/sokol-d/build/clear.o /home/kassane/sokol-d/src/examples/clear.d /home/kassane/sokol-d/src/sokol/log.d /home/kassane/sokol-d/src/sokol/utils.d /home/kassane/sokol-d/src/sokol/audio.d /home/kassane/sokol-d/src/sokol/debugtext.d /home/kassane/sokol-d/src/sokol/gfx.d /home/kassane/sokol-d/src/sokol/gl.d /home/kassane/sokol-d/src/sokol/shape.d /home/kassane/sokol-d/src/sokol/time.d /home/kassane/sokol-d/src/sokol/glue.d /home/kassane/sokol-d/src/sokol/app.d /home/kassane/sokol-d/src/examples/clear.d /home/kassane/sokol-d/src/handmade/math.d /home/kassane/sokol-d/src/shaders/blend.d /home/kassane/sokol-d/src/shaders/bufferoffsets.d /home/kassane/sokol-d/src/shaders/cube.d /home/kassane/sokol-d/src/shaders/instancing.d /home/kassane/sokol-d/src/shaders/mrt.d /home/kassane/sokol-d/src/shaders/noninterleaved.d /home/kassane/sokol-d/src/shaders/offscreen.d /home/kassane/sokol-d/src/shaders/quad.d /home/kassane/sokol-d/src/shaders/shapes.d /home/kassane/sokol-d/src/shaders/texcube.d Failed after 6041ms with message Error: module `examples.clear` from file /home/kassane/sokol-d/src/examples/clear.d is specified twice on the command line object.Error@(0): Build failure ---------------- ??:? [0x5ef5a3f0a13e] ??:? [0x5ef5a3f09db2] ??:? [0x5ef5a3f3043e] ??:? [0x5ef5a3f11a6f] ../.dub/packages/redub/1.2.13/redub/source/redub/api.d:84 [0x5ef5a3e8ea9d] ../.dub/packages/redub/1.2.13/redub/source/app.d:70 [0x5ef5a3e8f8cb] ../.dub/packages/redub/1.2.13/redub/source/app.d:63 [0x5ef5a3e8f746] ??:? [0x5ef5a3f1174c] ??:? [0x5ef5a3f11646] ??:? [0x5ef5a3f1149c] /home/kassane/ldcup/ldc2-bb083913-linux-x86_64/bin/../import/core/internal/entrypoint.d:42 [0x5ef5a3e91851] ??:? [0x7679dd1f7ccf] ??:? __libc_start_main [0x7679dd1f7d89] ??:? [0x5ef5a3e35b04] Error Program exited with code 1 ```
dub build ```bash $> LD_LIBRARY_PATH=$PWD/zig-out/lib dub :clear --compiler=ldc2 Starting Performing "debug" build using ldc2 for x86_64. Up-to-date sokol-d:clear 0.1.0: target for configuration [application] is up to date. Finished To force a rebuild of up-to-date targets, run again with --force Running build/sokol-d_clear Backend: Glcore33 ```

Reference

MrcSnm commented 10 months ago

Please do try with 1.2.14

kassane commented 10 months ago

master version

LD_LIBRARY_PATH=$PWD/zig-out/lib ../redub/build/redub :clear --compiler=ldc2
/home/kassane/sokol-d/src/examples/clear.d
/home/kassane/sokol-d/build/libsokol.a
std.exception.ErrnoException@std/stdio.d(682): Cannot open file `/home/kassane/sokol-d/build/libsokol.a' in mode `rb' (No such file or directory)
----------------
??:? [0x588dbc60d04e]
??:? [0x588dbc60ccc2]
??:? [0x588dbc6333be]
??:? [0x588dbc6149ef]
/home/kassane/ldcup/ldc2-bb083913-linux-x86_64/bin/../import/std/exception.d:522 [0x588dbc5a95d5]
??:? [0x588dbc5d1adf]
??:? [0x588dbc5f0fa3]
adv_diff/source/redub/libs/adv_diff/files.d:167 [0x588dbc5c7c78]
source/redub/building/cache.d:150 [0x588dbc5a1c71]
source/redub/building/cache.d:110 [0x588dbc5a1f46]
source/redub/api.d:147 [0x588dbc5a4f60]
source/app.d:231 [0x588dbc5a6203]
source/app.d:70 [0x588dbc5a53ec]
source/app.d:63 [0x588dbc5a5228]
??:? [0x588dbc6146cc]
??:? [0x588dbc6145c6]
??:? [0x588dbc61441c]
??:? [0x7a1f85cdfccf]
??:? __libc_start_main [0x7a1f85cdfd89]
??:? [0x588dbc573b24]

Why /home/kassane/sokol-d/build/libsokol.a, wrong path? libsokol isn't static (search *.so)!!

My dub.sdl:

libs "sokol"
lflags "-Lzig-out/lib" platform="posix"
ldflags "/LIBPATH:zig-out/lib" platform="windows"
MrcSnm commented 10 months ago

I'm current refactoring the up to date system. Right now it does not support using shared libraries as a dependency. If it is something just as simple as passing the .dll files to the linker I may implement it right after the refactor

kassane commented 10 months ago

I understand. No worries!😅

I'm still learning about dub/redub, in addition to Dlang.

I'm still confused about ldc2's limitation on Windows libraries and the dub doesn't seem friendly to me for adding conditioned dependencies. 🤔

MrcSnm commented 10 months ago

My engine uses dll with no problems, which problem you're having with shared libraries? Usually I dynamically load them

kassane commented 10 months ago

which problem you're having with shared libraries? Usually I dynamically load them

Exactly, shared lib". So, just dynamic library loader. :thinking: I use static libraries by default (in zig build) all targets [ :heavy_check_mark: ]. But for re/dub support I thought about just adding shared. [ :x: ]

MrcSnm commented 6 months ago

@kassane Maybe you could try it again on the latest version? There were a lot of updates since the last time you tried

kassane commented 6 months ago

Fail

note: libsokol - shared-library

sokol-d build ```bash $ redub build --compiler=ldc2 :clear Project clear requires rebuild. Dependencies resolved in 15 ms for "debug" using ldc2 Build Failure: 'clear []' Redub v1.3.19 ldc 1.38.0-git-f259534-dirty Failed with flags: 'ldc2' --enable-color=true --oq -d-debug -g --d-version=Have_clear -I/home/kassane/sokol-d/src -c --od=/tmp/.redub --of=/home/kassane/sokol-d/build/clear.o /home/kassane/sokol-d/src/examples/clear.d /home/kassane/sokol-d/src/examples/clear.d /home/kassane/sokol-d/src/handmade/math.d /home/kassane/sokol-d/src/shaders/blend.d /home/kassane/sokol-d/src/shaders/bufferoffsets.d /home/kassane/sokol-d/src/shaders/cube.d /home/kassane/sokol-d/src/shaders/instancing.d /home/kassane/sokol-d/src/shaders/mrt.d /home/kassane/sokol-d/src/shaders/noninterleaved.d /home/kassane/sokol-d/src/shaders/offscreen.d /home/kassane/sokol-d/src/shaders/quad.d /home/kassane/sokol-d/src/shaders/shapes.d /home/kassane/sokol-d/src/shaders/texcube.d /home/kassane/sokol-d/src/sokol/app.d /home/kassane/sokol-d/src/sokol/audio.d /home/kassane/sokol-d/src/sokol/debugtext.d /home/kassane/sokol-d/src/sokol/gfx.d /home/kassane/sokol-d/src/sokol/gl.d /home/kassane/sokol-d/src/sokol/glue.d /home/kassane/sokol-d/src/sokol/log.d /home/kassane/sokol-d/src/sokol/shape.d /home/kassane/sokol-d/src/sokol/time.d /home/kassane/sokol-d/src/sokol/utils.d Failed after 5962ms with message Error: module `examples.clear` from file /home/kassane/sokol-d/src/examples/clear.d is specified twice on the command line Warning: If you think this is a bug on redub, do test with dub, if it works, do file an issue at https://github.com/MrcSnm/redub/issues/new/choose object.Error@(0): Build failure ---------------- ??:? [0x5a2dc521ff6e] ??:? [0x5a2dc521fbd2] ??:? [0x5a2dc52470be] ??:? [0x5a2dc522802f] source/redub/api.d:92 [0x5a2dc51abe87] source/app.d:180 [0x5a2dc51acbfd] ??:? [0x5a2dc5227d0c] ??:? [0x5a2dc5227c06] ??:? [0x5a2dc5227a5c] ??:? [0x75fd4a001c87] ??:? __libc_start_main [0x75fd4a001d4b] ??:? [0x5a2dc5179b54] $ dub build --compiler=ldc2 :clear Starting Performing "debug" build using ldc2 for x86_64. Building sokol-d:clear 0.1.0: building configuration [application] Pre-build Running commands Linking sokol-d_clear ```

OK

note: libgc/libgccpp - static-libraries

bdwgc-d build ```bash $ redub build --compiler=ldc2 :example1 Dependencies resolved in 13 ms for "debug" using ldc2 Up-to-Date: example1 []. Took 0ms Up-to-Date: example1, skipping linking Built project in 0 ms. $ dub build --compiler=ldc2 :example1 Starting Performing "debug" build using ldc2 for x86_64. Building bdwgc-d:example1 0.2.1: building configuration [application] Pre-build Running commands ```
MrcSnm commented 6 months ago
  1. I've noticed that you used glob patterns on exclude. I haven't implemented this and need to think how to do that
  2. I've also noticed that you do specify the additional sourceFile. The problem with that is as this is inside the sourceFolder, it is searched recursively, so, it is found without you needing to specify it. The behavior of dub is probably simply deleting duplicates. I 2.1. I kinda wanna turn this into an error instead since it is handling what it should not. My solution for you would be instead of excluding examples by name, you simply do a glob pattern on them:
"excludedSourceFiles": [
                "src/examples/*.d",
                "src/shaders/*.d"
            ],
            "name": "clear",
            "sourceFiles": [
                "src/examples/clear.d"
            ],

So, this is kinda of an issue in how dub works also. So, for this issue, I'll do the following:

  1. Implement glob patterns on files
  2. Issue an error when adding a file via both sourcePath + sourceFiles

What do you think about that @kassane

MrcSnm commented 6 months ago

@kassane This has been fixed at v1.3.20, please test it :)

kassane commented 6 months ago

@MrcSnm , sorry delay...

Not building file...

@@ -32,109 +32,109 @@ subPackage {
    name "clear"
    targetType "executable"
    targetPath "build"
        libs "sokol"
    sourceFiles "src/examples/clear.d"
    lflags "-Lzig-out/lib" platform="posix"
    lflags "/LIBPATH:zig-out/lib" platform="windows"
-   excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d"
+   excludedSourceFiles "src/examples/*.d" "src/shaders/*.d"
    preBuildCommands "zig build -Dshared -Doptimize=ReleaseFast"
 }
$ redub build -b release --compiler=ldc2 :clear
Dependencies resolved in 13 ms for "release" using ldc2
Up-to-Date: clear  []. Took 0ms
Up-to-Date: clear, skipping linking
Built project in 0 ms.

$ dub build -b release --compiler=ldc2 :clear    Starting Performing "release" build using ldc2 for x86_64.
    Building sokol-d:clear 0.1.0: building configuration [application]
   Pre-build Running commands
     Linking sokol-d_clear
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1
Error ldc2 failed with exit code 1.
MrcSnm commented 6 months ago

So, dub can't process the file with the given changes? :(

kassane commented 6 months ago

So, dub can't process the file with the given changes? :(

So, actually the dub is correct because the file was not created but redub did not report an error.

MrcSnm commented 6 months ago

What happened was that redub reported that it was up to date, even skipping linking. This might be a bug since it should see also if the binary is up to date

kassane commented 6 months ago

Why re/dub clean not remove targetPath & builded files? Only pkg/deps file.

MrcSnm commented 6 months ago

Because one may need to distribute some .dll/.so files in the same path

MrcSnm commented 6 months ago

So, dub can't process the file with the given changes? :(

So, actually the dub is correct because the file was not created but redub did not report an error.

@kassane I have fixed that in the latest version. This bug was that was killing my rebuilding and now it has finally got stability on the up to date cache :)

kassane commented 6 months ago

Nice work @MrcSnm

Note: While testing this issue, a behavioral incompatibility between dub and redub was noted.

Build test again

Diff ```diff @@ -32,109 +32,109 @@ subPackage { name "clear" targetType "executable" targetPath "build" libs "sokol" sourceFiles "src/examples/clear.d" lflags "-Lzig-out/lib" platform="posix" lflags "/LIBPATH:zig-out/lib" platform="windows" - excludedSourceFiles "src/examples/sgl_context.d" "src/examples/triangle.d" "src/examples/sgl_points.d" "src/examples/saudio.d" "src/examples/debugtext.d" "src/examples/mrt.d" "src/examples/user_data.d" "src/examples/cube.d" "src/examples/blend.d" "src/shaders/*.d" + excludedSourceFiles "src/examples/*.d" "src/shaders/*.d" preBuildCommands "zig build -Doptimize=ReleaseFast" } ```
Output ```sh $ redub --version Redub v1.3.27 - A reimagined DUB $ redub build -b release :clear Warning: The compiler 'dmd' that was specified in your system wasnt found. Redub found ldc2 and it will use for this compilation. Project clear requires rebuild. Dependencies resolved in 18 ms for "release" using ldc2 Built: clear []. Took 793ms Linked: clear finished! Built project in 878 ms. $ ls build/ total 916 -rwxr-xr-x 1 kassane kassane 731512 2024-05-15 16:48 clear -rw-r--r-- 1 kassane kassane 202656 2024-05-15 16:48 clear.o # RUN $ ./build/clear # REMOVE built & cached files $ rm -fr build zig-* $ redub build -b release :clear Warning: The compiler 'dmd' that was specified in your system wasnt found. Redub found ldc2 and it will use for this compilation. Project clear requires rebuild. Dependencies resolved in 17 ms for "release" using ldc2 Built: clear []. Took 5991ms Linked: clear finished! Built project in 6073 ms. $ ls build/ total 916 -rwxr-xr-x 1 kassane kassane 731512 2024-05-15 16:48 clear -rw-r--r-- 1 kassane kassane 202656 2024-05-15 16:48 clear.o $ rm -fr build $ dub build -b release :clear Starting Performing "release" build using ldc2 for x86_64. Building sokol-d:clear 0.1.1: building configuration [application] Pre-build Running commands Linking sokol-d_clear /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib/Scrt1.o: in function `_start': (.text+0x1b): undefined reference to `main' collect2: error: ld returned 1 exit status Error: /usr/bin/cc failed with status: 1 Error /home/kassane/zig-bootstrap/out/host-xtensa/bin/ldc2 failed with exit code 1. ```
kassane commented 6 months ago

For current status, solve my issue... (update sokol-d v0.1.1 used on latest test, now is static-lib for re/dub). I want to understand exactly how to make it usable using your redub together with dub.

Questions about

Not sure if I misunderstood, but while testing using redub, noticed that it requires dub installed to convert the sdl to json. Right? Could it be viable for a project to use both formats or would dub cause some kind of conflict?

Hide dub from redub

$ redub build -b release :clear
Warning: The compiler 'dmd' that was specified in your system wasn't found. Redub found ldc2 and it will use for this compilation.
object.Exception@source/redub/parsers/sdl.d(26): dub could not convert file at path /home/kassane/sokoldd/dub.sdl to json: /bin/sh: line 1: dub: command not found
MrcSnm commented 6 months ago

@kassane The best way to support both of them is by using JSON for both. Since JSON is supported out of the box from D, it was the language of choice. The thing about it is that I wanted to reduce complexity from dub codebase, so, supporting one less language makes it easier.

Also, from what I understood, looks like dub executes the exclude after the include (which IMO is pretty wrong. There's no sense into excluding explicitly defined sources)