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

nim building requires xmake build -r or else build doesn't see file changes #5482

Open lewisl opened 2 months ago

lewisl commented 2 months ago

Xmake Version

xmake v2.9.4+20240729

Operating System Version and Architecture

macOS 14.6.1 (23G93)

Describe Bug

Change a source file in the nim project other than the "main" file. xmake build doesn't see the change and does nothing. you must run xmake build -r. this should not be necessary.

Another related problem: for nim prefers that only the "main" file is added to the project. In my case, that is


target("hex")
    set_kind("binary")
    add_ncflags("--opt:speed", "--mm:orc")
    add_files("src/hex.nim")

If I do add_files("src/*.nim)"" then I get the errorError: arguments can only be given if the '--run' option is selected```

This is a bogus error.

In fact, the situation is so bad that xmake build doesn't even realize that xmake.lua has changed.

this is all using the embedded terminal in VS Code, which might have some weird state management problems. I will note that this problem does not occur when using an external terminal (terminal.app on macosx). xmake sees any file that has changed. A work around then, is using the external terminal. This loses some convenience though...

Expected Behavior

xmake should see any change in any source file in the project that is imported into the "main" nim file. And it should not be necessary to explicitly add all source files, which causes other unrelated errors.

Project Configuration

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

target("hex")
    set_kind("binary")
    add_ncflags("--opt:speed", "--mm:orc")
    add_files("src/hex.nim")

Additional Information and Error Logs

so it turns out that xmake does not see changes to nim source files at all. We must always use xmake build -r whether using the external terminal or the vscode embedded terminal. Not fair to blame vscode for this.

If all source files are included, then the bogus command line argument requiring the --run option occurs.

So, we must only include the "main" source file and use the -r (rebuild) option.

I have only used xmake with c++ and nim. I have not see such a problem with c++.

I think it is also relevant to show the nim setup info from the .xmake directory:

this is xmake.conf:

{
    __toolchains_macosx_arm64 = {
        "envs",
        "xcode",
        "yasm",
        "nasm",
        "cuda",
        "rust",
        "go",
        "gfortran",
        "fpc",
        "nim"
    },
    arch = "arm64",
    buildir = "build",
    ccache = true,
    host = "macosx",
    kind = "static",
    mode = "release",
    ndk_stdcxx = true,
    plat = "macosx"
}

here is detect from the xmake cache:

{
    find_program_nim_arch_arm64_plat_macosx_checktoolnc = {
        ["/opt/homebrew/bin/nim"] = "/opt/homebrew/bin/nim"
    },
    find_programver = {
        ["/opt/homebrew/bin/nim"] = "2.0.8"
    },
    ["detect.tools.nim.has_flags"] = {
        ["/opt/homebrew/bin/nim_2.0.8"] = {
            ["--help"] = true,
            ["--fullhelp"] = true,
            ["--version"] = true,
            ["--run"] = true
        }
    },
    find_program_nim_arch_arm64_plat_macosx_checktoolncld = {
        ["/opt/homebrew/bin/nim"] = "/opt/homebrew/bin/nim"
    },
    ["detect.sdks.find_xcode"] = {
        xcode = { }
    },
    find_program = {
        nim = "/opt/homebrew/bin/nim",
        ["/opt/homebrew/bin/nim"] = "/opt/homebrew/bin/nim",
        zig = false
    },
    ["lib.detect.has_flags"] = {
        ["macosx_arm64_/opt/homebrew/bin/nim_2.0.8_nc_ncflags__--opt:speed"] = true,
        ["macosx_arm64_/opt/homebrew/bin/nim_2.0.8_nc_ncflags__--mm:orc"] = true,
        ["macosx_arm64_/opt/homebrew/bin/nim_2.0.8_nc___-d:release"] = true
    }
}

this is toolchain from the xmake cache:

{
    xcode_arch_arm64_plat_macosx = {
        __global = true,
        xcode_sysroot = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk",
        arch = "arm64",
        bindir = "/Library/Developer/CommandLineTools/usr/bin",
        plat = "macosx"
    },
    tool_target_hex_macosx_arm64_nc = {
        toolname = "nim",
        toolchain_info = {
            cachekey = "nim_arch_arm64_plat_macosx",
            name = "nim",
            arch = "arm64",
            plat = "macosx"
        },
        program = "/opt/homebrew/bin/nim"
    },
    tool_target_hex_macosx_arm64_ncld = {
        toolname = "nim",
        toolchain_info = {
            cachekey = "nim_arch_arm64_plat_macosx",
            name = "nim",
            arch = "arm64",
            plat = "macosx"
        },
        program = "/opt/homebrew/bin/nim"
    },
    nim_arch_arm64_plat_macosx = {
        __global = true,
        arch = "arm64",
        nim = "/opt/homebrew/bin/nim",
        plat = "macosx"
    }
}
waruqi commented 2 months ago

Xmake does not support nim incremental compilation yet, because I don't know how to get all its dependent files based on the nim main file. (like -MMD flag for gcc/cpp)

lewisl commented 2 months ago

OK. Thanks for replying. I don’t know if the nim compile command even does. Nim compiles so fast I just do xmake -r.

Where is the nim.cfg you use? I note that you compile down smaller executable with no loss in performance comparing to use nim cmdline.

Close it.

From: ruki @.> Reply-To: xmake-io/xmake @.> Date: Monday, August 19, 2024 at 7:34 AM To: xmake-io/xmake @.> Cc: Lewis Levin @.>, Author @.***> Subject: Re: [xmake-io/xmake] nim building requires xmake build -r or else build doesn't see file changes (Issue #5482)

Xmake does not support nim incremental compilation yet, because I don't know how to get all its dependent files based on the nim main file. (like -MMD flag for gcc/cpp)

— Reply to this email directly, view it on GitHubhttps://github.com/xmake-io/xmake/issues/5482#issuecomment-2296732570, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAIYWLMITHOXIB4FETC6VNDZSH7AFAVCNFSM6AAAAABMWSQFASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJWG4ZTENJXGA. You are receiving this because you authored the thread.Message ID: @.***>

waruqi commented 2 months ago

OK. Thanks for replying. I don’t know if the nim compile command even does. Nim compiles so fast I just do xmake -r.

Where is the nim.cfg you use? I note that you compile down smaller executable with no loss in performance comparing to use nim cmdline.

xmake does not use nim.cfg. it will call nim to build project directly. you can run xmake -rv to see the whole build command.