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

--plat=linux need support more archs such as armv8, mips64 with conan package manager #615

Closed
rel1ve opened this issue Nov 6, 2019 · 8 comments

Comments

@rel1ve
Copy link

rel1ve commented Nov 6, 2019

I am using xmake v2.2.8 to cross compile(x86_64, armv8 and mips64) for several Embedded Linux OS. My build OS is Ubuntu/x86_64, and use CONAN as package manager.

First I got an error "plat is 'nil' value" when I execute command "xmake f -p linux -a armv8 --sdk=... --cross=...". I looked source code and found in modules/pakcage/manager/conan/install_package.lua

-- set architecture
table.insert(argv, "-s")
if opt.arch == "x86_64" or opt.arch == "x64" then
table.insert(argv, "arch=x86_64")
elseif opt.arch == "i386" or opt.arch == "x86" then
table.insert(argv, "arch=x86")
else
raise("cannot install package(%s) for arch(%s)!", name, opt.arch)
end

Xmake only support x64 and x86 now. Then I add code to support armv8 and mips64, but I got another error.

checking for the conan::thrift/0.13.0@lanxum/testing ... no
error: @programdir/actions/require/impl/action/install.lua:202: fetch conan::thrift/0.13.0@lanxum/testing failed!
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:762]: in function 'raiselevel'
[@programdir/core/sandbox/modules/utils.lua:176]: in function 'assert'
[@programdir/actions/require/impl/action/install.lua:202]:
[C]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:121]: in function 'try'
[@programdir/actions/require/impl/action/install.lua:142]: in function 'install'
[@programdir/actions/require/impl/package.lua:594]:
=> install conan::thrift/0.13.0@lanxum/testing .. failed
error: @programdir/core/sandbox/modules/process.lua:148: @programdir/actions/require/impl/action/install.lua:261: install failed!
stack traceback:
[C]: in function 'error'
@programdir/core/base/os.lua:762: in function 'raise'
@programdir/actions/require/impl/action/install.lua:261: in function 'catch'
@programdir/core/sandbox/modules/try.lua:127: in function 'try'
@programdir/actions/require/impl/action/install.lua:142: in function 'install'
@programdir/actions/require/impl/package.lua:594: in function <@programdir/actions/require/impl/package.lua:519>

I debug xmake and found the issue at /data/scp-rpc-trunk/pack-cpp/build/.conan/thrift/0.13.0@lanxum/testing/conanbuildinfo.xmake.lua

{
Linux_x86_64_Release = {
linkdirs = {
...

The xmake-generator for conan generates this file and seems wrong, 'Linux_x86_64_Release' should be 'Linux_mips64_Release'. I fix it in this file, and all went right.

Is this an issue or what I missed?

@waruqi
Copy link
Member

waruqi commented Nov 6, 2019

If you pass --cross, --sdk and other parameters, you will switch to cross-compilation mode directly, and the arch argument will be ignored.

if config.get("cross") or config.get("bin") or config.get("sdk") then
-- init linkdirs and includedirs
local sdkdir = config.get("sdk")
if sdkdir then
local includedir = path.join(sdkdir, "include")
if os.isdir(includedir) then
platform:add("includedirs", includedir)
end
local linkdir = path.join(sdkdir, "lib")
if os.isdir(linkdir) then
platform:add("linkdirs", linkdir)
end
end
-- ok
return
end

 if config.get("cross") or config.get("bin") or config.get("sdk") then  
     -- will return ..
    return
 end

    -- not reached
    local archflags = nil
    local arch = config.get("arch")
    if arch then
        if arch == "x86_64" then archflags = "-m64"
        elseif arch == "i386" then archflags = "-m32"
        end
    end

About the conan package, I only tested the pc host architecture and I have not supported other archs.

I'm not sure if conan supports pulling armv8 and mips64 packages. If conan supports them, I can improve the xmake generator to support it.

@rel1ve
Copy link
Author

rel1ve commented Nov 6, 2019

I'm sure that conan supports pulling armv8 and mips64 packages. It's very useful for cross compile c++ projects to support multiple architectures.

@rel1ve
Copy link
Author

rel1ve commented Nov 6, 2019

Here are my conan package info on my conan-local repo by Jfrog Artifactory CE for c/c++.

OS: | Linux
Architecture: | armv8
Build Type: | Release
Compiler: | gcc
Compiler Version: | 4.9
compiler.libcxx: | libstdc++

OS: | Linux
Architecture: | x86_64
Build Type: | Release
Compiler: | gcc
Compiler Version: | 4.9
compiler.libcxx: | libstdc++

OS: | Linux
Architecture: | mips64
Build Type: | Release
Compiler: | gcc
Compiler Version: | 4.9
compiler.libcxx: | libstdc++

@waruqi
Copy link
Member

waruqi commented Nov 6, 2019

I don't have an environment for now, you can try to modify the code below to support it, or help me to submit a pr to support it.

table.insert(argv, "-s")
if opt.arch == "x86_64" or opt.arch == "x64" then
table.insert(argv, "arch=x86_64")
elseif opt.arch == "i386" or opt.arch == "x86" then
table.insert(argv, "arch=x86")
else
raise("cannot install package(%s) for arch(%s)!", name, opt.arch)
end

function _conan_get_arch(opt)
if opt.plat == "windows" then
return opt.arch == "x64" and "x86_64" or "x86"
else
return opt.arch == "i386" and "x86" or opt.arch
end
end

@rel1ve
Copy link
Author

rel1ve commented Nov 6, 2019

I tried to modify code in install_package.lua and find_package.lua to no effect.
I found some codes in conanfile.py of xmake_generater.

    # get plat
    plat = str(self.settings.get_safe("os_build"))

    # get mode
    mode = str(self.settings.get_safe("build_type"))

    # get arch
    arch = str(self.settings.get_safe("arch_build"))

    # make template
    template = ('  {plat}_{arch}_{mode} = \n'
                '  {{\n'
                '    includedirs = {{{deps.include_paths}}},\n'
                '    linkdirs    = {{{deps.lib_paths}}},\n'
                '    links       = {{{deps.libs}}},\n'
                '    defines     = {{{deps.defines}}},\n'
                '    cxxflags    = {{{deps.cppflags}}},\n'
                '    cflags      = {{{deps.cflags}}},\n'
                '    shflags     = {{{deps.sharedlinkflags}}},\n'
                '    ldflags     = {{{deps.exelinkflags}}}\n'
                '  }}')

And I modify conan's default profile and set arch_build=armv8, but it doesn't work. 'arch' is still x86_64.

@waruqi
Copy link
Member

waruqi commented Nov 7, 2019

I have supported it. You can run xmake update dev to update the dev version and try it again.

Please remove the previous conan package and .xmake cache first, because I updated xmake_generater.

conan remove xxx
rm -rf .xmake
xmake f -c -p linux -a arm64-v8a 
xmake f -c -p linux -a mips

local archs = {x86_64 = "x86_64",
x64 = "x86_64",
i386 = "x86",
x86 = "x86",
armv7 = "armv7",
armv7s = "armv7s",
arm64 = "armv8", -- for iphoneos
["arm64-v8a"] = "armv8",
mips = "mips",
mips64 = "mips64"}

In addition, I do not fully support for ios and android package, I will improve it in future, if you are interested, you can also help improve it.

@waruqi
Copy link
Member

waruqi commented Nov 8, 2019

I have tested it, it (dev version) supports for conan/ios package. (conan >= 1.20)

ref: https://docs.conan.io/en/latest/systems_cross_building/cross_building.html

@rel1ve
Copy link
Author

rel1ve commented Nov 8, 2019

It works.

@rel1ve rel1ve closed this as completed Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants