xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

Unable to run newly-created project #5307

Closed thanhnguyen2187 closed 4 months ago

thanhnguyen2187 commented 4 months ago

Xmake Version

2.9.1

Operating System Version and Architecture

Linux nixos 6.9.4 #1-NixOS SMP PREEMPT_DYNAMIC Wed Jun 12 09:39:59 UTC 2024 x86_64 GNU/Linux

Describe Bug

Running xmake in a newly created project doesn't work

error: ./xmake.lua:7: unexpected symbol near '$'
checking for platform ... linux
checking for architecture ... x86_64
error: ./xmake.lua:7: unexpected symbol near '$'

Expected Behavior

The project is built successfully

Project Configuration

Minimal reproduce steps:

xmake create -P hello
# create hello ...
# error: cannot open file: xmake.lua, Not access because it is busy
cd hello
xmake
# error: ./xmake.lua:7: unexpected symbol near '$'
# checking for platform ... linux
# checking for architecture ... x86_64
# error: ./xmake.lua:7: unexpected symbol near '$'

Additional Information and Error Logs

Output of xmake -vD:

error: ./xmake.lua:7: unexpected symbol near '$'
checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /home/thanh/.nix-profile/bin/gcc
checkinfo: cannot runv(zig version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(zig version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
error: @programdir/core/main.lua:329: @programdir/core/sandbox/modules/import/core/base/task.lua:65: @programdir/core/project/project.lua:956: ./xmake.lua:7: unexpected symbol near '$'
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/project/project.lua:956]: in function 'options'
    [...dir/core/sandbox/modules/import/core/project/project.lua:79]: in function 'check_options'
    [@programdir/actions/config/main.lua:367]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/base/task.lua:491]: in function 'run'
    [@programdir/core/sandbox/modules/import/core/base/task.lua:63]: in function 'run'
    [@programdir/actions/build/main.lua:191]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/base/task.lua:491]: in function 'run'
    [@programdir/core/main.lua:327]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

Content of xmake.lua:

add_rules("mode.debug", "mode.release")

target("${TARGETNAME}")
    set_kind("binary")
    add_files("src/*.cpp")

${FAQ}
thanhnguyen2187 commented 4 months ago

Removing ${FAQ} helps, but I really wonder if it is the case :sweat_smile:

waruqi commented 4 months ago

try

xmake create test
cd test
tree
cat xmake.lua
xmake -vD
thanhnguyen2187 commented 4 months ago

Here you go

xmake create test
# create test ...
# error: cannot open file: xmake.lua, Not access because it is busy
cd test
tree
# .
# ├── src
# │   └── main.cpp
# └── xmake.lua
cat xmake.lua
# add_rules("mode.debug", "mode.release")
# 
# target("${TARGETNAME}")
#     set_kind("binary")
#     add_files("src/*.cpp")
# 
# ${FAQ}
xmake -vD
# error: ./xmake.lua:7: unexpected symbol near '$'
# checking for platform ... linux
# checking for architecture ... x86_64
# checking for gcc ... /nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/gcc
# checkinfo: cannot runv(zig version), No such file or directory
# checking for zig ... no
# checkinfo: cannot runv(zig version), No such file or directory
# checking for zig ... no
# checkinfo: cannot runv(nim --version), No such file or directory
# checking for nim ... no
# checkinfo: cannot runv(nim --version), No such file or directory
# checking for nim ... no
# error: @programdir/core/main.lua:329: @programdir/core/sandbox/modules/import/core/base/task.lua:65: @programdir/core/project/project.lua:956: ./xmake.lua:7: unexpected symbol near '$'
# stack traceback:
#     [C]: in function 'error'
#     [@programdir/core/base/os.lua:973]:
#     [@programdir/core/project/project.lua:956]: in function 'options'
#     [...dir/core/sandbox/modules/import/core/project/project.lua:79]: in function 'check_options'
#     [@programdir/actions/config/main.lua:367]:
#     [C]: in function 'xpcall'
#     [@programdir/core/base/utils.lua:275]:
#     [@programdir/core/base/task.lua:491]: in function 'run'
#     [@programdir/core/sandbox/modules/import/core/base/task.lua:63]: in function 'run'
#     [@programdir/actions/build/main.lua:191]:
#     [C]: in function 'xpcall'
#     [@programdir/core/base/utils.lua:275]:
#     [@programdir/core/base/task.lua:491]: in function 'run'
#     [@programdir/core/main.lua:327]: in function 'cotask'
#     [@programdir/core/base/scheduler.lua:406]:
# 
# stack traceback:
#         [C]: in function 'error'
#         @programdir/core/base/os.lua:973: in function 'base/os.raiselevel'
#         (...tail calls...)
#         @programdir/core/main.lua:329: in upvalue 'cotask'
#         @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>
waruqi commented 4 months ago

error: cannot open file: xmake.lua, Not access because it is busy

I don't know why. Maybe a file read/write permission issue

xmake cannot write xmake.lua and do replace vars

thanhnguyen2187 commented 4 months ago

I see. It seems plausible. Do you mean ${FAQ} of xmake.lua should be replaced when we run xmake create ...

waruqi commented 4 months ago

I see. It seems plausible. Do you mean ${FAQ} of xmake.lua should be replaced when we run xmake create ...

it will create a template xmake.lua file with ${FAQ} string, then it will be replaced in xmake.lua file. but xmake write file failed.

https://github.com/xmake-io/xmake/blob/71db286a686ab5ecc4f7430fe8ee8e9200027b97/xmake/actions/create/main.lua#L116

thanhnguyen2187 commented 4 months ago

Thanks. I was wondering if this is related to nix and the way xmake is packaged. I made it work by removing ${FAQ} from xmake.lua. Let's close this for now.

star-hengxing commented 1 month ago

xmake v2.9.5 should work https://github.com/NixOS/nixpkgs/issues/314313