xmake-io / xmake

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

Target can not build with rule when add rules in script scope #3267

Closed star-hengxing closed 1 year ago

star-hengxing commented 1 year ago

Xmake Version

xmake v2.7.5+HEAD.d523fc824

Operating System Version and Architecture

Windows 10 Professional 19044.2130

Describe Bug

// io.hpp
#pragma once

auto test() -> void;

// io.cpp
auto test() -> void {}

// main.cpp
#include "io.hpp"

int main()
{
    test();
}

xmake.lua

set_warnings("all")
set_languages("c++20")

if is_plat("windows") then
    set_runtimes("MD")
end

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

target("io")
    set_kind("$(kind)")
    add_files("io.cpp")
    on_load(function (target)
        if is_mode("debug") then
            target:set("kind", "shared")
            if is_plat("windows") then
                target:add("rules", "utils.symbols.export_all", {export_classes = true})
            end
        elseif is_mode("release") then
            target:set("kind", "static")
        end
    end)
    -- if is_mode("debug") then
    --     set_kind("shared")
    --     if is_plat("windows") then
    --         add_rules("utils.symbols.export_all", {export_classes = true})
    --     end
    -- elseif is_mode("release") then
    --     set_kind("static")
    -- end
target_end()

target("main")
    set_kind("binary")
    add_files("main.cpp")
    add_deps("io")
    set_rundir("$(projectdir)")
target_end()
xmake show --target=io

rules: mode.debug, mode.release, utils.symbols.export_all

try

xmake f -m debug
xmake

[ 25%]: cache compiling.debug io.cpp
[ 25%]: cache compiling.debug main.cpp
[ 50%]: linking.debug io.dll
[ 75%]: linking.debug main.exe
❗ error: LINK : fatal error LNK1104: Cannot open file "io.lib"

Expected Behavior

Success to build.

Project Configuration

No response

Additional Information and Error Logs

No response

waruqi commented 1 year ago

再试下 xmake update -s dev

star-hengxing commented 1 year ago

不行,另外我试了一下我之前写的 rule utils.ispc,也是构建失败

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

target("test")
    set_kind("binary")
    -- add_rules("utils.ispc", {header_extension = "_ispc.h"})
    -- set_values("ispc.flags", "--target=host")
    -- add_files("src/*.ispc")
    add_files("src/*.cpp")

    on_load(function (target)
        target:add("rules", "utils.ispc", {header_extension = "_ispc.h"})
        target:set("values", "ispc.flags", "--target=host")
        target:add("files", "src/*.ispc")
    end)
waruqi commented 1 year ago

试下

    on_load(function (target)
        import("core.project.rule")
        local rule = rule.rule("utils.symbols.export_all")
        target:rule_add(rule)
        target:extraconf_set("rules", "utils.symbols.export_all", {export_classes = true})
    end)

ipsc 那个更新下 dev,然后参考上面使用

star-hengxing commented 1 year ago

可以了,套用这个写法两个都构建成功