A DUB project with only kernel files cannot be built
When I run dub on such a project, I get the error message below:
Performing "debug" build using ldc2 for x86_64.
dcompute-library ~master: building configuration "library"...
/usr/local/include/d/core/internal/array/equality.d(73,119): Error: can only call functions from other @compute modules in @compute code
/usr/local/include/d/core/internal/array/equality.d(79,23): Error: can only call functions from other @compute modules in @compute code
/usr/local/include/d/core/internal/array/equality.d(79,37): Error: can only call functions from other @compute modules in @compute code
ldc2 failed with exit code 1.
What are you trying to do? Can you minimise the project that causes this problem?
That line (73)is return () @trusted { return memcmp(cast(void*)lhs.ptr, cast(void*)rhs.ptr, lhs.length * U1.sizeof) == 0; }();, which makes sense, you could mark core.stdc.string @compute(CompileFor.hostAndDevice). Please try that and report back.
It seems that the semantic analysis delves into if(__ctfe) code which I will need to fix.
The minimum project is like below:
├── dub.sdl
└── source
└── testkernel.d
and the content of testkernel.d is:
@compute(CompileFor.deviceOnly)
module testkernel;
import ldc.dcompute;
import dcompute.std.index;
@kernel void testKernel() {}
I tried marking core.stdc.string, but it causes the same error.
This error seems to be caused by not only call of memcmp but also surrounding closure.
And marking the closure @compute causes another error:
Failed to invoke the compiler ldc2 to determine the build platform: binary /usr/local/bin/ldc2
version 1.19.0-git-c104917-dirty (DMD v2.089.0, LLVM 9.0.0)
config /usr/local/etc/ldc2.conf (x86_64-pc-linux-gnu)
predefs LDC all D_Version2 assert D_ModuleInfo D_Exceptions D_TypeInfo X86_64 D_InlineAsm_X86_64 D_HardFloat LittleEndian D_LP64 D_PIC linux Posix CRuntime_Glibc CppRuntime_Gcc LDC_LLVM_900
parse dub_platform_probe_c43c1bb1_5539_48eb_b94d_f00ea1c066af
importall dub_platform_probe
import object (/usr/local/include/d/object.d)
import core.internal.hash (/usr/local/include/d/core/internal/hash.d)
import core.internal.traits (/usr/local/include/d/core/internal/traits.d)
import core.internal.convert (/usr/local/include/d/core/internal/convert.d)
import core.internal.entrypoint (/usr/local/include/d/core/internal/entrypoint.d)
import core.internal.array.appending (/usr/local/include/d/core/internal/array/appending.d)
import core.internal.array.comparison (/usr/local/include/d/core/internal/array/comparison.d)
import core.internal.array.equality (/usr/local/include/d/core/internal/array/equality.d)
/usr/local/include/d/core/internal/array/equality.d(73): Error: user-defined attributes cannot appear as postfixes
import core.internal.array.casting (/usr/local/include/d/core/internal/array/casting.d)
import core.internal.array.concatenation (/usr/local/include/d/core/internal/array/concatenation.d)
import core.internal.array.construction (/usr/local/include/d/core/internal/array/construction.d)
import core.internal.array.capacity (/usr/local/include/d/core/internal/array/capacity.d)
import core.internal.dassert (/usr/local/include/d/core/internal/dassert.d)
import core.internal.destruction (/usr/local/include/d/core/internal/destruction.d)
import core.internal.moving (/usr/local/include/d/core/internal/moving.d)
import core.internal.postblit (/usr/local/include/d/core/internal/postblit.d)
import core.internal.switch_ (/usr/local/include/d/core/internal/switch_.d)
https://github.com/ldc-developers/ldc/pull/3253 fixes the __ctfe issue.
can you use dub -v to print the command line? I want to see what else is on it.
> dub --compiler=ldc2 --verbose
Using dub registry url 'https://code.dlang.org/'
Refreshing local packages (refresh existing: true)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/sobaya/.dub/packages/local-packages.json
Note: Failed to determine version of package dcompute-bug at .. Assuming ~master.
Refreshing local packages (refresh existing: false)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/sobaya/.dub/packages/local-packages.json
Found dependency dcompute ~master
Found dependency derelict-cl 3.2.0
Found dependency derelict-util 3.0.0-beta.2
Found dependency derelict-cuda 3.1.1
Found dependency taggedalgebraic 0.10.13
Refreshing local packages (refresh existing: false)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/sobaya/.dub/packages/local-packages.json
Found dependency dcompute ~master
Found dependency derelict-cl 3.2.0
Found dependency derelict-util 3.0.0-beta.2
Found dependency derelict-cuda 3.1.1
Found dependency taggedalgebraic 0.10.13
WARNING: A deprecated branch based version specification is used for the dependency dcompute. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
Generating using build
Configuring dependent dcompute-bug, deps:"dcompute"
Configuring dependent dcompute, deps:"derelict-cl", "derelict-cuda", "taggedalgebraic"
Configuring dependent derelict-cl, deps:"derelict-util"
Configuring dependent derelict-util, deps:
Configuring dependent derelict-cuda, deps:"derelict-util"
Configuring dependent taggedalgebraic, deps:
Performing "debug" build using ldc2 for x86_64.
Target '/home/sobaya/dtest/dcompute-bug/.dub/build/library-debug-linux.posix-x86_64-ldc_2089-E6F781B3C53D5E4B05BDC82F9BA1761C/libdcompute-bug.a' doesn't exist, need rebuild.
dcompute-bug ~master: building configuration "library"...
Ignoring all import libraries for static library build.
ldc2 -mdcompute-targets=cuda-210 -oq -lib -of.dub/build/library-debug-linux.posix-x86_64-ldc_2089-E6F781B3C53D5E4B05BDC82F9BA1761C/libdcompute-bug.a -d-debug -g -w -oq -od=.dub/obj -d-version=Have_dcompute_bug -d-version=Have_dcompute -d-version=Have_derelict_cl -d-version=Have_derelict_cuda -d-version=Have_taggedalgebraic -d-version=Have_derelict_util -Isource/ -I../../.dub/packages/dcompute-master/dcompute/source/ -I../../.dub/packages/derelict-cl-3.2.0/derelict-cl/source/ -I../../.dub/packages/derelict-util-3.0.0-beta.2/derelict-util/source/ -I../../.dub/packages/derelict-cuda-3.1.1/derelict-cuda/source -I../../.dub/packages/taggedalgebraic-0.10.13/taggedalgebraic/source/ source/testkernel.d -vcolumns
/usr/local/include/d/core/internal/array/equality.d(73,119): Error: can only call functions from other `@compute` modules in `@compute` code
/usr/local/include/d/core/internal/array/equality.d(79,23): Error: can only call functions from other `@compute` modules in `@compute` code
/usr/local/include/d/core/internal/array/equality.d(79,37): Error: can only call functions from other `@compute` modules in `@compute` code
FAIL .dub/build/library-debug-linux.posix-x86_64-ldc_2089-E6F781B3C53D5E4B05BDC82F9BA1761C/ dcompute-bug staticLibrary
ldc2 failed with exit code 1.
Now this issue is fixed, but another issue has occurred.
LDC does not crush, but it says "Error: no object files".