ruki 6 mesi fa
parent
commit
26bf381569

+ 1 - 0
docs/config.ts

@@ -78,6 +78,7 @@ function guideSidebar(): DefaultTheme.SidebarItem[] {
       items: [
         { text: 'Create Project', link: 'basic-commands/create-project' },
         { text: 'Build Configuration', link: 'basic-commands/build-configuration' },
+        { text: 'Cross Compilation', link: 'basic-commands/cross-compilation' },
       ]
     },
     {

+ 212 - 0
docs/guide/basic-commands/build-configuration.md

@@ -0,0 +1,212 @@
+# Build Configuration
+
+Set compilation configuration before building project with command `xmake f|config`. If you want to known more options, please run: `xmake f --help`。
+
+::: tip NOTE
+You can use short or long command option, for example: <br>
+`xmake f` or `xmake config`.<br>
+`xmake f -p linux` or `xmake config --plat=linux`.
+:::
+
+## Switch Platforms
+
+### Current Host
+
+:::tip NOTE
+Xmake will detect the current host platform automatically and build project.
+:::
+
+```bash
+$ xmake
+```
+
+### Linux
+
+```bash
+$ xmake f -p linux [-a i386|x86_64]
+$ xmake
+```
+
+### Android
+
+```bash
+$ xmake f -p android --ndk=~/files/android-ndk-r10e/ [-a armeabi-v7a|arm64-v8a]
+$ xmake
+```
+
+If you want to set the other android toolchains, you can use [--bin](#-bin) option.
+
+For example:
+
+```bash
+$ xmake f -p android --ndk=~/files/android-ndk-r10e/ -a arm64-v8a --bin=~/files/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin
+```
+
+The [--bin](#-bin) option is used to set `bin` directory of toolchains.
+
+::: tip NOTE
+Please attempt to set `--arch=` option if it had failed to check compiler.
+:::
+
+### iPhoneOS
+
+```bash
+$ xmake f -p iphoneos [-a armv7|armv7s|arm64|i386|x86_64]
+$ xmake
+```
+
+Since the emulator on the m1 device also supports the arm64 architecture, it is no longer possible to distinguish the emulator from the arch alone.
+Therefore, in version 2.6.5, we have added a new parameter to distinguish between emulator targets and emulator targets.
+
+```bash
+$ xmake f -p iphoneos --appledev=simulator
+$ xmake f -p watchos --appledev=simulator
+$ xmake f -p appletvos --appledev=simulator
+```
+
+### Mac Catalyst
+
+We can also specify to build Mac Catalyst programs.
+
+```bash
+$ xmake f --appledev=catalyst
+```
+
+### Windows
+
+```bash
+$ xmake f -p windows [-a x86|x64]
+$ xmake
+```
+
+### MinGW
+
+In addition to supporting Msys2/MingW, MingW for macOS/linux, xmake also supports the llvm-mingw tool chain, which can switch the arm/arm64 architecture to compile.
+
+```bash
+$ xmake f -p mingw --sdk=/usr/local/i386-mingw32-4.3.0/ [-a i386|x86_64|arm|arm64]
+$ xmake
+```
+
+### WASM (WebAssembly)
+
+This platform is used to compile WebAssembly programs (emcc toolchain is used internally). Before switching this platform, we need to enter the Emscripten toolchain environment to ensure that emcc and other compilers are available.
+
+```bash
+$ xmake f -p wasm
+$ xmake
+```
+
+Xmake also supports Qt for wasm compilation, you only need:
+
+```bash
+$ xmake f -p wasm [--qt=~/Qt]
+$ xmake
+```
+
+The `--qt` parameter setting is optional, usually xmake can detect the sdk path of qt.
+
+
+One thing to note is that there is a correspondence between the versions of Emscripten and Qt SDK. If the version does not match, there may be compatibility issues between Qt/Wasm.
+
+Regarding the version correspondence, you can see: [https://wiki.qt.io/Qt_for_WebAssembly](https://wiki.qt.io/Qt_for_WebAssembly)
+
+For more details, please see: [https://github.com/xmake-io/xmake/issues/956](https://github.com/xmake-io/xmake/issues/956)
+
+In addition to emscripten, there is a common wasi-sdk toolchain for building wasi-based programs, and we just need to switch between toolchains.
+
+```console
+$ xmake f -p wasm --toolchain=wasi
+$ xmake
+```
+
+### Apple WatchOS
+
+```bash
+$ xmake f -p watchos [-a i386|armv7k]
+$ xmake
+```
+
+### HarmonyOS
+
+Version 2.9.1 adds native toolchain compilation support for the Hongmeng OS platform:
+
+```bash
+$ xmake f -p harmony
+```
+
+xmake will automatically detect the default SDK path, but you can also specify the Harmony SDK path.
+
+```bash
+$ xmake f -p Harmony --sdk=/Users/ruki/Library/Huawei/Sdk/openharmony/10/native
+```
+
+## Global Configuration
+
+You can save to the global configuration for simplfying operation.
+
+For example:
+
+```bash
+$ xmake g --ndk=~/files/android-ndk-r10e/
+```
+
+Now, we config and build project for android again.
+
+```bash
+$ xmake f -p android
+$ xmake
+```
+
+::: tip NOTE
+You can use short or long command option, for example: `xmake g` or `xmake global`.
+:::
+
+## Clean Configuration
+
+We can clean all cached configuration and re-configure project.
+
+```bash
+$ xmake f -c
+$ xmake
+```
+
+or
+
+```bash
+$ xmake f -p iphoneos -c
+$ xmake
+```
+
+## Import and export configuration
+
+After 2.5.5, we can also import and export the configured configuration set to facilitate rapid configuration migration.
+
+### Export configuration
+
+```bash
+$ xmake f --export=/tmp/config.txt
+$ xmake f -m debug --xxx=y --export=/tmp/config.txt
+```
+
+### Import configuration
+
+```bash
+$ xmake f --import=/tmp/config.txt
+$ xmake f -m debug --xxx=y --import=/tmp/config.txt
+```
+
+### Export configuration (with menu)
+
+```bash
+$ xmake f --menu --export=/tmp/config.txt
+$ xmake f --menu -m debug --xxx=y --export=/tmp/config.txt
+```
+
+
+### Import configuration (with menu)
+
+```bash
+$ xmake f --menu --import=/tmp/config.txt
+$ xmake f --menu -m debug --xxx=y --import=/tmp/config.txt
+```

+ 581 - 0
docs/guide/basic-commands/cross-compilation.md

@@ -0,0 +1,581 @@
+---
+outline: deep
+---
+
+# Cross Compilation
+
+Generally, if we need to compile and generate object files that can be run on other devices in the current pc environment, we need to compile and generate them through the corresponding cross-compilation tool chain, such as compiling linux programs on win/macos, or Compile object files of other embedded devices, etc.
+
+The usual cross-compilation tool chain is based on gcc/clang, and most of them have a structure similar to the following:
+
+```
+/home/toolchains_sdkdir
+   - bin
+       - arm-linux-armeabi-gcc
+       - arm-linux-armeabi-ld
+       - ...
+   - lib
+       - libxxx.a
+   - include
+       - xxx.h
+```
+
+Each toolchain has a corresponding include/lib directory, which is used to place some system libraries and header files, such as libc, stdc++, etc., and a series of tools for compiling the tool chain are placed under the bin directory. E.g:
+
+```
+arm-linux-armeabi-ar
+arm-linux-armeabi-as
+arm-linux-armeabi-c++
+arm-linux-armeabi-cpp
+arm-linux-armeabi-g++
+arm-linux-armeabi-gcc
+arm-linux-armeabi-ld
+arm-linux-armeabi-nm
+arm-linux-armeabi-strip
+```
+
+The `arm-linux-armeabi-` prefix is cross, which is used to mark the target platform and architecture, and is mainly used to distinguish it from the host's own gcc/clang.
+
+The gcc/g++ inside is the c/c++ compiler, which can also be used as a linker. When linking, it will internally call ld to link, and automatically add some c++ libraries.
+Cpp is a preprocessor, as is an assembler, ar is used to generate a static library, and strip is used to crop out some symbol information, making the target program smaller. nm is used to view the list of exported symbols.
+
+## Automatic detection and compilation
+
+If our cross-compilation tool chain is the above structure, Xmake will automatically detect and identify the structure of the SDK, extract the cross and include/lib path location, users usually do not need to do additional parameter settings, just configure the SDK The root directory can be compiled, for example:
+
+```bash
+$ xmake f -p cross --sdk=/home/toolchains_sdkdir
+$ xmake
+```
+
+Among them, `-p cross` is used to specify that the current platform is a cross-compilation platform, and `--sdk=` is used to specify the root directory of the cross toolchain.
+
+Note: We can also specify the `-p linux` platform to configure cross compilation, the effect is the same, the only difference is that the name of the linux platform is additionally identified, which is convenient for `xmake.lua` to determine the platform by` is_plat ("linux") ` .
+
+At this time, Xmake will automatically detect the prefix name cross of gcc and other compilers: `arm-linux-armeabi-`, and when compiling, it will also automatically add search options for` link library` and `header files` :
+
+```
+-I/home/toolchains_sdkdir/include
+-L/home/toolchains_sdkdir/lib
+```
+
+These are handled automatically by Xmake, there is no need to configure them manually.
+
+## Manually configure and compile
+
+If the above automatic detection fails to completely compile for some tool chains, you need to manually set some configuration parameters related to cross compilation to adjust to these special tool chains. I will explain how to configure them one by one.
+
+## Set toolchain bin directory
+
+For the irregular tool chain directory structure, by simply setting the [--sdk](https://xmake.io/#/zh-cn/guide/configuration?id=-sdk) option, it is impossible to completely detect the passing situation Next, you can continue to set the location of the bin directory of the toolchain through this option.
+
+For example: for some special cross toolchains, the compiler bin directory is not in the `/home/toolchains_sdkdir/bin` position, but is instead in `/usr/opt/bin`
+
+At this time, we can add the parameter setting of the bin directory on the basis of setting the sdk parameter to adjust the bin directory of the tool chain.
+
+```bash
+$ xmake f -p cross --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin
+$ xmake
+```
+
+## Set tool prefix for cross toolchain
+
+Like aarch64-linux-android-, usually if you configure --sdk or --bin, Xmake will automatically detect it, you don't need to set it manually.
+
+But for some very special tool chains, if there are multiple cross prefix tool bins in a directory at the same time, you need to manually set this configuration to distinguish which bin you need to choose.
+
+For example, there are two different compilers in the bin directory of toolchains:
+
+```
+/opt/bin
+  - armv7-linux-gcc
+  - aarch64-linux-gcc
+```
+
+We now want to choose the armv7 version, then we can append `--cross=` to configure the compiler tool prefix name, for example:
+
+```bash
+$ xmake f -p cross --sdk=/usr/toolsdk --bin=/opt/bin --cross=armv7-linux-
+```
+
+## Set the c/c++ compiler
+
+If you want to continue to subdivide and select compilers, continue to add relevant compiler options, for example:
+
+```bash
+$ xmake f -p cross --sdk=/user/toolsdk --cc=armv7-linux-clang --cxx=armv7-linux-clang++
+```
+
+Of course, we can also specify the full path of the compiler.
+
+`--cc` is used to specify the name of the c compiler, and `--cxx` is used to specify the name of the c++ compiler.
+
+Note: If the cc/cxx environment variable exists, the value specified in the current environment variable will be used first.
+
+If the specified compiler name is not a name recognized by Xmake (with gcc, clang, etc.), then the compiler tool detection will fail.
+
+At this time we can pass:
+
+```bash
+xmake f --cxx=clang++@/home/xxx/c++mips.exe
+```
+
+Set the c ++ mips.exe compiler as the clang ++-like way to compile.
+That is to say, while specifying the compiler as `c++mips.exe`, tell Xmake that it is basically the same as clang ++ usage and parameter options.
+
+## Set the c/c++ linker
+
+If you want to continue to subdivide and select the linker, continue to add related linker options, for example:
+
+```bash
+$ xmake f -p cross --sdk=/user/toolsdk --ld=armv7-linux-clang++ --sh=armv7-linux-clang++ --ar=armv7-linux-ar
+```
+
+ld specifies the executable program linker, sh specifies the shared library program linker, and ar specifies the archiver that generates the static library.
+
+Note: If there are ld/sh/ar environment variables, the value specified in the current environment variable will be used first.
+
+## Set header file and library search directory
+
+If there are additional other include/lib directories in the SDK that are not in the standard structure, resulting in cross compilation can not find the library and header files, then we can append the search path through `--includedirs` and` --linkdirs`, and then Add additional link libraries via `--links`.
+
+```bash
+$ xmake f -p cross --sdk=/usr/toolsdk --includedirs=/usr/toolsdk/xxx/include --linkdirs=/usr/toolsdk/xxx/lib --links=pthread
+```
+
+Note: If you want to specify multiple search directories, you can use `:` or `;` to separate, which is the path separator of different host platforms, use `:` under linux / macos, and `;` under win.
+
+## Set compile and link options
+
+We can also configure some additional compilation and linking options through `--cflags`,` --cxxflags`, `--ldflags`, `--shflags` and `--arflags` according to the actual situation.
+
+* cflags: specify c compilation parameters
+* cxxflags: specify c ++ compilation parameters
+* cxflags: specify c / c ++ compilation parameters
+* asflags: specify assembler compilation parameters
+* ldflags: specify executable program link parameters
+* shflags: specify dynamic library program link parameters
+* arflags: specify the generation parameters of the static library
+
+e.g:
+
+```bash
+$ xmake f -p cross --sdk=/usr/toolsdk --cflags="-DTEST -I/xxx/xxx" --ldflags="-lpthread"
+```
+
+## Custom build platform
+
+If the target program has a corresponding platform to be specified after a cross tool chain is compiled, and it needs to be configured in `xmake.lua` according to different cross compilation platforms, and some additional compilation parameters need to be configured, then the `-p cross` setting above Can not meet the demand.
+
+In fact, the `-p/-plat=` parameter can also be set to other custom values. You only need to maintain the corresponding relationship with `is_plat`. All non-built-in platform names will default to cross-compilation mode, for example:
+
+```bash
+$ xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/
+$ xmake
+```
+
+We passed in the myplat custom platform name as the current cross-toolchain compilation platform, and then we set the corresponding settings for this platform in `xmake.lua`:
+
+```lua
+if is_plat("myplat") then
+    add_defines("TEST")
+end
+```
+
+In this way, Xmake can be easily extended to deal with various compilation platforms, users can extend their own support for freebsd, netbsd, sunos and other cross-compiling platforms.
+
+I excerpted a cross-compilation configuration written before porting libuv, and intuitively feel:
+
+```lua
+-- for dragonfly/freebsd/netbsd/openbsd platform
+if is_plat("dragonfly", "freebsd", "netbsd", "openbsd") then
+    add_files("src/unix/bsd-ifaddrs.c")
+    add_files("src/unix/freebsd.c")
+    add_files("src/unix/kqueue.c")
+    add_files("src/unix/posix-hrtime.c")
+    add_headerfiles("(include/uv-bsd.h)")
+end
+
+-- for sunos platform
+if is_plat("sunos") then
+    add_files("src/unix/no-proctitle.c")
+    add_files("src/unix/sunos.c")
+    add_defines("__EXTENSIONS_", "_XOPEN_SOURCE=600")
+    add_headerfiles("(include/uv-sunos.h)")
+end
+```
+
+Then, we can switch these platforms to compile:
+
+```bash
+$ xmake f -p [dragonfly|freebsd|netbsd|openbsd|sunos] --sdk=/home/arm-xxx-gcc/
+$ xmake
+```
+
+In addition, the built-in Linux platform also supports cross-compilation. If you do n’t want to configure other platform names, you can cross-compile as the linux platform.
+
+```bash
+$ xmake f -p linux --sdk=/usr/local/arm-xxx-gcc/
+$ xmake
+```
+
+As long as the `--sdk=` and other parameters are set, the cross-compilation mode of the Linux platform will be enabled.
+
+## Toolchain configuration
+
+For a complete list of tool chains, please execute the following command to view:
+
+```bash
+$ xmake show -l toolchains
+```
+
+::: tip NOTE
+This feature requires v2.3.4 or later to support
+:::
+
+The above describes the general cross-compilation toolchain configuration. If some specific toolchains need to be imported into additional scenarios such as `--ldflags/--includedirs`, it is more cumbersome
+Therefore, xmake also has some common tool chains built-in, which can save the complicated configuration process of cross-compilation tool chain, and only need to execute:
+
+```bash
+$ xmake f --toolchain=gnu-rm --sdk=/xxx/
+$ xmake
+```
+
+You can quickly switch the designated cross-compilation tool chain. If this tool chain needs to add some specific flags settings, it will be automatically set up to simplify configuration.
+
+Among them, gnu-rm is the built-in GNU Arm Embedded Toolchain.
+
+For example, we can also quickly switch from the entire gcc tool chain to the clang or llvm tool chain, no longer need to make `xmake f --cc=clang --cxx=clang --ld=clang++` one by one.
+
+```bash
+$ xmake f --toolchain=clang
+$ xmake
+```
+
+or
+
+```bash
+$ xmake f --toolchain=llvm --sdk=/xxx/llvm
+$ xmake
+```
+
+The specific tool chains supported by Xmake can be viewed with the following command:
+
+```bash
+$ 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
+```
+
+### Custom toolchain
+
+In addition, we can also customize the toolchain in `xmake.lua`, and then specify the switch through `xmake f --toolchain=myclang`, for example:
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    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")
+
+    - ...
+```
+
+For details about this piece, you can go to the [Custom Toolchain](https://xmake.io/#/manual/custom_toolchain).
+
+For more details, please see: [#780](https://github.com/xmake-io/xmake/issues/780)
+
+### MingW Toolchain
+
+Compiling with the mingw toolchain is actually cross-compilation, but because this is more commonly used, Xmake specifically adds a mingw platform to quickly handle compilation using the mingw toolchain.
+
+Therefore, Xmake's toolchain detection for mingw will be more perfect. Under macos, basically even the sdk path does not need to be configured, and can be directly detected, only need to switch to the mingw platform to compile.
+
+```bash
+$ xmake f -p mingw
+$ xmake -v
+configure
+{
+    ld = /usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-g++
+    ndk_stdcxx = true
+    plat = mingw
+    mingw = /usr/local/opt/mingw-w64
+    buildir = build
+    arch = x86_64
+    xcode = /Applications/Xcode.app
+    mode = release
+    cxx = /usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-gcc
+    cross = x86_64-w64-mingw32-
+    theme = default
+    kind = static
+    ccache = true
+    host = macosx
+    clean = true
+    bin = /usr/local/opt/mingw-w64/bin
+}
+[  0%]: cache compiling.release src/main.cpp
+/usr/local/bin/ccache /usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-gcc -c -fvisibility=hidden -O3 -m64 -o build/.objs/test/mingw/x86_64/release/src/main.cpp.obj src/main.cpp
+[100%]: linking.release test.exe
+/usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-g++ -o build/mingw/x86_64/release/test.exe build/.objs/test/mingw/x86_64/release/src/main.cpp.obj -s -fvisibility=hidden -m64
+build ok!
+```
+
+Here we have added the `-v` parameter and looked at the detailed compile commands and detected mingw toolchain configuration values, where cross is automatically detected as:` x86_64-w64-mingw32-`, and the bin directory is also automatically detected , As well as compilers and linkers.
+
+Although it is not possible to automatically detect the sdk path on linux/win, we can also manually specify the sdk path. It should be noted that xmake specifically provides a `--mingw =` parameter for mingw to specify the tool chain root of mingw The directory has the same effect as `--sdk =`, but it can be set as a global configuration.
+
+```bash
+$ xmake g --mingw=/home/mingwsdk
+$ xmake f -p mingw
+$ xmake
+```
+
+After setting the `--mingw` root directory to the global configuration through the` xmake g/global` command, after each compilation and switching of the compilation platform, there is no need to specify an additional mingw toolchain path, which is convenient for use.
+
+In addition, the usage of other tool chain configuration parameters is the same as that described above. For example, `--cross`,` --bin=`, etc. can be adjusted according to the actual needs of the environment. Own mingw tool chain.
+
+xmake also supports the llvm-mingw tool chain, which can be switched to arm/arm64 architecture to compile.
+
+```bash
+$ xmake f --mingw=/xxx/llvm-mingw -a arm64
+$ xmake
+```
+
+### LLVM Toolchain
+
+The tool chain of llvm is relatively standard, only need to set the sdk configuration path to use:
+
+```bash
+$ xmake f -p cross --toolchain=llvm --sdk="C:\Program Files\LLVM"
+$ xmake
+```
+
+### GNU-RM Toolchain
+
+toolchain downlaod url: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads#
+
+```bash
+$ xmake f -p cross --toolchain=gnu-rm --sdk=/xxx/cc-arm-none-eabi-9-2019-q4-major
+$ xmake
+```
+
+### TinyC Toolchain
+
+```bash
+$ xmake f --toolchain=tinyc
+$ xmake
+```
+
+::: tip NOTE
+In the Releases directory, we also provide a special xmake-tinyc-vX.X.X.win32.exe installation package, built-in tinyc tool chain, without relying on msvc, you can also compile c code, out of the box use without dependencies.
+:::
+
+### Emcc tool chain
+
+Usually only need to switch to the Wasm platform, which has built-in emcc toolchain, and additionally adjusts the extension of the target program to `*.html` and output `*.wasm`.
+
+```bash
+$ xmake f -p wasm
+$ xmake
+```
+
+However, we can also switch directly to the emcc toolchain, but the suffix name will not be modified.
+
+```bash
+$ xmake f --toolchain=emcc
+$ xmake
+```
+
+### Intel C++ Compiler Tool Chain
+
+```bash
+$ xmake f --toolchain=icc
+$ xmake
+```
+
+### Intel Fortran Compilation Tool Chain
+
+```bash
+$ xmake f --toolchain=ifort
+$ xmake
+```
+
+## Common Cross-compilation configuration
+
+if you want to known more options, please run: `xmake f --help`。
+
+### --sdk
+
+- Set the sdk root directory of toolchains
+
+xmake provides a convenient and flexible cross-compiling support.
+In most cases, we need not to configure complex toolchains prefix, for example: `arm-linux-`
+
+As long as this toolchains meet the following directory structure:
+
+```
+/home/toolchains_sdkdir
+   - bin
+       - arm-linux-gcc
+       - arm-linux-ld
+       - ...
+   - lib
+       - libxxx.a
+   - include
+       - xxx.h
+```
+
+Then,we can only configure the sdk directory and build it.
+
+```bash
+$ xmake f -p linux --sdk=/home/toolchains_sdkdir
+$ xmake
+```
+
+Xmake will detect the prefix: arm-linux- and add the include and library search directory automatically.
+
+```
+-I/home/toolchains_sdkdir/include -L/home/toolchains_sdkdir/lib
+```
+
+### --bin
+
+- Set the `bin` directory of toolchains
+
+We need set it manually if the toolchains /bin directory is in other places, for example:
+
+```bash
+$ xmake f -p linux --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin
+$ xmake
+```
+
+::: tip NOTE
+Before v2.2.1 version, this parameter name is `--toolchains`, exists more ambiguous, so we changed to `--bin=` to set the bin directory.
+:::
+
+### --cross
+
+- Set the prefix of compilation tools
+
+For example, under the same toolchains directory at the same time, there are two different compilers:
+
+```
+/opt/bin
+ - armv7-linux-gcc
+ - aarch64-linux-gcc
+```
+
+If we want to use the `armv7-linux-gcc` compiler, we can run the following command:
+
+```bash
+$ xmake f -p linux --sdk=/usr/toolsdk --bin=/opt/bin --cross=armv7-linux-
+```
+
+### --as
+
+- Set `asm` assembler
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --as=armv7-linux-as
+```
+
+If the 'AS' environment variable exists, it will use the values specified in the current environment variables.
+
+::: tip NOTE
+We can set a unknown compiler as like-gcc/clang compiler, .e.g `xmake f --as=gcc@/home/xxx/asmips.exe`
+:::
+
+### --cc
+
+- Set c compiler
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --cc=armv7-linux-clang
+```
+
+If the 'CC' environment variable exists, it will use the values specified in the current environment variables.
+
+::: tip NOTE
+We can set a unknown compiler as like-gcc/clang compiler, .e.g `xmake f --cc=gcc@/home/xxx/ccmips.exe`
+:::
+
+### --cxx
+
+- Set `c++` compiler
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --cxx=armv7-linux-clang++
+```
+
+If the 'CXX' environment variable exists, it will use the values specified in the current environment variables.
+
+::: tip NOTE
+We can set a unknown compiler as like-gcc/clang compiler, .e.g `xmake f --cxx=g++@/home/xxx/c++mips.exe`
+:::
+
+### --ld
+
+- Set `c/c++/objc/asm` linker
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --ld=armv7-linux-clang++
+```
+
+If the 'LD' environment variable exists, it will use the values specified in the current environment variables.
+
+::: tip NOTE
+We can set a unknown compiler as like-gcc/clang linker, .e.g `xmake f --ld=g++@/home/xxx/c++mips.exe`
+:::
+
+### --sh
+
+- Set `c/c++/objc/asm` shared library linker
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --sh=armv7-linux-clang++
+```
+
+If the 'SH' environment variable exists, it will use the values specified in the current environment variables.
+
+::: tip NOTE
+We can set a unknown compiler as like-gcc/clang linker, .e.g `xmake f --sh=g++@/home/xxx/c++mips.exe`
+:::
+
+### --ar
+
+- Set `c/c++/objc/asm` static library archiver
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --ar=armv7-linux-ar
+```
+
+If the 'AR' environment variable exists, it will use the values specified in the current environment variables.
+
+::: tip NOTE
+We can set a unknown compiler as like-ar archiver, .e.g `xmake f --ar=ar@/home/xxx/armips.exe`
+:::
+

+ 1 - 0
docs/zh/config.ts

@@ -159,6 +159,7 @@ function guideSidebar(): DefaultTheme.SidebarItem[] {
       items: [
         { text: '创建工程', link: 'basic-commands/create-project' },
         { text: '编译配置', link: 'basic-commands/build-configuration' },
+        { text: '交叉编译', link: 'basic-commands/cross-compilation' },
       ]
     },
     {

+ 213 - 0
docs/zh/guide/basic-commands/build-configuration.md

@@ -0,0 +1,213 @@
+# 编译配置 {#build-configuration}
+
+通过`xmake f|config`配置命令,设置构建前的相关配置信息,详细参数选项,请运行: `xmake f --help`。
+
+::: tip 注意
+你可以使用命令行缩写来简化输入,也可以使用全名,例如: <br>
+`xmake f` 或者 `xmake config`.<br>
+`xmake f -p linux` 或者 `xmake config --plat=linux`.
+:::
+
+## 切换平台 {#switch-platforms}
+
+### 主机平台
+
+```bash
+$ xmake
+```
+
+::: tip 注意
+Xmake 将会自动探测当前主机平台,默认自动生成对应的目标程序。
+:::
+
+### Linux
+
+```bash
+$ xmake f -p linux [-a i386|x86_64]
+$ xmake
+```
+
+### Android
+
+```bash
+$ xmake f -p android --ndk=~/files/android-ndk-r10e/ [-a armeabi-v7a|arm64-v8a]
+$ xmake
+```
+
+如果要手动指定ndk中具体某个工具链,而不是使用默认检测的配置,可以通过[--bin](#-bin)来设置,例如:
+
+```bash
+$ xmake f -p android --ndk=~/files/android-ndk-r10e/ -a arm64-v8a --bin=~/files/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin
+```
+
+[--bin](#-bin)主要用于设置选择编译工具的具体bin目录,这个的使用跟[交叉编译](#交叉编译)中的[--bin](#-bin)的行为是一致的。
+
+::: tip 注意
+如果手动设置了bin目录,没有通过检测,可以看下是否`--arch=`参数没有匹配对。
+:::
+
+### iPhoneOS
+
+```bash
+$ xmake f -p iphoneos [-a armv7|armv7s|arm64|i386|x86_64]
+$ xmake
+```
+
+由于 m1 设备上模拟器也支持 arm64 架构,因此之前单纯从 arch 去区分是否为模拟器,已无法满足需求。
+因此,2.6.5 版本,我们新增了一个参数配置去区分是否为模拟器目标。
+
+```bash
+$ xmake f -p iphoneos --appledev=simulator
+$ xmake f -p watchos --appledev=simulator
+$ xmake f -p appletvos --appledev=simulator
+```
+
+### Mac Catalyst
+
+我们也可以指定构建 Mac Catalyst 程序。
+
+```bash
+$ xmake f --appledev=catalyst
+```
+
+### Windows
+
+```bash
+$ xmake f -p windows [-a x86|x64]
+$ xmake
+```
+
+### Mingw
+
+xmake 除了支持 Msys2/MingW, MingW for macOS/linux 之外,还支持 llvm-mingw 工具链,可以切换 arm/arm64 架构来编译。
+
+```bash
+$ xmake f -p mingw --sdk=/usr/local/i386-mingw32-4.3.0/ [-a i386|x86_64|arm|arm64]
+$ xmake
+```
+
+### Apple WatchOS
+
+```bash
+$ xmake f -p watchos [-a i386|armv7k]
+$ xmake
+```
+
+### Wasm (WebAssembly)
+
+此平台用于编译 WebAssembly 程序(内部会使用emcc工具链),在切换此平台之前,我们需要先进入 Emscripten 工具链环境,确保 emcc 等编译器可用。
+
+```bash
+$ xmake f -p wasm
+$ xmake
+```
+
+xmake 也支持 Qt for wasm 编译,只需要:
+
+```bash
+$ xmake f -p wasm [--qt=~/Qt]
+$ xmake
+```
+
+其中 `--qt` 参数设置是可选的,通常xmake都能检测到qt的sdk路径。
+
+
+需要注意的一点是,Emscripten 和 Qt SDK 的版本是有对应关系的,不匹配的版本,可能会有Qt/Wasm之间的兼容问题。
+
+关于版本对应关系,可以看下:[https://wiki.qt.io/Qt_for_WebAssembly](https://wiki.qt.io/Qt_for_WebAssembly)
+
+更多详情见:[https://github.com/xmake-io/xmake/issues/956](https://github.com/xmake-io/xmake/issues/956)
+
+除了 emscripten 以外,还有一个常用的wasm工具链 wasi-sdk,用于构建基于wasi的程序,我们仅仅只需要切换工具链即可。
+
+```bash
+$ xmake f -p wasm --toolchain=wasi
+$ xmake
+```
+
+### HarmonyOS (鸿蒙)
+
+2.9.1 版本新增了鸿蒙 OS 平台的 native 工具链编译支持:
+
+```bash
+$ xmake f -p harmony
+```
+
+xmake 会自动探测默认的 SDK 路径,当然我们也可以指定 Harmony SDK 路径。
+
+```bash
+$ xmake f -p Harmony --sdk=/Users/ruki/Library/Huawei/Sdk/openharmony/10/native
+```
+
+
+## 全局配置
+
+我们也可以将一些常用配置保存到全局配置中,来简化频繁地输入:
+
+例如:
+
+```bash
+$ xmake g --ndk=~/files/android-ndk-r10e/
+```
+
+现在,我们重新配置和编译`android`程序:
+
+```bash
+$ xmake f -p android
+$ xmake
+```
+
+以后,就不需要每次重复配置`--ndk=`参数了。
+
+::: tip 注意
+每个命令都有其简写,例如: `xmake g` 或者 `xmake global`.
+:::
+
+## 清除配置
+
+有时候,配置出了问题编译不过,或者需要重新检测各种依赖库和接口,可以加上`-c`参数,清除缓存的配置,强制重新检测和配置
+
+```bash
+$ xmake f -c
+$ xmake
+```
+
+或者:
+
+```bash
+$ xmake f -p iphoneos -c
+$ xmake
+```
+
+## 导入导出配置
+
+2.5.5 之后,我们还可以导入导出已经配置好的配置集,方便配置的快速迁移。
+
+### 导出配置
+
+```bash
+$ xmake f --export=/tmp/config.txt
+$ xmake f -m debug --xxx=y --export=/tmp/config.txt
+```
+
+### 导入配置
+
+```bash
+$ xmake f --import=/tmp/config.txt
+$ xmake f -m debug --xxx=y --import=/tmp/config.txt
+```
+
+### 导出配置(带菜单)
+
+```bash
+$ xmake f --menu --export=/tmp/config.txt
+$ xmake f --menu -m debug --xxx=y --export=/tmp/config.txt
+```
+
+
+### 导入配置(带菜单)
+
+```bash
+$ xmake f --menu --import=/tmp/config.txt
+$ xmake f --menu -m debug --xxx=y --import=/tmp/config.txt
+```

+ 651 - 0
docs/zh/guide/basic-commands/cross-compilation.md

@@ -0,0 +1,651 @@
+---
+outline: deep
+---
+
+# 交叉编译 {#cross-compilation}
+
+通常,如果我们需要在当前pc环境编译生成其他设备上才能运行的目标文件时候,就需要通过对应的交叉编译工具链来编译生成它们,比如在win/macos上编译linux的程序,或者在linux上编译其他嵌入式设备的目标文件等。
+
+通常的交叉编译工具链都是基于gcc/clang的,大都具有类似如下的结构:
+
+```
+/home/toolchains_sdkdir
+   - bin
+       - arm-linux-armeabi-gcc
+       - arm-linux-armeabi-ld
+       - ...
+   - lib
+       - libxxx.a
+   - include
+       - xxx.h
+```
+
+每个工具链都有对应的include/lib目录,用于放置一些系统库和头文件,例如libc, stdc++等,而bin目录下放置的就是编译工具链一系列工具。例如:
+
+```
+arm-linux-armeabi-ar
+arm-linux-armeabi-as
+arm-linux-armeabi-c++
+arm-linux-armeabi-cpp
+arm-linux-armeabi-g++
+arm-linux-armeabi-gcc
+arm-linux-armeabi-ld
+arm-linux-armeabi-nm
+arm-linux-armeabi-strip
+```
+
+其中`arm-linux-armeabi-`前缀就是cross,通过用来标示目标平台和架构,主要用于跟主机自身的gcc/clang进行区分。
+
+里面的gcc/g++就是c/c++的编译器,通常也可以作为链接器使用,链接的时候内部会去调用ld来链接,并且自动追加一些c++库。
+cpp是预处理器,as是汇编器,ar用于生成静态库,strip用于裁剪掉一些符号信息,使得目标程序会更加的小。nm用于查看导出符号列表。
+
+## 自动探测和编译
+
+如果我们的交叉编译工具链是上文的结构,xmake会自动检测识别这个sdk的结构,提取里面的cross,以及include/lib路径位置,用户通常不需要做额外的参数设置,只需要配置好sdk根目录就可以编译了,例如:
+
+```bash
+$ xmake f -p cross --sdk=/home/toolchains_sdkdir
+$ xmake
+```
+
+其中,`-p cross`用于指定当前的平台是交叉编译平台,`--sdk=`用于指定交叉工具链的根目录。
+
+注:我们也可以指定`-p linux`平台来配置交叉编译,效果是一样的,唯一的区别是额外标识了linux平台名,方便xmake.lua里面通过`is_plat("linux")`来判断平台。
+
+这个时候,xmake会去自动探测gcc等编译器的前缀名cross:`arm-linux-armeabi-`,并且编译的时候,也会自动加上`链接库`和`头文件`的搜索选项,例如:
+
+```
+-I/home/toolchains_sdkdir/include
+-L/home/toolchains_sdkdir/lib
+```
+
+这些都是xmake自动处理的,不需要手动配置他们。
+
+## 手动配置编译
+
+如果上面的自动检测对某些工具链,还无法完全通过编译,就需要用户自己手动设置一些交叉编译相关的配置参数,来调整适应这些特殊的工具链了,下面我会逐一讲解如何配置。
+
+## 设置工具链bin目录
+
+对于不规则工具链目录结构,靠单纯地[--sdk](https://xmake.io/#/zh-cn/guide/configuration?id=-sdk)选项设置,没法完全检测通过的情况下,可以通过这个选项继续附加设置工具链的bin目录位置。
+
+例如:一些特殊的交叉工具链的,编译器bin目录,并不在  `/home/toolchains_sdkdir/bin`  这个位置,而是独立到了  `/usr/opt/bin`
+
+这个时候,我们可以在设置了sdk参数的基础上追加bin目录的参数设置,来调整工具链的bin目录。
+
+```bash
+$ xmake f -p cross --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin
+$ xmake
+```
+
+## 设置交叉工具链工具前缀
+
+像aarch64-linux-android-这种,通常如果你配置了--sdk或者--bin的情况下,xmake会去自动检测的,不需要自己手动设置。
+
+但是对于一些极特殊的工具链,一个目录下同时有多个cross前缀的工具bin混在一起的情况,你需要手动设置这个配置,来区分到底需要选用哪个bin。
+
+例如,toolchains的bin目录下同时存在两个不同的编译器:
+
+```
+/opt/bin
+  - armv7-linux-gcc
+  - aarch64-linux-gcc
+```
+
+我们现在想要选用armv7的版本,那么我们可以追加`--cross=`配置编译工具前缀名,例如:
+
+```bash
+$ xmake f -p cross --sdk=/usr/toolsdk --bin=/opt/bin --cross=armv7-linux-
+```
+
+## 设置c/c++编译器
+
+如果还要继续细分选择编译器,则继续追加相关编译器选项,例如:
+
+```bash
+$ xmake f -p cross --sdk=/user/toolsdk --cc=armv7-linux-clang --cxx=armv7-linux-clang++
+```
+
+当然,我们也可以指定编译器全路径。
+
+`--cc`用于指定c编译器名,`--cxx`用于指定c++编译器名。
+
+注:如果存在CC/CXX环境变量的话,会优先使用当前环境变量中指定的值。
+
+如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。
+
+这个时候我们可以通过:
+
+```bash
+xmake f --cxx=clang++@/home/xxx/c++mips.exe
+```
+
+设置c++mips.exe编译器作为类clang++的使用方式来编译。
+
+也就是说,在指定编译器为`c++mips.exe`的同时,告诉xmake,它跟clang++用法和参数选项基本相同。
+
+## 设置c/c++链接器
+
+如果还要继续细分选择链接器,则继续追加相关链接器选项,例如:
+
+```bash
+$ xmake f -p cross --sdk=/user/toolsdk --ld=armv7-linux-clang++ --sh=armv7-linux-clang++ --ar=armv7-linux-ar
+```
+
+ld指定可执行程序链接器,sh指定共享库程序链接器,ar指定生成静态库的归档器。
+
+注:如果存在LD/SH/AR环境变量的话,会优先使用当前环境变量中指定的值。
+
+## 设置头文件和库搜索目录
+
+如果sdk里面还有额外的其他include/lib目录不在标准的结构中,导致交叉编译找不到库和头文件,那么我们可以通过`--includedirs`和`--linkdirs`来追加搜索路径,然后通过`--links`添加额外的链接库。
+
+```bash
+$ xmake f -p cross --sdk=/usr/toolsdk --includedirs=/usr/toolsdk/xxx/include --linkdirs=/usr/toolsdk/xxx/lib --links=pthread
+```
+
+注:如果要指定多个搜索目录,可以通过`:`或者`;`来分割,也就是不同主机平台的路径分隔符,linux/macos下用`:`,win下用`;`。
+
+## 设置编译和链接选项
+
+我们也可以根据实际情况通过`--cflags`, `--cxxflags`,`--ldflags`,`--shflags`和`--arflags`额外配置一些编译和链接选项。
+
+* cflags: 指定c编译参数
+* cxxflags:指定c++编译参数
+* cxflags: 指定c/c++编译参数
+* asflags: 指定汇编器编译参数
+* ldflags: 指定可执行程序链接参数
+* shflags: 指定动态库程序链接参数
+* arflags: 指定静态库的生成参数
+
+例如:
+
+```bash
+$ xmake f -p cross --sdk=/usr/toolsdk --cflags="-DTEST -I/xxx/xxx" --ldflags="-lpthread"
+```
+
+## 自定义编译平台
+
+如果某个交叉工具链编译后目标程序有对应的平台需要指定,并且需要在xmake.lua里面根据不同的交叉编译平台,还需要配置一些额外的编译参数,那么上文的`-p cross`设置就不能满足需求了。
+
+其实,`-p/--plat=`参数也可以设置为其他自定义的值,只需要跟`is_plat`保持对应关系就可以,所有非内置平台名,都会默认采用交叉编译模式,例如:
+
+```bash
+$ xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/
+$ xmake
+```
+
+我们传入了myplat自定义平台名,作为当前交叉工具链的编译平台,然后xmake.lua里面我们对这个平台,配置下对应的设置:
+
+```lua
+if is_plat("myplat") then
+    add_defines("TEST")
+end
+```
+
+通过这种方式,xmake就可以很方便的扩展处理各种编译平台,用户可以自己扩展支持freebsd, netbsd, sunos等其他各种平台的交叉编译。
+
+我摘录一段之前移植libuv写的交叉编译的配置,直观感受下:
+
+```lua
+-- for dragonfly/freebsd/netbsd/openbsd platform
+if is_plat("dragonfly", "freebsd", "netbsd", "openbsd") then
+    add_files("src/unix/bsd-ifaddrs.c")
+    add_files("src/unix/freebsd.c")
+    add_files("src/unix/kqueue.c")
+    add_files("src/unix/posix-hrtime.c")
+    add_headerfiles("(include/uv-bsd.h)")
+end
+
+-- for sunos platform
+if is_plat("sunos") then
+    add_files("src/unix/no-proctitle.c")
+    add_files("src/unix/sunos.c")
+    add_defines("__EXTENSIONS_", "_XOPEN_SOURCE=600")
+    add_headerfiles("(include/uv-sunos.h)")
+end
+```
+
+然后,我们就可以切换这些平台来编译:
+
+```bash
+$ xmake f -p [dragonfly|freebsd|netbsd|openbsd|sunos] --sdk=/home/arm-xxx-gcc/
+$ xmake
+```
+
+另外,内置的linux平台也是支持交叉编译的哦,如果不想配置其他平台名,统一作为linux平台来交叉编译,也是可以的。
+
+```bash
+$ xmake f -p linux --sdk=/usr/local/arm-xxx-gcc/
+$ xmake
+```
+
+只要设置了`--sdk=`等参数,就会启用linux平台的交叉编译模式。
+
+## 常用工具链配置
+
+完整的工具链列表,请执行下面的命令查看:
+
+```bash
+$ xmake show -l toolchains
+```
+
+!> 此特性需要v2.3.4以上版本才支持
+
+上文讲述的是通用的交叉编译工具链配置,如果一些特定的工具链需要额外传入`--ldflags/--includedirs`等场景就比较繁琐了,
+因此xmake也内置了一些常用工具链,可以省去交叉编译工具链复杂的配置过程,只需要执行:
+
+```bash
+$ xmake f --toolchain=gnu-rm --sdk=/xxx/
+$ xmake
+```
+
+就可以快速切换的指定的交叉编译工具链,如果这个工具链需要追加一些特定的flags设置,也会自动设置好,简化配置。
+
+其中,gnu-rm就是内置的GNU Arm Embedded Toolchain。
+
+比如,我们也可以快速从gcc工具链整体切换到clang或者llvm工具链,不再需要`xmake f --cc=clang --cxx=clang --ld=clang++`等挨个配置了。
+
+```bash
+$ xmake f --toolchain=clang
+$ xmake
+```
+
+或者
+
+```bash
+$ xmake f --toolchain=llvm --sdk=/xxx/llvm
+$ xmake
+```
+
+具体xmake支持哪些工具链,可以通过下面的命令查看:
+
+```bash
+$ 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
+```
+
+### 自定义工具链
+
+另外,我们也可以在xmake.lua中自定义toolchain,然后通过`xmake f --toolchain=myclang`指定切换,例如:
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    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")
+
+    -- ...
+```
+
+关于这块的详情介绍,可以到[自定义工具链](/zh-cn/manual/custom_toolchain)章节查看
+
+更多详情见:[#780](https://github.com/xmake-io/xmake/issues/780)
+
+### MingW 工具链
+
+使用mingw工具链编译,其实也是交叉编译,但是由于这个比较常用,xmake专门增加了一个mingw的平台来快速处理使用mingw工具链的编译。
+
+因此,xmake对mingw的工具链检测会更加完善,在macos下,基本上连sdk路径都不需要配置,也能直接检测到,只需要切到mingw平台编译即可。
+
+```bash
+$ xmake f -p mingw
+$ xmake -v
+configure
+{
+    ld = /usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-g++
+    ndk_stdcxx = true
+    plat = mingw
+    mingw = /usr/local/opt/mingw-w64
+    buildir = build
+    arch = x86_64
+    xcode = /Applications/Xcode.app
+    mode = release
+    cxx = /usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-gcc
+    cross = x86_64-w64-mingw32-
+    theme = default
+    kind = static
+    ccache = true
+    host = macosx
+    clean = true
+    bin = /usr/local/opt/mingw-w64/bin
+}
+[  0%]: cache compiling.release src/main.cpp
+/usr/local/bin/ccache /usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-gcc -c -fvisibility=hidden -O3 -m64 -o build/.objs/test/mingw/x86_64/release/src/main.cpp.obj src/main.cpp
+[100%]: linking.release test.exe
+/usr/local/opt/mingw-w64/bin/x86_64-w64-mingw32-g++ -o build/mingw/x86_64/release/test.exe build/.objs/test/mingw/x86_64/release/src/main.cpp.obj -s -fvisibility=hidden -m64
+build ok!
+```
+
+这里我们追加了`-v`参数,看了下详细的编译命令和检测到的mingw工具链配置值,其中cross被自动检测为:`x86_64-w64-mingw32-`,bin目录也被自动检测到了,还有编译器和链接器也是。
+
+尽管在linux/win上还没法自动检测到sdk路径,我们也可以手动指定sdk路径,需要注意的是,xmake为mingw专门提供了一个`--mingw=`参数用来指定mingw的工具链根目录,其效果跟`--sdk=`是一样的,但是它可以作为全局配置被设置。
+
+```bash
+$ xmake g --mingw=/home/mingwsdk
+$ xmake f -p mingw
+$ xmake
+```
+
+我们通过`xmake g/global`命令设置`--mingw`根目录到全局配置后,之后每次编译和切换编译平台,就不用额外指定mingw工具链路径了,方便使用。
+
+另外,其他的工具链配置参数用法,跟上文描述的没什么区别,像`--cross`, `--bin=`等都可以根据实际的环境需要,自己控制是否需要额外追加配置来适配自己的mingw工具链。
+
+xmake 还支持 llvm-mingw 工具链,可以切换到 arm/arm64 架构来编译。
+
+```bash
+$ xmake f --mingw=/xxx/llvm-mingw -a arm64
+$ xmake
+```
+
+### LLVM 工具链
+
+llvm工具链下载地址:https://releases.llvm.org/
+
+```bash
+$ xmake f -p cross --toolchain=llvm --sdk="C:\Program Files\LLVM"
+$ xmake
+```
+
+### GNU-RM 工具链
+
+工具链地址:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads#
+
+```bash
+$ xmake f -p cross --toolchain=gnu-rm --sdk=/xxx/cc-arm-none-eabi-9-2019-q4-major
+$ xmake
+```
+
+### TinyC 工具链
+
+```bash
+$ xmake f --toolchain=tinyc
+$ xmake
+```
+
+!> Releases目录下,我们还提供了特殊的 xmake-tinyc-vX.X.X.win32.exe 安装包,内置tinyc工具链,无需依赖msvc,也可以编译c代码,开箱即用无依赖。
+
+### Emcc 工具链
+
+通常只需要切换到 Wasm 平台,里面内置了 emcc 工具链,还会额外调整目标程序的扩展名为 `*.html` 以及输出 `*.wasm`。
+
+```bash
+$ xmake f -p wasm
+$ xmake
+```
+
+不过我们也能够直接切换到 emcc 工具链,但是后缀名不会被修改。
+
+```bash
+$ xmake f --toolchain=emcc
+$ xmake
+```
+
+### Intel C++ 编译工具链
+
+```bash
+$ xmake f --toolchain=icc
+$ xmake
+```
+
+### Intel Fortran 编译工具链
+
+```bash
+$ xmake f --toolchain=ifort
+$ xmake
+```
+
+## 通用交叉编译配置
+
+| 参数名                       | 描述                             |
+| ---------------------------- | -------------------------------- |
+| [--sdk](#-sdk)               | 设置交叉工具链的sdk根目录        |
+| [--bin](#-bin)               | 设置工具链bin目录                |
+| [--cross](#-cross)           | 设置交叉工具链工具前缀           |
+| [--as](#-as)                 | 设置`asm`汇编器                  |
+| [--cc](#-cc)                 | 设置`c`编译器                    |
+| [--cxx](#-cxx)               | 设置`c++`编译器                  |
+| [--mm](#-mm)                 | 设置`objc`编译器                 |
+| [--mxx](#-mxx)               | 设置`objc++`编译器               |
+| [--sc](#-sc)                 | 设置`swift`编译器                |
+| [--gc](#-gc)                 | 设置`golang`编译器               |
+| [--dc](#-dc)                 | 设置`dlang`编译器                |
+| [--rc](#-rc)                 | 设置`rust`编译器                 |
+| [--cu](#-cu)                 | 设置`cuda`编译器                 |
+| [--ld](#-ld)                 | 设置`c/c++/objc/asm`链接器       |
+| [--sh](#-sh)                 | 设置`c/c++/objc/asm`共享库链接器 |
+| [--ar](#-ar)                 | 设置`c/c++/objc/asm`静态库归档器 |
+| [--scld](#-scld)             | 设置`swift`链接器                |
+| [--scsh](#-scsh)             | 设置`swift`共享库链接器          |
+| [--gcld](#-gcld)             | 设置`golang`链接器               |
+| [--gcar](#-gcar)             | 设置`golang`静态库归档器         |
+| [--dcld](#-dcld)             | 设置`dlang`链接器                |
+| [--dcsh](#-dcsh)             | 设置`dlang`共享库链接器          |
+| [--dcar](#-dcar)             | 设置`dlang`静态库归档器          |
+| [--rcld](#-rcld)             | 设置`rust`链接器                 |
+| [--rcsh](#-rcsh)             | 设置`rust`共享库链接器           |
+| [--rcar](#-rcar)             | 设置`rust`静态库归档器           |
+| [--cu-ccbin](#-cu-ccbin)     | 设置`cuda` host编译器            |
+| [--culd](#-culd)             | 设置`cuda`链接器                 |
+| [--asflags](#-asflags)       | 设置`asm`汇编编译选项            |
+| [--cflags](#-cflags)         | 设置`c`编译选项                  |
+| [--cxflags](#-cxflags)       | 设置`c/c++`编译选项              |
+| [--cxxflags](#-cxxflags)     | 设置`c++`编译选项                |
+| [--mflags](#-mflags)         | 设置`objc`编译选项               |
+| [--mxflags](#-mxflags)       | 设置`objc/c++`编译选项           |
+| [--mxxflags](#-mxxflags)     | 设置`objc++`编译选项             |
+| [--scflags](#-scflags)       | 设置`swift`编译选项              |
+| [--gcflags](#-gcflags)       | 设置`golang`编译选项             |
+| [--dcflags](#-dcflags)       | 设置`dlang`编译选项              |
+| [--rcflags](#-rcflags)       | 设置`rust`编译选项               |
+| [--cuflags](#-cuflags)       | 设置`cuda`编译选项               |
+| [--ldflags](#-ldflags)       | 设置链接选项                     |
+| [--shflags](#-shflags)       | 设置共享库链接选项               |
+| [--arflags](#-arflags)       | 设置静态库归档选项               |
+
+::: tip 注意
+如果你想要了解更多参数选项,请运行: `xmake f --help`。
+:::
+
+### --sdk
+
+- 设置交叉工具链的sdk根目录
+
+大部分情况下,都不需要配置很复杂的toolchains前缀,例如:`arm-linux-` 什么的
+
+只要这个工具链的sdk目录满足如下结构(大部分的交叉工具链都是这个结构):
+
+```
+/home/toolchains_sdkdir
+   - bin
+       - arm-linux-gcc
+       - arm-linux-ld
+       - ...
+   - lib
+       - libxxx.a
+   - include
+       - xxx.h
+```
+
+那么,使用xmake进行交叉编译的时候,只需要进行如下配置和编译:
+
+```bash
+$ xmake f -p linux --sdk=/home/toolchains_sdkdir
+$ xmake
+```
+
+这个时候,xmake会去自动探测,gcc等编译器的前缀名:`arm-linux-`,并且编译的时候,也会自动加上`链接库`和`头文件`的搜索选项,例如:
+
+```
+-I/home/toolchains_sdkdir/include -L/home/toolchains_sdkdir/lib
+```
+
+这些都是xmake自动处理的,不需要手动配置他们。。
+
+### --bin
+
+- 设置工具链bin目录
+
+对于不规则工具链目录结构,靠单纯地[--sdk](#-sdk)选项设置,没法完全检测通过的情况下,可以通过这个选项继续附加设置工具链的bin目录位置。
+
+例如:一些特殊的交叉工具链的,编译器bin目录,并不在 `/home/toolchains_sdkdir/bin` 这个位置,而是独立到了 `/usr/opt/bin`
+
+```bash
+$ xmake f -p linux --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin
+$ xmake
+```
+
+::: tip 注意
+v2.2.1版本之前,这个参数名是`--toolchains`,比较有歧义,因此新版本中,统一改成`--bin=`来设置bin目录。
+:::
+
+### --cross
+
+- 设置交叉工具链工具前缀
+
+像`aarch64-linux-android-`这种,通常如果你配置了[--sdk](#-sdk)或者[--bin](#-bin)的情况下,xmake会去自动检测的,不需要自己手动设置。
+
+但是对于一些极特殊的工具链,一个目录下同时有多个cross前缀的工具bin混在一起的情况,你需要手动设置这个配置,来区分到底需要选用哪个bin。
+
+例如,toolchains的bin目录下同时存在两个不同的编译器:
+
+```
+/opt/bin
+ - armv7-linux-gcc
+ - aarch64-linux-gcc
+```
+
+我们现在想要选用armv7的版本,则配置如下:
+
+```bash
+$ xmake f -p linux --sdk=/usr/toolsdk --bin=/opt/bin --cross=armv7-linux-
+```
+
+### --as
+
+- 设置`asm`汇编器
+
+如果还要继续细分选择编译器,则继续追加相关编译器选项,例如:
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --as=armv7-linux-as
+```
+
+如果存在`AS`环境变量的话,会优先使用当前环境变量中指定的值。
+
+::: tip 注意
+如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。
+这个时候我们可以通过:`xmake f --as=gcc@/home/xxx/asmips.exe` 设置ccmips.exe编译器作为类gcc的使用方式来编译。
+也就是说,在指定编译器为`asmips.exe`的同时,告诉xmake,它跟gcc用法和参数选项基本相同。
+:::
+
+### --cc
+
+- 设置c编译器
+
+如果还要继续细分选择编译器,则继续追加相关编译器选项,例如:
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --cc=armv7-linux-clang
+```
+
+如果存在`CC`环境变量的话,会优先使用当前环境变量中指定的值。
+
+::: tip 注意
+如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。
+这个时候我们可以通过:`xmake f --cc=gcc@/home/xxx/ccmips.exe` 设置ccmips.exe编译器作为类gcc的使用方式来编译。
+也就是说,在指定编译器为`ccmips.exe`的同时,告诉xmake,它跟gcc用法和参数选项基本相同。
+:::
+
+### --cxx
+
+- 设置`c++`编译器
+
+如果还要继续细分选择编译器,则继续追加相关编译器选项,例如:
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --cxx=armv7-linux-clang++
+```
+
+如果存在`CXX`环境变量的话,会优先使用当前环境变量中指定的值。
+
+::: tip 注意
+如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。
+这个时候我们可以通过:`xmake f --cxx=clang++@/home/xxx/c++mips.exe` 设置c++mips.exe编译器作为类clang++的使用方式来编译。
+也就是说,在指定编译器为`c++mips.exe`的同时,告诉xmake,它跟clang++用法和参数选项基本相同。
+:::
+
+### --ld
+
+- 设置`c/c++/objc/asm`链接器
+
+如果还要继续细分选择链接器,则继续追加相关编译器选项,例如:
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --ld=armv7-linux-clang++
+```
+
+如果存在`LD`环境变量的话,会优先使用当前环境变量中指定的值。
+
+::: tip 注意
+如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么链接器工具检测就会失败。
+这个时候我们可以通过:`xmake f --ld=g++@/home/xxx/c++mips.exe` 设置c++mips.exe链接器作为类g++的使用方式来编译。
+也就是说,在指定链接器为`c++mips.exe`的同时,告诉xmake,它跟g++用法和参数选项基本相同。
+:::
+
+### --sh
+
+- 设置`c/c++/objc/asm`共享库链接器
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --sh=armv7-linux-clang++
+```
+
+如果存在`SH`环境变量的话,会优先使用当前环境变量中指定的值。
+
+::: tip 注意
+如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么链接器工具检测就会失败。
+这个时候我们可以通过:`xmake f --sh=g++@/home/xxx/c++mips.exe` 设置c++mips.exe链接器作为类g++的使用方式来编译。
+也就是说,在指定链接器为`c++mips.exe`的同时,告诉xmake,它跟g++用法和参数选项基本相同。
+:::
+
+### --ar
+
+- 设置`c/c++/objc/asm`静态库归档器
+
+```bash
+$ xmake f -p linux --sdk=/user/toolsdk --ar=armv7-linux-ar
+```
+
+如果存在`AR`环境变量的话,会优先使用当前环境变量中指定的值。
+
+::: tip 注意
+如果指定的编译器名不是那些xmake内置可识别的名字(带有ar等字样),那么链接器工具检测就会失败。
+这个时候我们可以通过:`xmake f --ar=ar@/home/xxx/armips.exe` 设置armips.exe链接器作为类ar的使用方式来编译。
+也就是说,在指定链接器为`armips.exe`的同时,告诉xmake,它跟ar用法和参数选项基本相同。
+:::