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

Improve to detect cross-compilation toolchains #780

Closed
33 of 35 tasks
waruqi opened this issue May 12, 2020 · 5 comments
Closed
33 of 35 tasks

Improve to detect cross-compilation toolchains #780

waruqi opened this issue May 12, 2020 · 5 comments

Comments

@waruqi
Copy link
Member

waruqi commented May 12, 2020

Roadmap

备注:重构工具链,实现平台定义和工具链完全分离,提供更好的工具链扩展性,支持对独立工具链完整快速切换,支持对target的单独工具链配置,支持在xmake.lua自定义工具链,内置支持更多常用交叉编译工具链

@waruqi
Copy link
Member Author

waruqi commented May 21, 2020

Switch the given toolchain in any platform

$ xmake f --toolchain=clang
$ xmake
$ xmake f --toolchain=llvm --sdk=/xxx/llvm
$ xmake
$ xmake f -p cross --sdk=/xxx/llvm
$ xmake

@waruqi
Copy link
Member Author

waruqi commented May 22, 2020

Custom toolchain in project xmake.lua

-- define toolchain
toolchain("myclang")

    -- mark as standalone toolchain
    set_kind("standalone")
        
    -- set toolset
    set_toolset("cc", "clang")
    set_toolset("cxx", "clang", "clang++")
    set_toolset("ld", "clang++", "clang")
    set_toolset("sh", "clang++", "clang")
    set_toolset("ar", "ar")
    set_toolset("ex", "ar")
    set_toolset("strip", "strip")
    set_toolset("mm", "clang")
    set_toolset("mxx", "clang", "clang++")
    set_toolset("as", "clang")

    add_defines("MYCLANG")

    -- check toolchain
    on_check(function (toolchain)
        return import("lib.detect.find_tool")("clang")
    end)

    -- on load
    on_load(function (toolchain)

        -- get march
        local march = is_arch("x86_64", "x64") and "-m64" or "-m32"

        -- init flags for c/c++
        toolchain:add("cxflags", march)
        toolchain:add("ldflags", march)
        toolchain:add("shflags", march)
        if not is_plat("windows") and os.isdir("/usr") then
            for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do
                if os.isdir(includedir) then
                    toolchain:add("includedirs", includedir)
                end
            end
            for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do
                if os.isdir(linkdir) then
                    toolchain:add("linkdirs", linkdir)
                end
            end
        end

        -- init flags for objc/c++  (with ldflags and shflags)
        toolchain:add("mxflags", march)

        -- init flags for asm
        toolchain:add("asflags", march)
    end)
$ xmake f --toolchain=myclang
$ xmake

@waruqi
Copy link
Member Author

waruqi commented May 22, 2020

Set the different toolchain to the given target

target("test")
    set_toolchains("clang", "yasm")

target("test2")
    set_toolset("cc", "clang")
    set_toolset("ld", "clang++")

@waruqi
Copy link
Member Author

waruqi commented May 29, 2020

Gnu

GNU Arm Embedded Toolchain

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm

xmake f -p cross --sdk=~/files/gcc-arm-none-eabi-9-2019-q4-major/ --toolchain=gnu-rm
xmake

@waruqi
Copy link
Member Author

waruqi commented May 29, 2020

Show toolchains

$ xmake show -l toolchains
xcode         Xcode IDE
vs            VisualStudio IDE
yasm          The Yasm Modular Assembler
clang         A C language family frontend for LLVM
go            Go Programming Language Compiler
dlang         D Programming Language Compiler
sdcc          Small Device C Compiler
cuda          CUDA Toolkit
ndk           Android NDK
rust          Rust Programming Language Compiler
llvm          A collection of modular and reusable compiler and toolchain technologies
cross         Common cross compilation toolchain
nasm          NASM Assembler
gcc           GNU Compiler Collection
mingw         Minimalist GNU for Windows
gnu-rm        GNU Arm Embedded Toolchain
envs          Environment variables toolchain
fasm          Flat Assembler

@waruqi waruqi closed this as completed Jun 3, 2020
@waruqi waruqi mentioned this issue Nov 1, 2020
@waruqi waruqi unpinned this issue Jan 8, 2021
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

1 participant