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

Compilation error on stage2 with @cImport and SDL2 #12737

Closed
Tracked by #180
sagehane opened this issue Sep 4, 2022 · 5 comments
Closed
Tracked by #180

Compilation error on stage2 with @cImport and SDL2 #12737

sagehane opened this issue Sep 4, 2022 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@sagehane
Copy link
Contributor

sagehane commented Sep 4, 2022

Zig Version

0.10.0-dev.3871+b7d5582de

Steps to Reproduce

Build/run a file using SDL2 without -fstage1.

Sample test.zig file with SDL2:

const c = @cImport(
    @cInclude("SDL2/SDL.h"),
);

comptime {
    _ = c;
}

pub fn main() void {}

Notes

Reproduced on NixOS and Guix.
The Guix user who helped me test this bug couldn't reproduce it on 0.10.0-dev.3838+77f31ebbb, which suggests its a regression.

I also couldn't reproduce this bug with Raylib, meaning the extent of this breakage isn't to all imported C libraries.

Expected Behavior

It should behave the same as with stage1:

$ zig run test.zig -lc -lSDL2 -fstage1 && echo hi
hi

Actual Behavior

$ zig run test.zig -lc -lSDL2
/home/<user>/.cache/zig/o/8e09ae690747d858ba9b2bca9e76ec36/cimport.zig:2271:5: error: redeclaration of '__mm_storeh_pi_struct'
pub const __mm_storeh_pi_struct = @compileError("cannot translate packed record union"); // /nix/store/ciigv5x04k16fyvqlwbwanknmngz6sly-zig-0.10.0-dev.3871+b7d5582de/lib/zig/include/xmmintrin.h:1948:10
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/<user>/.cache/zig/o/8e09ae690747d858ba9b2bca9e76ec36/cimport.zig:2260:5: note: other declaration here
pub const __mm_storeh_pi_struct = @compileError("cannot translate packed record union"); // /nix/store/ciigv5x04k16fyvqlwbwanknmngz6sly-zig-0.10.0-dev.3871+b7d5582de/lib/zig/include/xmmintrin.h:1927:10
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<omitted>
/home/<user>/.cache/zig/o/8e09ae690747d858ba9b2bca9e76ec36/cimport.zig:17994:18: error: use of undeclared identifier 'struct___storeu_i64'
    @ptrCast([*c]struct___storeu_i64, @alignCast(@import("std").meta.alignment([*c]struct___storeu_i64), __P_1)).*.__v = @bitCast(c_longlong, @as(c_ulonglong, __builtin_bswap64(@bitCast(c_ulong, @truncate(c_long, __D)))));
                 ^~~~~~~~~~~~~~~~~~~
test.zig:1:11: error: C import failed: AnalysisFail
const c = @cImport(
          ^~~~~~~~
@sagehane sagehane added the bug Observed behavior contradicts documented or intended behavior label Sep 4, 2022
@Vexu
Copy link
Member

Vexu commented Sep 4, 2022

See #12733

@Vexu Vexu closed this as completed Sep 4, 2022
@nektro
Copy link
Contributor

nektro commented Sep 4, 2022

that's different. the issue here is

  • error: redeclaration of '__mm_storeh_pi_struct'
  • error: use of undeclared identifier 'struct___storeu_i64'

@Vexu Vexu reopened this Sep 4, 2022
@Vexu Vexu added the translate-c C to Zig source translation feature (@cImport) label Sep 4, 2022
@Vexu Vexu added this to the 0.10.0 milestone Sep 4, 2022
@michal-z
Copy link
Contributor

michal-z commented Sep 4, 2022

I'm hitting the same problem. This is a regression introduced by #12723

C:\Development\projects\zig-gamedev\zig-cache\o\3367f8690c85323febb96ffeac1bea59\cimport.zig:12988:5: error: redeclaration of '__mm_storeh_pi_struct'
pub const __mm_storeh_pi_struct = @compileError("cannot translate packed record union"); // C:\Development\zig\lib\include/xmmintrin.h:1948:10
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Development\projects\zig-gamedev\zig-cache\o\3367f8690c85323febb96ffeac1bea59\cimport.zig:12977:5: note: other declaration here
pub const __mm_storeh_pi_struct = @compileError("cannot translate packed record union"); // C:\Development\zig\lib\include/xmmintrin.h:1927:10
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@igaryhe
Copy link
Contributor

igaryhe commented Sep 5, 2022

a workaround might be manually comment #include "SDL_cpuinfo.h" in SDL.h, only if you are not using these SIMD extension checking functions

fabioarnold added a commit to fabioarnold/MiniPixel that referenced this issue Sep 7, 2022
@slimsag
Copy link
Sponsor Contributor

slimsag commented Sep 8, 2022

We also hit this in mach/freetype:

/Users/slimsag/Desktop/hexops/mach/libs/freetype/zig-cache/o/bb72da8deab15f11b164ed8d77d537bf/cimport.zig:766:39: error: use of undeclared identifier 'struct__OSUnalignedU16'
    return _OSSwapInt16(@intToPtr([*c]struct__OSUnalignedU16, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val);
                                      ^~~~~~~~~~~~~~~~~~~~~~
/Users/slimsag/Desktop/hexops/mach/libs/freetype/zig-cache/o/bb72da8deab15f11b164ed8d77d537bf/cimport.zig:771:39: error: use of undeclared identifier 'struct__OSUnalignedU32'
    return _OSSwapInt32(@intToPtr([*c]struct__OSUnalignedU32, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val);
                                      ^~~~~~~~~~~~~~~~~~~~~~
/Users/slimsag/Desktop/hexops/mach/libs/freetype/zig-cache/o/bb72da8deab15f11b164ed8d77d537bf/cimport.zig:776:39: error: use of undeclared identifier 'struct__OSUnalignedU64'
    return _OSSwapInt64(@intToPtr([*c]struct__OSUnalignedU64, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val);
                                      ^~~~~~~~~~~~~~~~~~~~~~
/Users/slimsag/Desktop/hexops/mach/libs/freetype/zig-cache/o/bb72da8deab15f11b164ed8d77d537bf/cimport.zig:782:19: error: use of undeclared identifier 'struct__OSUnalignedU16'
    @intToPtr([*c]struct__OSUnalignedU16, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val = _OSSwapInt16(_data);
                  ^~~~~~~~~~~~~~~~~~~~~~
/Users/slimsag/Desktop/hexops/mach/libs/freetype/zig-cache/o/bb72da8deab15f11b164ed8d77d537bf/cimport.zig:788:19: error: use of undeclared identifier 'struct__OSUnalignedU32'
    @intToPtr([*c]struct__OSUnalignedU32, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val = _OSSwapInt32(_data);
                  ^~~~~~~~~~~~~~~~~~~~~~
/Users/slimsag/Desktop/hexops/mach/libs/freetype/zig-cache/o/bb72da8deab15f11b164ed8d77d537bf/cimport.zig:794:19: error: use of undeclared identifier 'struct__OSUnalignedU64'
    @intToPtr([*c]struct__OSUnalignedU64, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val = _OSSwapInt64(_data);
                  ^~~~~~~~~~~~~~~~~~~~~~
/Users/slimsag/Desktop/hexops/mach/libs/freetype/src/c.zig:1:20: error: C import failed: AnalysisFail
pub usingnamespace @cImport({
                   ^~~~~~~~

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

6 participants