Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate-c fails for Windows Driver Kit (WDK) #14043

Open
thewavelength opened this issue Dec 23, 2022 · 0 comments
Open

translate-c fails for Windows Driver Kit (WDK) #14043

thewavelength opened this issue Dec 23, 2022 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@thewavelength
Copy link

Zig Version

0.11.0-dev.926+266e2e9a3

Steps to Reproduce and Observed Behavior

Try building minimal.zig:

const win = @import("std").os.windows;

const wdk = @cImport({
    //@cDefine("_NO_CRT_STDIO_INLINE", "1");
    //@cDefine("_NTDDK_", "1");
    //@cDefine("_WIN64", "1");
    //@cDefine("_WIN64_", "1");
    //@cDefine("_MSC_VER", "1933");
    //@cDefine("_MSC_VER_FULL", "193331630");
    @cDefine("_AMD64_", "1");
    @cInclude("wdm.h");
    //@cInclude("ntddk.h");
});

fn driverEntry(_: wdk.PDRIVER_OBJECT, _: *const win.UNICODE_STRING) callconv(.C) c_int {
    return 0;
}

comptime {
    @export(driverEntry, .{ .name = "DriverEntry" });
}

with this command line:

zig build-obj minimal.zig -I"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/include" -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/km" -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/shared" -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/ucrt" --verbose-cimport -target x86_64-windows-msvc -freference-trace

You need to have the following requirements (see MSDN for more info):

  • Windows SDK 10.0.22621.0
  • Windows Driver Kit (WDK) 10.0.22621.0

Error output:

info(compilation): C import output: test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig
test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig:1337:5: error: redeclaration of 'struct__COMPRESSED_DATA_INFO'
pub const struct__COMPRESSED_DATA_INFO = opaque {};
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig:1334:5: note: other declaration here
pub const struct__COMPRESSED_DATA_INFO = opaque {};
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig:6154:5: error: redeclaration of 'struct__KBUGCHECK_REASON_CALLBACK_RECORD'
pub const struct__KBUGCHECK_REASON_CALLBACK_RECORD = extern struct {
~~~~^~~~~
test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig:6150:5: note: other declaration here
pub const struct__KBUGCHECK_REASON_CALLBACK_RECORD = opaque {};
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig:6698:5: error: redeclaration of 'struct__DEVICE_OBJECT'
pub const struct__DEVICE_OBJECT = opaque {};
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test\zig-cache\o\8335af4a1accae1cd499dd683dd36e05\cimport.zig:1696:5: note: other declaration here
pub const struct__DEVICE_OBJECT = extern struct {
~~~~^~~~~
minimal.zig:3:13: error: C import failed: AnalysisFail
const wdk = @cImport({
            ^~~~~~~~

referenced by:
    driverEntry: minimal.zig:15:19

I attached the generated cimport.zig.

Expected Behavior

@cImport should behave correctly.

@thewavelength thewavelength added the bug Observed behavior contradicts documented or intended behavior label Dec 23, 2022
@Vexu Vexu added the translate-c C to Zig source translation feature (@cImport) label Dec 23, 2022
@Vexu Vexu added this to the 0.11.0 milestone Dec 23, 2022
@Vexu Vexu modified the milestones: 0.11.0, 0.12.0 Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

2 participants