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

Zig build problem #3837

Closed
Immortalin opened this issue Jun 12, 2023 · 16 comments
Closed

Zig build problem #3837

Immortalin opened this issue Jun 12, 2023 · 16 comments
Labels

Comments

@Immortalin
Copy link

Xmake Version

v2.7.9+20230612

Operating System Version and Architecture

Windows 10 Subsystem for Linux, Ubuntu 22.04

Describe Bug

Zig compiler support no longer works with the latest version of zig.

With Zig 0.10.1 and following the getting started guide:

xmake create -l zig -t console hello
cd hello/
xmake

results in the following error:

error: ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:56: cannot get program for zc
stack traceback:
        @programdir/core/base/utils.lua:290: in function <@programdir/core/base/utils.lua:280>
        [C]: in function 'error'
        @programdir/core/base/os.lua:913: in function 'base/os.raiselevel'
        (...tail calls...)
        ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:56: in field 'co_start_withopt'
        @programdir/modules/private/async/runjobs.lua:217: in function <@programdir/modules/private/async/runjobs.lua:162>
        [C]: in function 'xpcall'
        @programdir/core/base/utils.lua:280: in function 'sandbox/modules/utils.trycall'
        @programdir/core/base/scheduler.lua:520: in function 'base/scheduler.co_group_begin'
        ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:94: in field 'co_group_begin'
        @programdir/modules/private/async/runjobs.lua:162: in function <@programdir/modules/private/async/runjobs.lua:56>
        (...tail calls...)
        @programdir/actions/build/build.lua:259: in function <@programdir/actions/build/build.lua:247>
        (...tail calls...)
        @programdir/actions/build/main.lua:109: in global '_do_build'
        @programdir/actions/build/main.lua:180: in function <@programdir/actions/build/main.lua:173>
        [C]: in function 'xpcall'
        @programdir/core/base/utils.lua:280: in function 'sandbox/modules/utils.trycall'
        @programdir/core/sandbox/modules/try.lua:117: in global 'try'
        @programdir/actions/build/main.lua:171: in function <@programdir/actions/build/main.lua:133>
        (...tail calls...)
        [C]: in function 'xpcall'
        @programdir/core/base/utils.lua:280: in function 'sandbox/modules/utils.trycall'
        (...tail calls...)
        @programdir/core/base/task.lua:501: in function 'base/task.run'
        @programdir/core/main.lua:298: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>

Expected Behavior

Hello World!

Project Configuration

No response

Additional Information and Error Logs

Detailed logs:

error: @programdir/core/main.lua:300: @programdir/actions/build/main.lua:206: ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:96: ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:56: @programdir/modules/private/async/runjobs.lua:256: ...amdir/core/sandbox/modules/import/core/tool/compiler.lua:37: cannot get program for zc
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:913]:
    [...amdir/core/sandbox/modules/import/core/tool/compiler.lua:37]: in function 'load'
    [@programdir/modules/private/action/build/object.lua:40]: in function 'script'
    [@programdir/modules/private/action/build/object.lua:104]: in function 'build_object'
    [@programdir/modules/private/action/build/object.lua:129]: in function 'jobfunc'
    [@programdir/modules/private/async/runjobs.lua:232]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:913: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir/modules/private/async/runjobs.lua:256: in field 'catch'
        @programdir/core/sandbox/modules/try.lua:123: in global 'try'
        @programdir/modules/private/async/runjobs.lua:218: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>
stack traceback:
        @programdir/core/base/utils.lua:290: in function <@programdir/core/base/utils.lua:280>
        [C]: in function 'error'
        @programdir/core/base/os.lua:913: in function 'base/os.raiselevel'
        (...tail calls...)
        ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:56: in field 'co_start_withopt'
        @programdir/modules/private/async/runjobs.lua:217: in function <@programdir/modules/private/async/runjobs.lua:162>
        [C]: in function 'xpcall'
        @programdir/core/base/utils.lua:280: in function 'base/utils.trycall'
        @programdir/core/base/scheduler.lua:520: in function 'base/scheduler.co_group_begin'
        ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:94: in field 'co_group_begin'
        @programdir/modules/private/async/runjobs.lua:162: in function <@programdir/modules/private/async/runjobs.lua:56>
        (...tail calls...)
        @programdir/actions/build/build.lua:259: in function <@programdir/actions/build/build.lua:247>
        (...tail calls...)
        @programdir/actions/build/main.lua:109: in global '_do_build'
        @programdir/actions/build/main.lua:180: in function <@programdir/actions/build/main.lua:173>
        [C]: in function 'xpcall'
        @programdir/core/base/utils.lua:280: in function 'base/utils.trycall'
        @programdir/core/sandbox/modules/try.lua:117: in global 'try'
        @programdir/actions/build/main.lua:171: in function <@programdir/actions/build/main.lua:133>
        (...tail calls...)
        [C]: in function 'xpcall'
        @programdir/core/base/utils.lua:280: in function 'base/utils.trycall'
        (...tail calls...)
        @programdir/core/base/task.lua:501: in function 'base/task.run'
        @programdir/core/main.lua:298: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>
stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:913: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:300: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>
@Immortalin Immortalin added the bug label Jun 12, 2023
@waruqi
Copy link
Member

waruqi commented Jun 12, 2023

zig not found, did you add zig to %PATH%?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


zig not found, did you add zig to %PATH%?

@Immortalin
Copy link
Author

I think the zig compiler is no longer named zc

@kassane
Copy link

kassane commented Jun 12, 2023

Here, working:

xmake v2.7.9+20230515
zig version: 0.11.0-dev.3395+1e7dcaa3a

[kassane@Catarino Documentos]$ xmake create -l zig -t console hello
create hello ...
  [+]: src/main.zig
  [+]: src/test.zig
  [+]: xmake.lua
  [+]: .gitignore
create ok!
[kassane@Catarino Documentos]$ cd hello/
[kassane@Catarino hello]$ xmake -rv
checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checking for zig ... /home/kassane/zig/master/files/zig
checking for /home/kassane/zig/master/files/zig ... ok
checking for the zig compiler (zc) ... zig
checking for /home/kassane/zig/master/files/zig ... ok
checking for the zig compiler (zc) ... zig
checking for flags (-O ReleaseFast) ... ok
checking for flags (--cache-dir build/.objs/hello/linux/x86_64/release/zig-cache) ... ok
[ 20%]: compiling.release src/main.zig
/home/kassane/zig/master/files/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/hello/linux/x86_64/release/zig-cache -femit-bin=build/.objs/hello/linux/x86_64/release/src/main.zig.o src/main.zig
[ 20%]: compiling.release src/test.zig
/home/kassane/zig/master/files/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/hello/linux/x86_64/release/zig-cache -femit-bin=build/.objs/hello/linux/x86_64/release/src/test.zig.o src/test.zig
checking for /home/kassane/zig/master/files/zig ... ok
checking for the zig linker (zcld) ... zig
[ 60%]: linking.release hello
/home/kassane/zig/master/files/zig build-exe -target x86_64-linux-gnu -fstrip -dead_strip -femit-bin=build/linux/x86_64/release/hello build/.objs/hello/linux/x86_64/release/src/main.zig.o build/.objs/hello/linux/x86_64/release/src/test.zig.o
[100%]: build ok, spent 6,673s

@waruqi , why zig cc not use inherit("clang")?

@waruqi
Copy link
Member

waruqi commented Jun 13, 2023

I think the zig compiler is no longer named zc

It has nothing to do with zc, that's just an internal name for xmake, as long as you add zig to the PATH, xmake will automatically set zig to zc.

Of course, you can also set it manually.

xmake f --zc=/xxx/zig --ld=/xxx/zig --sh=/xxx/zig --ar=xxx/zig

zc: zig compiler
ld: zig binary linker
sh: zig shared library linker
ar: archiver

@waruqi
Copy link
Member

waruqi commented Jun 13, 2023

or you try zig package. https://github.com/xmake-io/xmake/blob/master/tests/projects/package/toolchain_zig/xmake.lua

xmake will download zig and use it automatically.

@waruqi
Copy link
Member

waruqi commented Jun 13, 2023

Here, working:

xmake v2.7.9+20230515 zig version: 0.11.0-dev.3395+1e7dcaa3a

[kassane@Catarino Documentos]$ xmake create -l zig -t console hello
create hello ...
  [+]: src/main.zig
  [+]: src/test.zig
  [+]: xmake.lua
  [+]: .gitignore
create ok!
[kassane@Catarino Documentos]$ cd hello/
[kassane@Catarino hello]$ xmake -rv
checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checking for zig ... /home/kassane/zig/master/files/zig
checking for /home/kassane/zig/master/files/zig ... ok
checking for the zig compiler (zc) ... zig
checking for /home/kassane/zig/master/files/zig ... ok
checking for the zig compiler (zc) ... zig
checking for flags (-O ReleaseFast) ... ok
checking for flags (--cache-dir build/.objs/hello/linux/x86_64/release/zig-cache) ... ok
[ 20%]: compiling.release src/main.zig
/home/kassane/zig/master/files/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/hello/linux/x86_64/release/zig-cache -femit-bin=build/.objs/hello/linux/x86_64/release/src/main.zig.o src/main.zig
[ 20%]: compiling.release src/test.zig
/home/kassane/zig/master/files/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/hello/linux/x86_64/release/zig-cache -femit-bin=build/.objs/hello/linux/x86_64/release/src/test.zig.o src/test.zig
checking for /home/kassane/zig/master/files/zig ... ok
checking for the zig linker (zcld) ... zig
[ 60%]: linking.release hello
/home/kassane/zig/master/files/zig build-exe -target x86_64-linux-gnu -fstrip -dead_strip -femit-bin=build/linux/x86_64/release/hello build/.objs/hello/linux/x86_64/release/src/main.zig.o build/.objs/hello/linux/x86_64/release/src/test.zig.o
[100%]: build ok, spent 6,673s

@waruqi , why zig cc not use inherit("clang")?

clang is also inherit("gcc") There is not much difference.

@Immortalin
Copy link
Author

Works after reloading shell, closing.

@Immortalin
Copy link
Author

Immortalin commented Jun 13, 2023

Zig links automatically through the --library flag, does xmake supports passing the linkdirs directly to zc? I tried it with libguile but it does not work. xmake l find_package guile is able to find the package but zig is not able to.

target("demo")
    set_kind("binary")
    add_zcflags("-lc")
    add_zcflags("--library libguile")
    add_files("src/*.zig")
    add_packages("vcpkg::guile")

and

const std = @import("std");
const guile = @cImport({
    @cInclude("libguile.h");
});

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, {s}!\n", .{"world"});
    try stdout.print("hello {s}\n", guile);
}

@waruqi
Copy link
Member

waruqi commented Jun 13, 2023

add_linkdirs, add_links, add_syslinks

@waruqi
Copy link
Member

waruqi commented Jun 13, 2023

add_packages("vcpkg::guile")

you did not add add_requires

@waruqi
Copy link
Member

waruqi commented Jun 13, 2023

add_requires("vcpkg::guile")

target("demo")
    set_kind("binary")
    add_files("src/main.zig")
    add_packages("vcpkg::guile")

@Immortalin
Copy link
Author

The problem is that xmake is not passing the header files to the zig compiler, this is the generated command with xmake -vD:

/home/linuxbrew/.linuxbrew/bin/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/alien_zag/linux/x86_64/release/zig-cache -femit-bin=build/.objs/alien_zag/linux/x86_64/release/src/main.zig.o src/main.zig

@Immortalin
Copy link
Author

waruqi do you have any suggestions?

@waruqi
Copy link
Member

waruqi commented Jun 14, 2023

The problem is that xmake is not passing the header files to the zig compiler, this is the generated command with xmake -vD:

/home/linuxbrew/.linuxbrew/bin/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/alien_zag/linux/x86_64/release/zig-cache -femit-bin=build/.objs/alien_zag/linux/x86_64/release/src/main.zig.o src/main.zig

Does zig support using c/c++ header files? Can you provide some examples?

@Immortalin
Copy link
Author

You can see the raylib example here:

https://ziglang.org/learn/samples/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants