When using ImportC sources inside a dub package, dependent packages cannot import the corresponding C modules.
Minimal reproduction:
Project structure:
<root>
│ appbar.d
│ dub.json
└───pkg
├───include
│ libfoo.h
└───src
libfoo.c
dub.json
{
"name": "bar",
"targetType": "executable",
"sourceFiles": ["appbar.d"],
"subPackages": [
{
"name": "foo",
"cSourcePaths": ["pkg/src"],
"cImportPaths": ["pkg/include"],
"targetType": "library"
}
],
"dependencies": { ":foo": "*" }
}
pkg/src/libfoo.c
int foo(void) { return 42; }
pkg/include/libfoo.h
appbar.d
module appbar;
import std;
import libfoo;
void main()
{
writeln(foo());
}
Build result:
> dub build
Starting Performing "debug" build using <dmd_path>\bin64\dmd.exe for x86_64.
Up-to-date bar:foo ~master: target for configuration [library] is up to date.
Building bar ~master: building configuration [application]
appbar.d(3,8): Error: unable to read module `libfoo`
import libfoo;
^
appbar.d(3,8): Expected 'libfoo.d' or 'libfoo\package.d' in one of the following import paths:
import path[0] = <dmd_path>\bin64\..\import
The immediate failure is that dependent packages cannot import ImportC modules from dependencies.
More fundamentally, dub currently has no supported mechanism to expose ImportC interfaces across package boundaries without recompiling dependency C sources.
However, simply propagating cSourcePaths is likely insufficient, because dependent builds would then recompile the same C sources and produce duplicate symbols.
This exposes a larger architectural issue around ImportC dependency handling:
- dependent packages require ImportC semantic information
- but recompiling dependency C sources is incorrect
- dub currently has no supported mechanism to expose ImportC interfaces across package boundaries without recompiling C sources
Possible directions may include:
- propagating ImportC interface metadata separately from C source compilation
.di-based workflows
- semantic-only ImportC handling
- other forms of generated interface artifacts
Note that current compiler .di generation for ImportC sources also appears incomplete, so this may require coordination with compiler-side support as well.
When using ImportC sources inside a dub package, dependent packages cannot import the corresponding C modules.
Minimal reproduction:
Project structure:
dub.json{ "name": "bar", "targetType": "executable", "sourceFiles": ["appbar.d"], "subPackages": [ { "name": "foo", "cSourcePaths": ["pkg/src"], "cImportPaths": ["pkg/include"], "targetType": "library" } ], "dependencies": { ":foo": "*" } }pkg/src/libfoo.cpkg/include/libfoo.happbar.dBuild result:
The immediate failure is that dependent packages cannot import ImportC modules from dependencies.
More fundamentally, dub currently has no supported mechanism to expose ImportC interfaces across package boundaries without recompiling dependency C sources.
However, simply propagating
cSourcePathsis likely insufficient, because dependent builds would then recompile the same C sources and produce duplicate symbols.This exposes a larger architectural issue around ImportC dependency handling:
Possible directions may include:
.di-based workflowsNote that current compiler
.digeneration for ImportC sources also appears incomplete, so this may require coordination with compiler-side support as well.