Network Optimization
If the download package is slow or fails due to an unstable network, we can use the following methods to resolve it.
Manual Download
By default, xmake will call curl, wget and other tools to download, users can also manually download with their own downloader (you can also use an agent), put the downloaded package in their own directory, for example: /download/packages/zlib -v1.0.tar.gz
Then use the following command to set the search directory for package download:
$ xmake g --pkg_searchdirs="/download/packages"
Then re-execute xmake to compile, xmake will first look for the source package from /download/packages
, and then use it directly, no longer download it yourself.
As for the package name you are looking for, you can check it by the following command:
$ xmake require --info zlib
-> searchdirs: /download/packages
-> searchnames: zlib-1.2.11.tar.gz
We can see the corresponding search directory and the searched package name.
Use Proxy
If manual downloading is still troublesome, we can also let xmake go directly to the agent.
$ 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'
The --proxy
parameter specifies the proxy protocol and address. The specific syntax can refer to curl. Usually, it can support http, https, socks5 and other protocols, but the actual support depends on curl, wget and git. For example, wget does not support the socks5 protocol.
We can use the following parameters to specify which hosts go to the proxy. If not set, the default is to go global.
--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'
If the hosts list is set, then the matching hosts in this list will go to the proxy. .
--proxy_host
supports multiple hosts settings, separated by commas, and supports basic pattern matching *.github.com, and other lua pattern matching rules are also supported
If we feel that the above hosts mode configuration 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
NOTE
If there are proxy_hosts, the host configuration is preferred, otherwise, the pac configuration can be used.
The default path of pac: ~/.xmake/pac.lua, if --proxy is set, and this file exists, it will automatically go to pac. If it does not exist, and there are no hosts, then the proxy will take effect globally.
You can also manually specify the pac full path
$ xmake g --proxy_pac=/xxxx/xxxxx_pac.lua
Configuration rule description:
function main(url, host)
if host:find("bintray.com") then
return true
end
end
If it returns true, then the url and host are the proxy to go, not to return or return false, it is not to proxy.
For specific details of this piece, see: https://github.com/xmake-io/xmake/issues/854
Configure Mirror Proxy
After v2.5.4, mirroring proxy rules can also be configured in the pac.lua configuration. For example, access to all github.com domain names is switched to the hub.fastgit.org domain name to achieve accelerated downloading of packages.
function mirror(url)
return url:gsub("github.com", "hub.fastgit.org")
end
$ xrepo install libpng
> curl https://hub.fastgit.org/glennrp/libpng/archive/v1.6.37.zip -o v1.6.37.zip