xmake-io / xmake

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

两次调用find_package的结果不一致 #2139

Closed Yiklek closed 2 years ago

Yiklek commented 2 years ago

Xmake 版本

2.6.4

操作系统版本和架构

Windows 10 21H2 19044.1526

描述问题

两次调用find_package的结果不一致

image

这里llvm-mlir是我使用packege安装到xmake的package的第三方库。第一次checking for xmake::llvm-mlir ... llvm-mlir 14.0.0-rc2是调用add_requires("llvm-mlir 14.0.0-rc2")的结果,第二次checking for xmake::llvm-mlir ... no是在rule的on_build_file中调用find_package的结果。两次的结果不一致。

期待的结果

希望find_package正确返回package的结果 或者是否有其他方法在rule的on_build_file中可以获取到指定package的includedirs吗?

工程配置

main.c

int main(int argc, char *argv[])
{
    return 0;
}

readme.md

hello world

xmake.lua

add_rules("mode.debug", "mode.release")
package("llvm-mlir")
    set_homepage("https://llvm.org/")
    set_description("The LLVM Compiler Infrastructure")

    -- projects
    add_configs("clang",                    {description = "Enable clang project.", default = true, type = "boolean"})
    add_configs("clang-tools-extra",        {description = "Enable extra clang tools project.", default = false, type = "boolean"})
    add_configs("lld",                      {description = "Enable lld project.", default = false, type = "boolean"})
    add_configs("lldb",                     {description = "Enable lldb project.", default = false, type = "boolean"})
    add_configs("openmp",                   {description = "Enable openmp project.", default = false, type = "boolean"})
    add_configs("polly",                    {description = "Enable polly project.", default = false, type = "boolean"})
    add_configs("mlir",                     {description = "Enable mlir project.", default = false, type = "boolean"})
    -- runtimes
    add_configs("compiler-rt",              {description = "Enable compiler-rt runtime.", default = false, type = "boolean"})
    add_configs("libunwind",                {description = "Enable libunwind runtime.", default = false, type = "boolean"})
    add_configs("libcxxabi",                {description = "Enable clang runtime.", default = false, type = "boolean"})

    set_urls("https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-$(version).zip")
    add_versions("13.0.1", "7793590FF8B3ECF2B6388F6CBF42F652ED83EE933391EDBB39EC80C33DF00CEC")
    add_versions("14.0.0-rc2", "350C763E78F8E43B2718CCC7A43483D2B6C0C681F5FFFB7437E1670B1067BB23")

    on_load(function (package) 
        if package:is_plat("windows") then
            package:add("includedirs", "include")
            package:add("linkdirs", "lib")
        end
    end)

    on_install(function (package)

        local projects = {
            "clang",
            "clang-tools-extra",
            "lld",
            "lldb",
            "openmp",
            "polly",
            "mlir",
        }
        local projects_enabled = {}
        for _, project in ipairs(projects) do
            if package:config(project) then
                table.insert(projects_enabled, project)
            end
        end
        local runtimes = {
            "compiler-rt",
            "libunwind",
            "libcxxabi"
        }
        local runtimes_enabled = {}
        for _, runtime in ipairs(runtimes) do
            if package:config(runtime) then
                table.insert(runtimes_enabled, runtime)
            end
        end
        local build_configs = {
            "../llvm",
            "-DCMAKE_BUILD_TYPE=Release",
            "-DLLVM_ENABLE_PROJECTS=" .. table.concat(projects_enabled, ";"),
            "-DLLVM_ENABLE_RUNTIMES=" .. table.concat(runtimes_enabled, ";"),
            "-DLLVM_ENABLE_ASSERTIONS=ON",
        }
        local build_opts = {}
        if package:is_plat("windows") then 
            table.insert(build_configs, "-DLLVM_TARGETS_TO_BUILD=host")
            table.insert(build_configs, "-Thost=x64")
            table.insert(build_configs, "-DCMAKE_INSTALL_PREFIX=" .. package:installdir())
            --table.insert(build_configs, "-B=build")
            build_opts.cmake_build = true
            build_opts.target = "ALL_BUILD"
            build_opts.config = "Release"
            --os.mkdir(path.join(package:installdir(), "lib"))
            --os.mkdir(path.join(package:installdir(), "bin"))
            --os.mkdir(path.join(package:installdir(), "include"))
            os.mkdir("build")
            os.cd("build")
            os.vrunv("cmake", build_configs)
            os.vrunv("cmake", {"--build", ".", 
                "--target", "ALL_BUILD",
                "--config", "Release", "-j" .. tostring(os.default_njob())})
            os.vrunv("cmake",{"--install", "."})
        elseif package:is_plat("linux") then
            table.insert(build_configs, "-DLLVM_TARGETS_TO_BUILD=X86;NVPTX;AMDGPU")
            table.insert(build_configs, "-G=Ninja")
            build_opts.cmake_build = true
            build_opts.target = "all"
            build_opts.config = "Release"
            import("package.tools.cmake").build(package, build_configs, build_opts)
            import("package.tools.cmake").install(package)
        end
    end)

    on_test(function (package)
        if package:config("mlir") then
            os.vrun("mlir-tblgen --version")
        end
    end)
package_end()

add_requires("llvm-mlir 14.0.0-rc2")

rule("md")
    set_extensions(".md")
    on_build_file(function (target, sourcefile, opt)
        print(sourcefile)
        local package, manager_name, package_name = find_package("xmake::llvm-mlir")
        print(package, manager_name, package_name)
    end)

target("test")
    add_files("main.c", "*.md")
    add_packages("llvm-mlir")
    add_rules("md")

附加信息和错误日志

checking for vswhere.exe ... C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
checking for cl.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2019
checkinfo: cannot runv(dmd.exe --version), No such file or directory
checking for dmd ... no
checkinfo: cannot runv(ldc2.exe --version), No such file or directory
checking for ldc2 ... no
checkinfo: cannot runv(gdc.exe --version), No such file or directory
checking for gdc ... no
checkinfo: cannot runv(zig.exe version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(zig.exe version), No such file or directory
checking for zig ... no
checking for unzip ... ok
checking for git ... ok
checking for gzip ... ok
checking for tar ... ok
finding llvm-mlir from xmake ..
checking for xmake::llvm-mlir ... llvm-mlir 14.0.0-rc2
checking for link.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
readme.md
finding llvm-mlir from xmake ..
checking for xmake::llvm-mlir ... no

checking for cl.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe
checking for the c compiler (cc) ... cl.exe
checking for C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe ... ok
checking for flags (-Ox -fp:fast) ... ok
> cl.exe "-Ox" "-fp:fast"
checking for flags (cl_external_includedir) ... ok
> cl.exe "-external:W0" "-external:IE:\xmake_pkg\l\llvm-mlir\14.0.0-rc2\7f59252a314947b0b525bc228f64d877\include" "-nologo"
checking for flags (-DNDEBUG) ... ok
> cl.exe "-DNDEBUG" "-nologo"
[100%]: build ok!
xq114 commented 2 years ago

试试target:pkg("llvm-mlir"):get("includedirs"),find_package是很老的接口了,对package()描述不适用

Yiklek commented 2 years ago

换成sysincludedirs可以了。谢谢大佬。 (文档有必要更新下了:joy: