This version is mainly work or continue to improve support for tool chain, although last version through refactoring implements modular tool chain extension, but for a compiler to flexibly in cross switch compilation toolchain/Host tool chain, is not very good support, therefore this version key improvement to the support.

In addition, this release addresses the problem of slow downloads of remote dependencies using add_requires integration by adding support for proxy Settings and local package retrieval reuse. Of course, the best way is to make a domestic CDN to speed up the download, but this cost is too high, not for the time being.

There are also some minor changes and bug fixes, check out the update at the bottom of this article.

  • Program source code
  • The official documentation

New Features

Flexible switching between multiple tool chains

For an example of this, see the Luajit project, where the compilation process involves compiling minilua/ buildVM targets for the host platform, and then using Minilua/buildVM to generate jit code for the target platform to participate in the compilation of the entire Luajit library.

Therefore, the entire compilation process requires using the Host toolchain for specific targets, and then using the cross toolchain for other targets.

Lua can be set to host toolchains for specific targets using the set_toolChains interface.

target("buildvm")
    set_kind("binary")
    add_files("src/*.c")
    set_toolchains("xcode", {plat = os.host(), arch = os.arch()})

target("luajit")
    set_kind("static")
    add_deps("buildvm")
    add_files("src/*.c")
Copy the code

If you are currently in cross-build mode, its buildvm will actually build the macOS target program using Xcode, even if you configure it for android by executing the following command, and only the Luajit library is compiled using the NDK tool chain:

$ xmake f -p android --ndk=/xxxx
Copy the code

However, this is not particularly convenient, especially when cross-platform compilation, different platforms of PC tool chains are different, including MSVC, Xcode, Clang, etc., also need to determine the platform to specify.

We can also continue generalizing to make Xmake automatically select the currently available Host toolchain for different platforms, rather than explicitly specifying specific toolchains, and improve to the following version:

target("buildvm")
    set_kind("binary")
    add_files("src/*.c")
    set_plat(os.host())
    set_host(os.arch())

target("luajit")
    set_kind("static")
    add_deps("buildvm")
    add_files("src/*.c")
Copy the code

By using the set_plat and set_ARCH interfaces to set specific targets directly to the host platform, the host toolchain can be automatically selected internally.

A complete configuration example of this can be found at github.com/xmake-io/xm…

Remote package download optimization

If the network is unstable, the download speed is slow or the download fails, we can solve the problem in the following ways.

Manually download

By default, xmake will use curl, wget and other tools to download the package. You can also use your own downloader (or proxy) to download the package and put it in your own directory, for example: /download/packages/zlib-v1.0.tar.gz

Then use the following command to set the search directory for package downloads:

$ xmake g --pkg_searchdirs="/download/packages"
Copy the code

When xmake is re-compiled, xmake will first find source packages from/Download/Packages and then use them directly instead of downloading them themselves.

To find the package name, you can use the following command:

$ xmake require --info zlib
-> searchdirs: /download/packages
->Searchnames: zlib - 1.2.11. Tar. Gz
Copy the code

We can see the corresponding search directory and the package name searched.

Set the agent

If manual downloading is still a hassle, we can also make Xmake go directly to the proxy.

$ xmake g --proxy="Socks5: / / 127.0.0.1:1086"
$ xmake g --help
    -x PROXY, --proxy=PROXY  Use proxy on given port. [PROTOCOL://]HOST[:PORT]
                                 e.g.
                                 - xmake g --proxy='http://host:port'
                                 - xmake g --proxy='https://host:port'
                                 - xmake g --proxy='socks5://host:port'
Copy the code

Curl supports HTTP, HTTPS, socks5, and wget. Wget does not support socks5.

We can specify which host travel proxy to use with the following parameter, if not set, default global travel proxy.

--proxy_hosts=PROXY_HOSTS    Only enable proxy for the given hosts list, it will enable all if be unset,
                             and we can pass match pattern to list:
                                 e.g.
                                 - xmake g --proxy_hosts='github.com,gitlab.*,*.xmake.io'
Copy the code

If the hosts list is set, then matched hosts in the list will go to the proxy.

Proxy_host supports multiple hosts Settings, comma separated, and supports basic schema matching *.github.com, as well as other lua schema matching rules

If the hosts mode configuration above is not flexible enough, we can also follow pac’s automatic proxy configuration rules:

--proxy_pac=PROXY_PAC    Set the auto proxy configuration file. (default: pac.lua)
                                     e.g.
                                     - xmake g --proxy_pac=pac.lua (in /Users/ruki/.xmake or absolute path)
                                     - function main(url, host)
                                           if host == 'github.com' then
                                                return true
                                           end
                                       end
Copy the code

! > If there is proxy_hosts, the hosts configuration is preferred. If there is no proxy_hosts configuration, the pac configuration is preferred.

The default path for pac is ~/.xmake/pac.lua. If –proxy is set and the file exists, pac will be automatically removed.

You can also specify the PAC full path manually

$ xmake g --proxy_pac=/xxxx/xxxxx_pac.lua
Copy the code

Configuration rule Description:

function main(url, host)
    if host:find("bintray.com") then
        return true
    end
end
Copy the code

If true, the url and host are traveling proxies, and if they do not return or return false, they are not traveling proxies.

For more details, see: github.com/xmake-io/xm…

! > < span style = “max-width: 100%; clear: both; min-height: 1em

Other minor changes

Rc header files depend on compilation support

#include

#include

#include

#include

#include < XXX.



It may not be precise (you can’t handle macros yet), but it works.

Improved compiling mode. Minsizerel

The new version of MSVC under the minimum compilation, default open /GL compilation option, further optimize the size of the target file, optimization effect is relatively obvious.

For details, please refer to github.com/xmake-io/xm…

Improved Support for Protobuf rules

Xmake’s built-in protobuf. CPP compilation rules also support the use of *. Proto subdirectories where multiple levels of import files can be used. Previously, only proto files of the same level could be used.

This is the case with import common-files/b.proto:

proto-files
    a.proto
    common-files
        b.proto
Copy the code

The corresponding xmake.lua configuration is as follows:

add_requires("protobuf-cpp")

target("test")
    set_kind("binary")
    set_languages("c++11")
    add_packages("protobuf-cpp")
    add_files("*.cpp")
    add_files("proto/**.proto", {rules = "protobuf.cpp", proto_rootdir = "proto"})
Copy the code

An additional {proto_rootdir = “”} configuration is passed to specify the root of all proTos relative to the import as compared to the previous one.

For details of this section, see: github.com/xmake-io/xm…

Update the content

New features

  • addxmake show -l envsTo display a list of xmake’s built-in environment variables
  • #861: Supports searching local packages from the specified directory to install remote dependencies directly
  • #854: Support global proxy Settings for wget, curl, and Git

To improve the

  • #828: Added import subdirectory proto support for Protobuf rules
  • #835: Improved mode.minsizerel mode, added /GL support for MSVC, further optimized target program size
  • #828: Protobuf rule supports import multilevel subdirectories
  • # 838: Supports complete rewriting of built-in build rules,add_files("src/*.c", {rules = {"xx", override = true}})
  • #847: Support header dependency resolution for RC files
  • Improved MSVC toolchain to remove dependencies on global environment variables
  • # 857Improvement:set_toolchains()When cross-compiling is supported, specific targets can be switched to the host tool chain while compiling

Bugs fix

  • Fixed progress character display
  • #829: Fix invalid sysroot paths due to macOS case insensitive systems
  • #832: Fixed issue where find_packages could not be found in Debug mode