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

Error-prone xmake behaviour when locating system packages #5467

Open
vspefs opened this issue Aug 14, 2024 · 2 comments
Open

Error-prone xmake behaviour when locating system packages #5467

vspefs opened this issue Aug 14, 2024 · 2 comments
Labels

Comments

@vspefs
Copy link

vspefs commented Aug 14, 2024

Xmake Version

2.9.4

Operating System Version and Architecture

Windows 11 21H2 Home. Using msys2, on clang64 environment

Describe Bug

A package holds multiple alias-es, like X, Y and Z. You can find the package using all the alias-es, but the target file to be linked to is named after one of them, for example, Y. When xmake successfully finds the system package and goes on to test if the compiler could actually link against the library, it tests only by adding the compiler flag "-lX", in which X is the package name we specify in our xmake.lua, instead of the real name we should use, Y.

Expected Behavior

Whichever package name we specify in xmake.lua, xmake could use the right name for the target file while testing if the library links.

Project Configuration

-- xmake.lua
-- add_requires("glfw") -- this makes xmake fail to locate the system package, as glfw's target file is named "libglfw3.a/.so"
add_requires("glfw3")

set_languages("c++latest")
add_rules("mode.debug", "mode.release")

target("main")

    set_kind("binary")

    add_files("main.cpp")

    -- add_requires("glfw")
    add_packages("glfw3")
// main.cpp
#include <print>
#include <GLFW/glfw3.h>

int main(void)
{
    // c++ test
    std::println("Hello, world!");

    // glfw test
    glfwInit();
    glfwTerminate();
}

Additional Information and Error Logs

using add_requires("glfw3")

$ xmake f -p mingw -a x64 -m debug --toolchain=clang -vD
checking for clang ... ok
checkinfo: cannot runv(unzip -v), No such file or directory
checking for unzip ... no
checking for 7z ... ok
checking for git ... ok
checking for gzip ... ok
checking for tar ... ok
checking for ping ... ok
pinging the host(gitee.com) ... 22 ms
pinging the host(github.com) ... 77 ms
pinging the host(gitlab.com) ... 214 ms
finding glfw3 from xmake ..
checking for xmake::glfw3 ... no
checking for pacman ... ok
checkinfo: cannot runv(emerge --version), No such file or directory
checking for emerge ... no
finding glfw3 from vcpkg ..
finding glfw3 from conan ..
finding glfw3 from pkgconfig ..
checking for pkg-config ... ok
checking for clang ... ok
checking for the c compiler (cc) ... clang
> clang -c -Qunused-arguments -m64 -o C:\coding\msys64\tmp\.xmake\240814\_A287B107AC4F49308CABDA46E52A7D50.o C:\coding\msys64\tmp\.xmake\240814\_775FB00633BC4F66BF87D39CCDE5CF30.c
checking for flags (-fdiagnostics-color=always) ... ok
> clang "-fdiagnostics-color=always" "-Qunused-arguments" "-m64"
checking for flags (-fansi-escape-codes) ... ok
> clang "-fansi-escape-codes" "-Qunused-arguments" "-m64"
checking for clang ... ok
checking for the c++ compiler (cxx) ... clang
checking for clang++ ... ok
checking for the linker (ld) ... clang++
> clang++ -o C:\coding\msys64\tmp\.xmake\240814\_A287B107AC4F49308CABDA46E52A7D50.b C:\coding\msys64\tmp\.xmake\240814\_A287B107AC4F49308CABDA46E52A7D50.o -m64 -lglfw3
> checking for c links(glfw3)
> checking for c snippet(find_package/glfw3)
checking for glfw3 ... pkgconfig::glfw3 3.4.0
configure
{
    proxy_pac = pac.lua
    proxy_hosts = github.com
    clean = true
    buildir = build
    plat = mingw
    kind = static
    theme = default
    mode = debug
    proxy = socks5://127.0.0.1:10808
    arch = x64
    ndk_stdcxx = true
    host = windows
    toolchain = clang
    network = public
    ccache = true
}

$ xmake build main
[ 50%]: cache compiling.debug main.cpp
[ 75%]: linking.debug main.exe
[100%]: build ok, spent 1.484s

$ xmake run main
Hello, world!

using add_requires("glfw")

$ xmake f -p mingw -a x64 -m debug --toolchain=clang -vD
checking for clang ... ok
checkinfo: cannot runv(unzip -v), No such file or directory
checking for unzip ... no
checking for 7z ... ok
checking for git ... ok
checking for gzip ... ok
checking for tar ... ok
checking for ping ... ok
pinging the host(gitee.com) ... 26 ms
pinging the host(github.com) ... 84 ms
pinging the host(gitlab.com) ... 206 ms
git rev-parse HEAD
checking for cmake ... no
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.41.34117\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.41.34117
checking for cmake ... no
checking for cmake ... no
checking for cmake ... ok
checking for xmake-repo-from-github::opengl ... opengl 
finding glfw from xmake ..
checking for xmake::glfw ... no
checking for pacman ... ok
checkinfo: cannot runv(emerge --version), No such file or directory
checking for emerge ... no
finding glfw from vcpkg ..
finding glfw from conan ..
finding glfw from pkgconfig ..
checking for pkg-config ... ok
finding glfw from pacman ..
finding glfw from system ..
checking for clang ... ok
checking for the c compiler (cc) ... clang
> clang -c -Qunused-arguments -m64 -o C:\coding\msys64\tmp\.xmake\240814\_8E93862609A14A708A62D0092736F8E0.o C:\coding\msys64\tmp\.xmake\240814\_775FB00633BC4F66BF87D39CCDE5CF30.c
checking for flags (-fdiagnostics-color=always) ... ok
> clang "-fdiagnostics-color=always" "-Qunused-arguments" "-m64"
checking for flags (-fansi-escape-codes) ... ok
> clang "-fansi-escape-codes" "-Qunused-arguments" "-m64"
checking for clang ... ok
checking for the c++ compiler (cxx) ... clang
checking for clang++ ... ok
checking for the linker (ld) ... clang++
> clang++ -o C:\coding\msys64\tmp\.xmake\240814\_8E93862609A14A708A62D0092736F8E0.b C:\coding\msys64\tmp\.xmake\240814\_8E93862609A14A708A62D0092736F8E0.o -m64 -lglfw
lld: error: unable to find library -lglfw
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> checking for c links(glfw)
> checking for c snippet(find_package/glfw)
checkinfo: ...gramdir\core\sandbox\modules\import\core\tool\linker.lua:75: @programdir\core\sandbox\modules\os.lua:378: execv(clang++ -o C:\coding\msys64\tmp\.xmake\240814\_8E93862609A14A708A62D0092736F8E0.b C:\coding\msys64\tmp\.xmake\240814\_8E93862609A14A708A62D0092736F8E0.o -m64 -lglfw) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:973]:
    [@programdir\core\sandbox\modules\os.lua:378]: in function 'execv'
    [@programdir\modules\core\tools\gcc.lua:583]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:275]:
    [@programdir\core\tool\linker.lua:222]: in function 'link'
    [...gramdir\core\sandbox\modules\import\core\tool\linker.lua:73]: in function 'link'
    [@programdir\modules\lib\detect\check_cxsnippets.lua:249]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:275]: in function 'trycall'
    [@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
    [@programdir\modules\lib\detect\check_cxsnippets.lua:236]:
    [@programdir\modules\package\manager\system\find_package.lua:103]:
    [@programdir\modules\package\manager\find_package.lua:84]: in function '_find_package_with_builtin_rule'
    [@programdir\modules\package\manager\find_package.lua:130]: in function '_find_package'
    [@programdir\modules\package\manager\find_package.lua:194]:
    [@programdir\modules\lib\detect\find_package.lua:109]:
    [@programdir\core\package\package.lua:1852]: in function '_fetch_library'
    [@programdir\core\package\package.lua:2022]: in function 'fetch'
    [...modules\private\action\require\impl\install_packages.lua:335]: in function 'jobfunc'
    [@programdir\modules\async\runjobs.lua:241]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:275]: in function 'trycall'
    [@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
    [@programdir\modules\async\runjobs.lua:223]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

checking for glfw ... no
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo-from-github:
  -> glfw 3.4 [toolchains:"clang"]
please input: y (y/n/m)

As you see, it fails to locate the system package.

@vspefs vspefs added the bug label Aug 14, 2024
@waruqi
Copy link
Member

waruqi commented Aug 15, 2024

you can open a pr to add add_extsources or on_fetch to improve to find system library for glfw package.

e.g. add_extsources("pkgconfig::glfw3")

https://github.com/xmake-io/xmake-repo/blob/8822e12a8bd9a85bb34b13bacbe1a0899968c964/packages/g/glfw/xmake.lua#L23

and you can refer other packages in xmake-repo

@star-hengxing
Copy link
Contributor

It work for me= =

add_requires("glfw", {system = true})
$ xmake f -c -y -vD
checking for platform ... mingw
checking for architecture ... x86_64
checking for mingw directory ... C:/Users/star/scoop/apps/msys2/2024-07-27/mingw64
checkinfo: cannot runv(unzip -v), No such file or directory
checking for unzip ... no
checking for 7z ... ok
checking for git ... ok
checking for gzip ... ok
checking for tar ... ok
git rev-parse HEAD
checking for cmake ... no
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.41.34120
checking for cmake ... no
checking for cmake ... no
checking for cmake ... ok
checking for xmake-repo::opengl ... opengl
checking for pacman ... ok
checkinfo: cannot runv(emerge --version), No such file or directory
checking for emerge ... no
finding glfw from vcpkg ..
finding glfw from conan ..
finding glfw from pkgconfig ..
checking for pkg-config ... ok
finding glfw from pacman ..
checking for x86_64-w64-mingw32-gcc ... C:\Users\star\scoop\apps\msys2\2024-07-27\mingw64\bin\x86_64-w64-mingw32-gcc
checking for the c compiler (cc) ... x86_64-w64-mingw32-gcc
> C:\Users\star\scoop\apps\msys2\2024-07-27\mingw64\bin\x86_64-w64-mingw32-gcc -c -m64 -o C:\Users\star\scoop\apps\msys2\2024-07-27\tmp\.xmake\240815\_F6A3B3A047DD416088DF1851D05151E0.o C:\Users\star\scoop\apps\msys2\2024-07-27\tmp\.xmake\240815\_775FB00633BC4F66BF87D39CCDE5CF30.c
checking for C:\Users\star\scoop\apps\msys2\2024-07-27\mingw64\bin\x86_64-w64-mingw32-gcc ... ok
checking for flags (-fdiagnostics-color=always) ... ok
> x86_64-w64-mingw32-gcc "-fdiagnostics-color=always" "-m64"
checking for x86_64-w64-mingw32-g++ ... C:\Users\star\scoop\apps\msys2\2024-07-27\mingw64\bin\x86_64-w64-mingw32-g++
checking for the linker (ld) ... x86_64-w64-mingw32-g++
> C:\Users\star\scoop\apps\msys2\2024-07-27\mingw64\bin\x86_64-w64-mingw32-g++ -o C:\Users\star\scoop\apps\msys2\2024-07-27\tmp\.xmake\240815\_F6A3B3A047DD416088DF1851D05151E0.b C:\Users\star\scoop\apps\msys2\2024-07-27\tmp\.xmake\240815\_F6A3B3A047DD416088DF1851D05151E0.o -m64 -lglfw3
> checking for c links(glfw3)
> checking for c snippet(find_package/glfw3)
checking for cygpath ... ok
checking for glfw ... pacman::glfw 3.4.0

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

3 participants