From 42066f46af45364f429a8ab4abd6f2ed3c9cbff1 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 27 Jul 2019 00:17:29 +0800 Subject: update package sidebar --- _sidebar.md | 7 +- guide/package_management.md | 490 ------------------------------------ package/local_package.md | 46 ++++ package/remote_package.md | 367 +++++++++++++++++++++++++++ package/system_package.md | 73 ++++++ zh-cn/_sidebar.md | 7 +- zh-cn/guide/package_management.md | 518 -------------------------------------- zh-cn/package/local_package.md | 46 ++++ zh-cn/package/remote_package.md | 395 +++++++++++++++++++++++++++++ zh-cn/package/system_package.md | 73 ++++++ 10 files changed, 1012 insertions(+), 1010 deletions(-) delete mode 100644 guide/package_management.md create mode 100644 package/local_package.md create mode 100644 package/remote_package.md create mode 100644 package/system_package.md delete mode 100644 zh-cn/guide/package_management.md create mode 100644 zh-cn/package/local_package.md create mode 100644 zh-cn/package/remote_package.md create mode 100644 zh-cn/package/system_package.md diff --git a/_sidebar.md b/_sidebar.md index 063cc731..8a361d33 100644 --- a/_sidebar.md +++ b/_sidebar.md @@ -13,9 +13,14 @@ - [Project Examples](guide/project_examples.md) - [Configuration](guide/configuration.md) - [Syntax Description](guide/syntax_description.md) - - [Package Management](guide/package_management.md) - [FAQ](guide/faq.md) +- Package Management + + - [Local Package](package/local_package.md) + - [System Package](package/system_package.md) + - [Remote Package](package/remote_package.md) + - Plugin - [Plugin Development](plugin/plugin_development.md) diff --git a/guide/package_management.md b/guide/package_management.md deleted file mode 100644 index e5f003eb..00000000 --- a/guide/package_management.md +++ /dev/null @@ -1,490 +0,0 @@ - -## Local Package Mode - -By including a dependency package directory and some binary library files in the project, it is convenient to integrate some third-party dependency libraries. This method is relatively simple and straightforward, but the disadvantages are also obvious and inconvenient to manage. - -Take the tbox project as an example. The dependency package is as follows: - -``` -- base.pkg -- zlib.pkg -- polarssl.pkg -- openssl.pkg -- mysql.pkg -- pcre.pkg -- ... -``` - -If you want the current project to recognize loading these packages, you first need to specify the package directory path, for example: - -```lua -add_packagedirs("packages") -``` - -Once specified, you can add integration package dependencies in the target scope via the [add_packages](/manual/project_target?id=targetadd_packages) interface, for example: - -```lua -target("tbox") -    add_packages("zlib", "polarssl", "pcre", "mysql") -``` - -So how to generate a *.pkg package, if it is based on xmake project, the generation method is very simple, only need: - -```console -$ cd tbox -$ xmake package -``` - -You can generate a tbox.pkg cross-platform package in the build directory for use by third-party projects. I can also directly set the output directory and compile and generate it into the other project, for example: - -```console -$ cd tbox -$ xmake package -o ../test/packages -``` - -In this way, the test project can pass [add_packages](/manual/project_target?id=targetadd_packages) and [add_packagedirs](/manual/global_interfaces?id=add_packagedirs) to configure and use the tbox.pkg package. - -For a detailed description of the built-in package, you can also refer to the following related article, which is described in detail: [Dependency package addition and automatic detection mechanism](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) - -## System Search Mode - -If you feel that the above built-in package management method is very inconvenient, you can use the extension interface [lib.detect.find_package](/manual/extension_modules?id=detectfind_package) to find the system. Existing dependencies. - -Currently this interface supports the following package management support: - -* vcpkg -* homebrew -* pkg-config - -And through the system and third-party package management tools for the installation of the dependency package, and then integrated with xmake, for example, we look for an openssl package: - -```lua -local packages = find_packages("openssl", "zlib") -``` - -The returned results are as follows: - -```lua -{ - {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, - {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -} -``` - -If the search is successful, return a table containing all the package information, if it fails, return nil - -The return result here can be directly passed as the parameter of `target:add`, `option:add`, which is used to dynamically increase the configuration of `target/option`: - -```lua -option("zlib") -    set_showmenu(true) -    before_check(function (option) -        option:add(find_packages("openssl", "zlib")) -    end) -``` - -```lua -target("test") -    on_load(function (target) -        target:add(find_packages("openssl", "zlib")) -    end) -``` - -If third-party tools such as `homebrew`, `pkg-config` are installed on the system, then this interface will try to use them to improve the search results. - -Another, we can also find packages from the given package manager. For example: - -```lua -find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") -``` - -For a more complete description of the usage, please refer to the [find_packages](/manual/builtin_modules?id=find_packages) interface documentation. - -### Homebrew Integration Support - -Since homebrew is generally installed directly into the system, users do not need to do any integration work, `lib.detect.find_package` has been natively seamlessly supported. - -### Vcpkg Integration Support - -Currently xmake v2.2.2 version already supports vcpkg, users only need to install vcpkg, execute `$ vcpkg integrate install`, xmake will automatically detect the root path of vcpkg from the system, and then automatically adapt the bread. - -Of course, we can also manually specify the root path of vcpkg to support: - -```console -$ xmake f --vcpkg=f:\vcpkg -``` - -Or we can set it to the global configuration to avoid repeating the settings each time we switch configurations: - -```console -$ xmake g --vcpkg=f:\vcpkg -``` - -## Remote dependency mode - -This has been initially supported after the 2.2.2 version, the usage is much simpler, just set the corresponding dependency package, for example: - -```lua -add_requires("tbox 1.6.*", "libpng ~1.16", "zlib") - -target("test") -    set_kind("binary") -    add_files("src/*.c") -    add_packages("tbox", "libpng", "zlib") -``` - -The above `add_requires` is used to describe the dependencies required by the current project, and `add_packages` is used to apply dependencies to the test target. Only settings will automatically add links, linkdirs, includedirs, etc. - -Then directly compile: - -```console -$ xmake -``` - -xmake will remotely pull the relevant source package, then automatically compile and install, finally compile the project, and link the dependency package. The specific effect is shown in the following figure: - - - -For more information and progress on package dependency management see the related issues: [Remote package management](https://github.com/xmake-io/xmake/issues/69) - -### Currently Supported Features - -* Semantic version support, for example: ">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" -* Provide multi-repository management support such as official package repository, self-built private repository, project built-in repository, etc. -* Cross-platform package compilation integration support (packages of different platforms and different architectures can be installed at the same time, fast switching use) -* Debug dependency package support, source code debugging - -### Dependency Package Processing Mechanism - -Here we briefly introduce the processing mechanism of the entire dependency package: - -
- -
- -1. Priority check for the current system directory, whether there is a specified package under the third-party package management, if there is a matching package, then you do not need to download and install (of course you can also set the system package) -2. Retrieve the package matching the corresponding version, then download, compile, and install (Note: installed in a specific xmake directory, will not interfere with the system library environment) -3. Compile the project, and finally automatically link the enabled dependencies - -### Semantic Version Settings - -Xmake's dependency package management fully supports semantic version selection, for example: "~1.6.1". For a detailed description of the semantic version, see: [https://semver.org/](https://semver.org/) - -Some semantic versions are written: - -```lua -add_requires("tbox 1.6.*", "pcre 1.3.x", "libpng ^1.18") -add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0") -``` - -The semantic version parser currently used by xmake is the [sv](https://github.com/uael/sv) library contributed by [uael](https://github.com/uael), which also has a description of the version. For detailed instructions, please refer to the following: [Version Description](https://github.com/uael/sv#versions) - -Of course, if we have no special requirements for the current version of the dependency package, then we can write directly: - -```lua -add_requires("tbox", "libpng", "zlib") -``` - -This will use the latest version of the package known, or the source code compiled by the master branch. If the current package has a git repo address, we can also specify a specific branch version: - -```lua -add_requires("tbox master") -add_requires("tbox dev") -``` - -### Extra Package Information Settings - -#### Optional Package Settings - -If the specified dependency package is not supported by the current platform, or if the compilation and installation fails, then xmake will compile the error, which is reasonable for some projects that must rely on certain packages to work. -However, if some packages are optional dependencies, they can be set to optional packages even if they are not compiled properly. - -```lua -add_requires("tbox", {optional = true}) -``` - -#### Disable System Library - -With the default settings, xmake will first check to see if the system library exists (if no version is required). If the user does not want to use the system library and the library provided by the third-party package management, then you can set: - -```lua -add_requires("tbox", {system = false}) -``` - -#### Using the debug version of the package - -If we want to debug the dependencies at the same time, we can set them to use the debug version of the package (provided that this package supports debug compilation): - -```lua -add_requires("tbox", {debug = true}) -``` - -If the current package does not support debug compilation, you can submit the modified compilation rules in the repository to support the debug, for example: - -```lua -package("openssl") -    on_install("linux", "macosx", function (package) -        os.vrun("./config %s --prefix=\"%s\"", package:debug() and "--debug" or "", package:installdir()) -        os.vrun("make -j4") -        os.vrun("make install") -    end) -``` - -#### Passing additional compilation information to the package - -Some packages have various compile options at compile time, and we can pass them in. Of course, the package itself supports: - -```lua -add_requires("tbox", {configs = {small=true}}) -``` - -Pass `--small=true` to the tbox package so that compiling the installed tbox package is enabled. - -### Install third-party packages - -After version 2.2.5, xmake supports support for dependency libraries in third-party package managers, such as: conan, brew, vcpkg, clib and etc. - -#### Add a homebrew dependency package - -```lua -add_requires("brew::zlib", {alias = "zlib"}}) -add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("pcre2", "zlib") -``` - -#### Add a vcpkg dependency package - -```lua -add_requires("vcpkg::zlib", "vcpkg::pcre2") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("vcpkg::zlib", "vcpkg::pcre2") -``` - -#### Add a conan dependency package - -```lua -add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) -add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", - configs = {options = "OpenSSL:shared=True"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("openssl", "zlib") -``` - -After executing xmake to compile: - -```console -ruki:test_package ruki$ xmake -checking for the architecture ... x86_64 -checking for the Xcode directory ... /Applications/Xcode.app -checking for the SDK version of Xcode ... 10.14 -note: try installing these packages (pass -y to skip confirm)? - -> CONAN::zlib/1.2.11@conan/stable (debug) - -> CONAN::OpenSSL/1.0.2n@conan/stable -please input: y (y/n) - - => installing CONAN::zlib/1.2.11@conan/stable .. ok - => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok - -[ 0%]: ccache compiling.release src/main.c -[100%]: linking.release test -``` - -#### Add a clib dependency package - -Clib is a source-based dependency package manager. The dependent package is downloaded directly to the corresponding library source code, integrated into the project to compile, rather than binary library dependencies. - -It is also very convenient to integrate in xmake. The only thing to note is that you need to add the source code of the corresponding library to xmake.lua, for example: - -```lua -add_requires("clib::clibs/bytes@0.0.4", {alias = "bytes"}) - -target("test") - set_kind("binary") - add_files("clib/bytes/*.c") - add_files("src/*.c") - add_packages("bytes") -``` - -### Using self-built private package repository - -If the required package is not in the official repository [xmake-repo](https://github.com/xmake-io/xmake-repo), we can submit the contribution code to the repository for support. -But if some packages are only for personal or private projects, we can create a private repository repo. The repository organization structure can be found at: [xmake-repo](https://github.com/xmake-io/xmake-repo) - -For example, now we have a private repository repo:`git@github.com:myrepo/xmake-repo.git` - -We can add the repository with the following command: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -Starting with v2.2.3, support for adding repos for specified branches, for example: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git dev -``` - -Or we write directly in xmake.lua: - -```lua -add_repositories("my-repo git@github.com:myrepo/xmake-repo.git") -``` - -If we just want to add one or two private packages, this time to build a git repo is too big, we can directly put the package repository into the project, for example: - -``` -projectdir -  - myrepo -    - packages -      - t/tbox/xmake.lua -      - z/zlib/xmake.lua -  - src -    - main.c -  - xmake.lua -``` - -The above myrepo directory is your own private package repository, built into your own project, and then add this repository location in xmake.lua: - -```lua -add_repositories("my-repo myrepo") -``` - -This can be referred to [benchbox](https://github.com/tboox/benchbox) project, which has a built-in private repository. - -We can even build a package without directly building a package description into the project xmake.lua, which is useful for relying on one or two packages, for example: - -```lua -package("libjpeg") - -    set_urls("http://www.ijg.org/files/jpegsrc.$(version).tar.gz") - -    add_versions("v9c", "650250979303a649e21f87b5ccd02672af1ea6954b911342ea491f351ceb7122") - -    on_install("windows", function (package) -        os.mv("jconfig.vc", "jconfig.h") -        os.vrun("nmake -f makefile.vc") -        os.cp("*.h", package:installdir("include")) -        os.cp("libjpeg.lib", package:installdir("lib")) -    end) - -    on_install("macosx", "linux", function (package) -        import("package.tools.autoconf").install(package) -    end) - -package_end() - -add_requires("libjpeg") - -target("test") -    set_kind("binary") -    add_files("src/*.c") -    add_packages("libjpeg") -``` - -### Package Management Command - -The package management command `$ xmake require` can be used to manually display the download, install, uninstall, retrieve, and view package information. - -#### Install the specified package - -```console -$ xmake require tbox -``` - -Install the specified version package: - -```console -$ xmake require tbox "~1.6" -``` - -Force a re-download of the installation and display detailed installation information: - -```console -$ xmake require -f -v tbox "1.5.x" -``` - -Pass additional setup information: - -```console -$ xmake require --extra="debug=true,config={small=true}" tbox -``` - -Install the debug package and pass the compilation configuration information of `small=true` to the package. - -#### Uninstall the specified package - -```console -$ xmake require --uninstall tbox -``` - -This will completely uninstall the removal package file. - -#### Show package information - -```console -$ xmake require --info tbox -``` - -#### Search for packages in the current repository - -```console -$ xmake require --search tbox -``` - -This is to support fuzzy search and lua pattern matching search: - -```console -$ xmake require --search pcr -``` - -Will also search for pcre, pcre2 and other packages. - -#### List the currently installed packages - -```console -$ xmake require --list -``` - -### Repository Management Command - -As mentioned above, adding a private repository is available (supporting local path addition): - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -We can also remove a repository that has already been installed: - -```console -$ xmake repo --remove myrepo -``` - -Or view all the added repositories: - -```console -$ xmake repo --list -``` - -If the remote repository has updates, you can manually perform a repository update to get more and the latest packages: - -```console -$ xmake repo -u -``` - -### Submit package to the official repository - -If you need a package that is not supported by the current official repository, you can commit it to the official repository after local tuning: [xmake-repo](https://github.com/xmake-io/xmake-repo) - -For detailed contribution descriptions, see: [CONTRIBUTING.md](https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md) - - diff --git a/package/local_package.md b/package/local_package.md new file mode 100644 index 00000000..f84f8264 --- /dev/null +++ b/package/local_package.md @@ -0,0 +1,46 @@ + +By including a dependency package directory and some binary library files in the project, it is convenient to integrate some third-party dependency libraries. This method is relatively simple and straightforward, but the disadvantages are also obvious and inconvenient to manage. + +Take the tbox project as an example. The dependency package is as follows: + +``` +- base.pkg +- zlib.pkg +- polarssl.pkg +- openssl.pkg +- mysql.pkg +- pcre.pkg +- ... +``` + +If you want the current project to recognize loading these packages, you first need to specify the package directory path, for example: + +```lua +add_packagedirs("packages") +``` + +Once specified, you can add integration package dependencies in the target scope via the [add_packages](/manual/project_target?id=targetadd_packages) interface, for example: + +```lua +target("tbox") +    add_packages("zlib", "polarssl", "pcre", "mysql") +``` + +So how to generate a *.pkg package, if it is based on xmake project, the generation method is very simple, only need: + +```console +$ cd tbox +$ xmake package +``` + +You can generate a tbox.pkg cross-platform package in the build directory for use by third-party projects. I can also directly set the output directory and compile and generate it into the other project, for example: + +```console +$ cd tbox +$ xmake package -o ../test/packages +``` + +In this way, the test project can pass [add_packages](/manual/project_target?id=targetadd_packages) and [add_packagedirs](/manual/global_interfaces?id=add_packagedirs) to configure and use the tbox.pkg package. + +For a detailed description of the built-in package, you can also refer to the following related article, which is described in detail: [Dependency package addition and automatic detection mechanism](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) + diff --git a/package/remote_package.md b/package/remote_package.md new file mode 100644 index 00000000..5bb180fa --- /dev/null +++ b/package/remote_package.md @@ -0,0 +1,367 @@ + +This has been initially supported after the 2.2.2 version, the usage is much simpler, just set the corresponding dependency package, for example: + +```lua +add_requires("tbox 1.6.*", "libpng ~1.16", "zlib") + +target("test") +    set_kind("binary") +    add_files("src/*.c") +    add_packages("tbox", "libpng", "zlib") +``` + +The above `add_requires` is used to describe the dependencies required by the current project, and `add_packages` is used to apply dependencies to the test target. Only settings will automatically add links, linkdirs, includedirs, etc. + +Then directly compile: + +```console +$ xmake +``` + +xmake will remotely pull the relevant source package, then automatically compile and install, finally compile the project, and link the dependency package. The specific effect is shown in the following figure: + + + +For more information and progress on package dependency management see the related issues: [Remote package management](https://github.com/xmake-io/xmake/issues/69) + +## Currently Supported Features + +* Semantic version support, for example: ">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" +* Provide multi-repository management support such as official package repository, self-built private repository, project built-in repository, etc. +* Cross-platform package compilation integration support (packages of different platforms and different architectures can be installed at the same time, fast switching use) +* Debug dependency package support, source code debugging + +## Dependency Package Processing Mechanism + +Here we briefly introduce the processing mechanism of the entire dependency package: + +
+ +
+ +1. Priority check for the current system directory, whether there is a specified package under the third-party package management, if there is a matching package, then you do not need to download and install (of course you can also set the system package) +2. Retrieve the package matching the corresponding version, then download, compile, and install (Note: installed in a specific xmake directory, will not interfere with the system library environment) +3. Compile the project, and finally automatically link the enabled dependencies + +## Semantic Version Settings + +Xmake's dependency package management fully supports semantic version selection, for example: "~1.6.1". For a detailed description of the semantic version, see: [https://semver.org/](https://semver.org/) + +Some semantic versions are written: + +```lua +add_requires("tbox 1.6.*", "pcre 1.3.x", "libpng ^1.18") +add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0") +``` + +The semantic version parser currently used by xmake is the [sv](https://github.com/uael/sv) library contributed by [uael](https://github.com/uael), which also has a description of the version. For detailed instructions, please refer to the following: [Version Description](https://github.com/uael/sv#versions) + +Of course, if we have no special requirements for the current version of the dependency package, then we can write directly: + +```lua +add_requires("tbox", "libpng", "zlib") +``` + +This will use the latest version of the package known, or the source code compiled by the master branch. If the current package has a git repo address, we can also specify a specific branch version: + +```lua +add_requires("tbox master") +add_requires("tbox dev") +``` + +## Extra Package Information Settings + +### Optional Package Settings + +If the specified dependency package is not supported by the current platform, or if the compilation and installation fails, then xmake will compile the error, which is reasonable for some projects that must rely on certain packages to work. +However, if some packages are optional dependencies, they can be set to optional packages even if they are not compiled properly. + +```lua +add_requires("tbox", {optional = true}) +``` + +### Disable System Library + +With the default settings, xmake will first check to see if the system library exists (if no version is required). If the user does not want to use the system library and the library provided by the third-party package management, then you can set: + +```lua +add_requires("tbox", {system = false}) +``` + +### Using the debug version of the package + +If we want to debug the dependencies at the same time, we can set them to use the debug version of the package (provided that this package supports debug compilation): + +```lua +add_requires("tbox", {debug = true}) +``` + +If the current package does not support debug compilation, you can submit the modified compilation rules in the repository to support the debug, for example: + +```lua +package("openssl") +    on_install("linux", "macosx", function (package) +        os.vrun("./config %s --prefix=\"%s\"", package:debug() and "--debug" or "", package:installdir()) +        os.vrun("make -j4") +        os.vrun("make install") +    end) +``` + +### Passing additional compilation information to the package + +Some packages have various compile options at compile time, and we can pass them in. Of course, the package itself supports: + +```lua +add_requires("tbox", {configs = {small=true}}) +``` + +Pass `--small=true` to the tbox package so that compiling the installed tbox package is enabled. + +## Install third-party packages + +After version 2.2.5, xmake supports support for dependency libraries in third-party package managers, such as: conan, brew, vcpkg, clib and etc. + +### Add a homebrew dependency package + +```lua +add_requires("brew::zlib", {alias = "zlib"}}) +add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("pcre2", "zlib") +``` + +### Add a vcpkg dependency package + +```lua +add_requires("vcpkg::zlib", "vcpkg::pcre2") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("vcpkg::zlib", "vcpkg::pcre2") +``` + +### Add a conan dependency package + +```lua +add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) +add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", + configs = {options = "OpenSSL:shared=True"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("openssl", "zlib") +``` + +After executing xmake to compile: + +```console +ruki:test_package ruki$ xmake +checking for the architecture ... x86_64 +checking for the Xcode directory ... /Applications/Xcode.app +checking for the SDK version of Xcode ... 10.14 +note: try installing these packages (pass -y to skip confirm)? + -> CONAN::zlib/1.2.11@conan/stable (debug) + -> CONAN::OpenSSL/1.0.2n@conan/stable +please input: y (y/n) + + => installing CONAN::zlib/1.2.11@conan/stable .. ok + => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok + +[ 0%]: ccache compiling.release src/main.c +[100%]: linking.release test +``` + +### Add a clib dependency package + +Clib is a source-based dependency package manager. The dependent package is downloaded directly to the corresponding library source code, integrated into the project to compile, rather than binary library dependencies. + +It is also very convenient to integrate in xmake. The only thing to note is that you need to add the source code of the corresponding library to xmake.lua, for example: + +```lua +add_requires("clib::clibs/bytes@0.0.4", {alias = "bytes"}) + +target("test") + set_kind("binary") + add_files("clib/bytes/*.c") + add_files("src/*.c") + add_packages("bytes") +``` + +## Using self-built private package repository + +If the required package is not in the official repository [xmake-repo](https://github.com/xmake-io/xmake-repo), we can submit the contribution code to the repository for support. +But if some packages are only for personal or private projects, we can create a private repository repo. The repository organization structure can be found at: [xmake-repo](https://github.com/xmake-io/xmake-repo) + +For example, now we have a private repository repo:`git@github.com:myrepo/xmake-repo.git` + +We can add the repository with the following command: + +```console +$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git +``` + +Starting with v2.2.3, support for adding repos for specified branches, for example: + +```console +$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git dev +``` + +Or we write directly in xmake.lua: + +```lua +add_repositories("my-repo git@github.com:myrepo/xmake-repo.git") +``` + +If we just want to add one or two private packages, this time to build a git repo is too big, we can directly put the package repository into the project, for example: + +``` +projectdir +  - myrepo +    - packages +      - t/tbox/xmake.lua +      - z/zlib/xmake.lua +  - src +    - main.c +  - xmake.lua +``` + +The above myrepo directory is your own private package repository, built into your own project, and then add this repository location in xmake.lua: + +```lua +add_repositories("my-repo myrepo") +``` + +This can be referred to [benchbox](https://github.com/tboox/benchbox) project, which has a built-in private repository. + +We can even build a package without directly building a package description into the project xmake.lua, which is useful for relying on one or two packages, for example: + +```lua +package("libjpeg") + +    set_urls("http://www.ijg.org/files/jpegsrc.$(version).tar.gz") + +    add_versions("v9c", "650250979303a649e21f87b5ccd02672af1ea6954b911342ea491f351ceb7122") + +    on_install("windows", function (package) +        os.mv("jconfig.vc", "jconfig.h") +        os.vrun("nmake -f makefile.vc") +        os.cp("*.h", package:installdir("include")) +        os.cp("libjpeg.lib", package:installdir("lib")) +    end) + +    on_install("macosx", "linux", function (package) +        import("package.tools.autoconf").install(package) +    end) + +package_end() + +add_requires("libjpeg") + +target("test") +    set_kind("binary") +    add_files("src/*.c") +    add_packages("libjpeg") +``` + +## Package Management Command + +The package management command `$ xmake require` can be used to manually display the download, install, uninstall, retrieve, and view package information. + +### Install the specified package + +```console +$ xmake require tbox +``` + +Install the specified version package: + +```console +$ xmake require tbox "~1.6" +``` + +Force a re-download of the installation and display detailed installation information: + +```console +$ xmake require -f -v tbox "1.5.x" +``` + +Pass additional setup information: + +```console +$ xmake require --extra="debug=true,config={small=true}" tbox +``` + +Install the debug package and pass the compilation configuration information of `small=true` to the package. + +### Uninstall the specified package + +```console +$ xmake require --uninstall tbox +``` + +This will completely uninstall the removal package file. + +### Show package information + +```console +$ xmake require --info tbox +``` + +### Search for packages in the current repository + +```console +$ xmake require --search tbox +``` + +This is to support fuzzy search and lua pattern matching search: + +```console +$ xmake require --search pcr +``` + +Will also search for pcre, pcre2 and other packages. + +### List the currently installed packages + +```console +$ xmake require --list +``` + +## Repository Management Command + +As mentioned above, adding a private repository is available (supporting local path addition): + +```console +$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git +``` + +We can also remove a repository that has already been installed: + +```console +$ xmake repo --remove myrepo +``` + +Or view all the added repositories: + +```console +$ xmake repo --list +``` + +If the remote repository has updates, you can manually perform a repository update to get more and the latest packages: + +```console +$ xmake repo -u +``` + +## Submit package to the official repository + +If you need a package that is not supported by the current official repository, you can commit it to the official repository after local tuning: [xmake-repo](https://github.com/xmake-io/xmake-repo) + +For detailed contribution descriptions, see: [CONTRIBUTING.md](https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md) + + diff --git a/package/system_package.md b/package/system_package.md new file mode 100644 index 00000000..a1650c73 --- /dev/null +++ b/package/system_package.md @@ -0,0 +1,73 @@ + +If you feel that the above built-in package management method is very inconvenient, you can use the extension interface [lib.detect.find_package](/manual/extension_modules?id=detectfind_package) to find the system. Existing dependencies. + +Currently this interface supports the following package management support: + +* vcpkg +* homebrew +* pkg-config + +And through the system and third-party package management tools for the installation of the dependency package, and then integrated with xmake, for example, we look for an openssl package: + +```lua +local packages = find_packages("openssl", "zlib") +``` + +The returned results are as follows: + +```lua +{ + {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, + {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +} +``` + +If the search is successful, return a table containing all the package information, if it fails, return nil + +The return result here can be directly passed as the parameter of `target:add`, `option:add`, which is used to dynamically increase the configuration of `target/option`: + +```lua +option("zlib") +    set_showmenu(true) +    before_check(function (option) +        option:add(find_packages("openssl", "zlib")) +    end) +``` + +```lua +target("test") +    on_load(function (target) +        target:add(find_packages("openssl", "zlib")) +    end) +``` + +If third-party tools such as `homebrew`, `pkg-config` are installed on the system, then this interface will try to use them to improve the search results. + +Another, we can also find packages from the given package manager. For example: + +```lua +find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") +``` + +For a more complete description of the usage, please refer to the [find_packages](/manual/builtin_modules?id=find_packages) interface documentation. + +## Homebrew Integration Support + +Since homebrew is generally installed directly into the system, users do not need to do any integration work, `lib.detect.find_package` has been natively seamlessly supported. + +## Vcpkg Integration Support + +Currently xmake v2.2.2 version already supports vcpkg, users only need to install vcpkg, execute `$ vcpkg integrate install`, xmake will automatically detect the root path of vcpkg from the system, and then automatically adapt the bread. + +Of course, we can also manually specify the root path of vcpkg to support: + +```console +$ xmake f --vcpkg=f:\vcpkg +``` + +Or we can set it to the global configuration to avoid repeating the settings each time we switch configurations: + +```console +$ xmake g --vcpkg=f:\vcpkg +``` + diff --git a/zh-cn/_sidebar.md b/zh-cn/_sidebar.md index f4b9cfe9..915e813d 100644 --- a/zh-cn/_sidebar.md +++ b/zh-cn/_sidebar.md @@ -13,9 +13,14 @@ - [工程例子](zh-cn/guide/project_examples.md) - [配置说明](zh-cn/guide/configuration.md) - [语法描述](zh-cn/guide/syntax_description.md) - - [包依赖管理](zh-cn/guide/package_management.md) - [问答](zh-cn/guide/faq.md) +- 包依赖管理 + + - [使用本地包](zh-cn/package/local_package.md) + - [使用系统包](zh-cn/package/system_package.md) + - [使用远程包](zh-cn/package/remote_package.md) + - 插件介绍 - [插件开发](zh-cn/plugin/plugin_development.md) diff --git a/zh-cn/guide/package_management.md b/zh-cn/guide/package_management.md deleted file mode 100644 index 0be1fdf1..00000000 --- a/zh-cn/guide/package_management.md +++ /dev/null @@ -1,518 +0,0 @@ - -## 本地内置模式 - -通过在项目中内置依赖包目录以及二进制包文件,可以方便的集成一些第三方的依赖库,这种方式比较简单直接,但是缺点也很明显,不方便管理。 - -以tbox工程为例,其依赖包如下: - -``` -- base.pkg -- zlib.pkg -- polarssl.pkg -- openssl.pkg -- mysql.pkg -- pcre.pkg -- ... -``` - -如果要让当前工程识别加载这些包,首先要指定包目录路径,例如: - -```lua -add_packagedirs("packages") -``` - -指定好后,就可以在target作用域中,通过[add_packages](/zh-cn/manual/project_target?id=targetadd_packages)接口,来添加集成包依赖了,例如: - -```lua -target("tbox") - add_packages("zlib", "polarssl", "pcre", "mysql") -``` - -那么如何去生成一个*.pkg的包呢,如果是基于xmake的工程,生成方式很简单,只需要: - -```console -$ cd tbox -$ xmake package -``` - -即可在build目录下生成一个tbox.pkg的跨平台包,给第三方项目使用,我也可以直接设置输出目录,编译生成到对方项目中去,例如: - -```console -$ cd tbox -$ xmake package -o ../test/packages -``` - -这样,test工程就可以通过[add_packages]((/zh-cn/manual/project_target?id=targetadd_packages)和[add_packagedirs](/zh-cn/manual/global_interfaces?id=add_packagedirs)去配置和使用tbox.pkg包了。 - -关于内置包的详细描述,还可以参考下相关文章,这里面有详细介绍:[依赖包的添加和自动检测机制](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) - -## 系统查找模式 - -如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。 - -目前此接口支持以下一些包管理支持: - -* vcpkg -* homebrew -* pkg-config - -并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包: - -```lua -local packages = find_packages("openssl", "zlib") -``` - -返回的结果如下: - -```lua -{ - {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, - {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -} -``` - -如果查找成功,则返回一个包含所有包信息的table,如果失败返回nil - -这里的返回结果可以直接作为`target:add`, `option:add`的参数传入,用于动态增加`target/option`的配置: - -```lua -option("zlib") - set_showmenu(true) - before_check(function (option) - option:add(find_packages("openssl", "zlib")) - end) -``` - -```lua -target("test") - on_load(function (target) - target:add(find_package("openssl", "zlib")) - end) -``` - -如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。 - -另外,我们也可以从指定的包管理器查找包: - -```lua -find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") -``` - -更完整的使用描述,请参考:[find_packages](/zh-cn/manual/builtin_modules?id=find_packages)接口文档。 - -### homebrew集成支持 - -由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。 - -### vcpkg集成支持 - -目前xmake v2.2.2版本已经支持了vcpkg,用户只需要装完vcpkg后,执行`$ vcpkg integrate install`,xmake就能自动从系统中检测到vcpkg的根路径,然后自动适配里面包。 - -当然,我们也可以手动指定vcpkg的根路径来支持: - -```console -$ xmake f --vcpkg=f:\vcpkg -``` - -或者我们可以设置到全局配置中去,避免每次切换配置的时候,重复设置: - -```console -$ xmake g --vcpkg=f:\vcpkg -``` - -## 远程依赖模式 - -这个在2.2.2版本后已经初步支持,用法上更加的简单,只需要设置对应的依赖包就行了,例如: - -```lua -add_requires("tbox 1.6.*", "libpng ~1.16", "zlib") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("tbox", "libpng", "zlib") -``` - -上面的`add_requires`用于描述当前项目需要的依赖包,而`add_packages`用于应用依赖包到test目标,只有设置这个才会自动追加links, linkdirs, includedirs等设置。 - -然后直接执行编译即可: - -```console -$ xmake -``` - -xmake会去远程拉取相关源码包,然后自动编译安装,最后编译项目,进行依赖包的链接,具体效果见下图: - - - -关于包依赖管理的更多相关信息和进展见相关issues:[Remote package management](https://github.com/xmake-io/xmake/issues/69) - -### 目前支持的特性 - -* 语义版本支持,例如:">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" -* 提供官方包仓库、自建私有仓库、项目内置仓库等多仓库管理支持 -* 跨平台包编译集成支持(不同平台、不同架构的包可同时安装,快速切换使用) -* debug依赖包支持,实现源码调试 - -### 依赖包处理机制 - -这里我们简单介绍下整个依赖包的处理机制: - - - -1. 优先检测当前系统目录、第三方包管理下有没有存在指定的包,如果有匹配的包,那么就不需要下载安装了 (当然也可以设置不使用系统包) -2. 检索匹配对应版本的包,然后下载、编译、安装(注:安装在特定xmake目录,不会干扰系统库环境) -3. 编译项目,最后自动链接启用的依赖包 - -### 快速上手 - -新建一个依赖tbox库的空工程: - -```console -$ xmake create -t console_tbox test -$ cd test -``` - -执行编译即可,如果当前没有安装tbox库,则会自动下载安装后使用: - -```console -$ xmake -``` - -切换到iphoneos平台进行编译,将会重新安装iphoneos版本的tbox库进行链接使用: - -```console -$ xmake f -p iphoneos -$ xmake -``` - -切换到android平台arm64-v8a架构编译: - -```console -$ xmake f -p android [--ndk=~/android-ndk-r16b] -$ xmake -``` - -### 语义版本设置 - -xmake的依赖包管理是完全支持语义版本选择的,例如:"~1.6.1",对于语义版本的具体描述见:[https://semver.org/](https://semver.org/) - -一些语义版本写法: - -```lua -add_requires("tbox 1.6.*", "pcre 1.3.x", "libpng ^1.18") -add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0") -``` - -目前xmake使用的语义版本解析器是[uael](https://github.com/uael)贡献的[sv](https://github.com/uael/sv)库,里面也有对版本描述写法的详细说明,可以参考下:[版本描述说明](https://github.com/uael/sv#versions) - -当然,如果我们对当前的依赖包的版本没有特殊要求,那么可以直接这么写: - -```lua -add_requires("tbox", "libpng", "zlib") -``` - -这会使用已知的最新版本包,或者是master分支的源码编译的包,如果当前包有git repo地址,我们也能指定特定分支版本: - -```lua -add_requires("tbox master") -add_requires("tbox dev") -``` - -### 额外的包信息设置 - -#### 可选包设置 - -如果指定的依赖包当前平台不支持,或者编译安装失败了,那么xmake会编译报错,这对于有些必须要依赖某些包才能工作的项目,这是合理的。 -但是如果有些包是可选的依赖,即使没有也可以正常编译使用的话,可以设置为可选包: - -```lua -add_requires("tbox", {optional = true}) -``` - -#### 禁用系统库 - -默认的设置,xmake会去优先检测系统库是否存在(如果没设置版本要求),如果用户完全不想使用系统库以及第三方包管理提供的库,那么可以设置: - -```lua -add_requires("tbox", {system = false}) -``` - -#### 使用调试版本的包 - -如果我们想同时源码调试依赖包,那么可以设置为使用debug版本的包(当然前提是这个包支持debug编译): - -```lua -add_requires("tbox", {debug = true}) -``` - -如果当前包还不支持debug编译,可在仓库中提交修改编译规则,对debug进行支持,例如: - -```lua -package("openssl") - on_install("linux", "macosx", function (package) - os.vrun("./config %s --prefix=\"%s\"", package:debug() and "--debug" or "", package:installdir()) - os.vrun("make -j4") - os.vrun("make install") - end) -``` - -#### 传递额外的编译信息到包 - -某些包在编译时候有各种编译选项,我们也可以传递进来,当然包本身得支持: - -```lua -add_requires("tbox", {configs = {small=true}}) -``` - -传递`--small=true`给tbox包,使得编译安装的tbox包是启用此选项的。 - -### 第三方依赖包安装 - -2.2.5版本之后,xmake支持对对第三方包管理器里面的依赖库安装支持,例如:conan,brew, vcpkg等 - -#### 添加homebrew的依赖包 - -```lua -add_requires("brew::zlib", {alias = "zlib"}}) -add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("pcre2", "zlib") -``` - -#### 添加vcpkg的依赖包 - -```lua -add_requires("vcpkg::zlib", "vcpkg::pcre2") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("vcpkg::zlib", "vcpkg::pcre2") -``` - -#### 添加conan的依赖包 - -```lua -add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) -add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", - configs = {options = "OpenSSL:shared=True"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("openssl", "zlib") -``` - -执行xmake进行编译后: - -```console -ruki:test_package ruki$ xmake -checking for the architecture ... x86_64 -checking for the Xcode directory ... /Applications/Xcode.app -checking for the SDK version of Xcode ... 10.14 -note: try installing these packages (pass -y to skip confirm)? - -> CONAN::zlib/1.2.11@conan/stable (debug) - -> CONAN::OpenSSL/1.0.2n@conan/stable -please input: y (y/n) - - => installing CONAN::zlib/1.2.11@conan/stable .. ok - => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok - -[ 0%]: ccache compiling.release src/main.c -[100%]: linking.release test -``` - -#### 添加clib的依赖包 - -clib是一款基于源码的依赖包管理器,拉取的依赖包是直接下载对应的库源码,集成到项目中编译,而不是二进制库依赖。 - -其在xmake中集成也很方便,唯一需要注意的是,还需要自己添加上对应库的源码到xmake.lua,例如: - -```lua -add_requires("clib::clibs/bytes@0.0.4", {alias = "bytes"}) - -target("test") - set_kind("binary") - add_files("clib/bytes/*.c") - add_files("src/*.c") - add_packages("bytes") -``` - -### 使用自建私有包仓库 - -如果需要的包不在官方仓库[xmake-repo](https://github.com/xmake-io/xmake-repo)中,我们可以提交贡献代码到仓库进行支持。 -但如果有些包仅用于个人或者私有项目,我们可以建立一个私有仓库repo,仓库组织结构可参考:[xmake-repo](https://github.com/xmake-io/xmake-repo) - -比如,现在我们有一个一个私有仓库repo:`git@github.com:myrepo/xmake-repo.git` - -我们可以通过下面的命令进行仓库添加: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -或者我们直接写在xmake.lua中: - -```lua -add_repositories("my-repo git@github.com:myrepo/xmake-repo.git") -``` - -如果我们只是想添加一两个私有包,这个时候特定去建立一个git repo太小题大做了,我们可以直接把包仓库放置项目里面,例如: - -``` -projectdir - - myrepo - - packages - - t/tbox/xmake.lua - - z/zlib/xmake.lua - - src - - main.c - - xmake.lua -``` - -上面myrepo目录就是自己的私有包仓库,内置在自己的项目里面,然后在xmake.lua里面添加一下这个仓库位置: - -```lua -add_repositories("my-repo myrepo") -``` - -这个可以参考[benchbox](https://github.com/tboox/benchbox)项目,里面就内置了一个私有仓库。 - -我们甚至可以连仓库也不用建,直接定义包描述到项目xmake.lua中,这对依赖一两个包的情况还是很有用的,例如: - -```lua -package("libjpeg") - - set_urls("http://www.ijg.org/files/jpegsrc.$(version).tar.gz") - - add_versions("v9c", "650250979303a649e21f87b5ccd02672af1ea6954b911342ea491f351ceb7122") - - on_install("windows", function (package) - os.mv("jconfig.vc", "jconfig.h") - os.vrun("nmake -f makefile.vc") - os.cp("*.h", package:installdir("include")) - os.cp("libjpeg.lib", package:installdir("lib")) - end) - - on_install("macosx", "linux", function (package) - import("package.tools.autoconf").install(package) - end) - -package_end() - -add_requires("libjpeg") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("libjpeg") -``` - -### 包管理命令使用 - -包管理命令`$ xmake require` 可用于手动显示的下载编译安装、卸载、检索、查看包信息。 - -#### 安装指定包 - -```console -$ xmake require tbox -``` - -安装指定版本包: - -```console -$ xmake require tbox "~1.6" -``` - -强制重新下载安装,并且显示详细安装信息: - -```console -$ xmake require -f -v tbox "1.5.x" -``` - -传递额外的设置信息: - -```console -$ xmake require --extra="debug=true,config={small=true}" tbox -``` - -安装debug包,并且传递`small=true`的编译配置信息到包中去。 - -#### 卸载指定包 - -```console -$ xmake require --uninstall tbox -``` - -这会完全卸载删除包文件。 - -#### 查看包详细信息 - -```console -$ xmake require --info tbox -``` - -#### 在当前仓库中搜索包 - -```console -$ xmake require --search tbox -``` - -这个是支持模糊搜素以及lua模式匹配搜索的: - -```console -$ xmake require --search pcr -``` - -会同时搜索到pcre, pcre2等包。 - -#### 列举当前已安装的包 - -```console -$ xmake require --list -``` - -### 仓库管理命令使用 - -上文已经简单讲过,添加私有仓库可以用(支持本地路径添加): - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -v2.2.3开始,支持添加指定分支的repo,例如: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git dev -``` - -我们也可以移除已安装的某个仓库: - -```console -$ xmake repo --remove myrepo -``` - -或者查看所有已添加的仓库: - -```console -$ xmake repo --list -``` - -如果远程仓库有更新,可以手动执行仓库更新,来获取更多、最新的包: - -```console -$ xmake repo -u -``` - -### 提交包到官方仓库 - -目前这个特性刚完成不久,目前官方仓库的包还不是很多,有些包也许还不支持部分平台,不过这并不是太大问题,后期迭代几个版本后,我会不断扩充完善包仓库。 - -如果你需要的包,当前的官方仓库还没有收录,可以提交issues或者自己可以在本地调通后,贡献提交到官方仓库:[xmake-repo](https://github.com/xmake-io/xmake-repo) - -详细的贡献说明,见:[CONTRIBUTING.md](https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md) - diff --git a/zh-cn/package/local_package.md b/zh-cn/package/local_package.md new file mode 100644 index 00000000..9a24dfb8 --- /dev/null +++ b/zh-cn/package/local_package.md @@ -0,0 +1,46 @@ + +通过在项目中内置依赖包目录以及二进制包文件,可以方便的集成一些第三方的依赖库,这种方式比较简单直接,但是缺点也很明显,不方便管理。 + +以tbox工程为例,其依赖包如下: + +``` +- base.pkg +- zlib.pkg +- polarssl.pkg +- openssl.pkg +- mysql.pkg +- pcre.pkg +- ... +``` + +如果要让当前工程识别加载这些包,首先要指定包目录路径,例如: + +```lua +add_packagedirs("packages") +``` + +指定好后,就可以在target作用域中,通过[add_packages](/zh-cn/manual/project_target?id=targetadd_packages)接口,来添加集成包依赖了,例如: + +```lua +target("tbox") + add_packages("zlib", "polarssl", "pcre", "mysql") +``` + +那么如何去生成一个*.pkg的包呢,如果是基于xmake的工程,生成方式很简单,只需要: + +```console +$ cd tbox +$ xmake package +``` + +即可在build目录下生成一个tbox.pkg的跨平台包,给第三方项目使用,我也可以直接设置输出目录,编译生成到对方项目中去,例如: + +```console +$ cd tbox +$ xmake package -o ../test/packages +``` + +这样,test工程就可以通过[add_packages]((/zh-cn/manual/project_target?id=targetadd_packages)和[add_packagedirs](/zh-cn/manual/global_interfaces?id=add_packagedirs)去配置和使用tbox.pkg包了。 + +关于内置包的详细描述,还可以参考下相关文章,这里面有详细介绍:[依赖包的添加和自动检测机制](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) + diff --git a/zh-cn/package/remote_package.md b/zh-cn/package/remote_package.md new file mode 100644 index 00000000..1d736c25 --- /dev/null +++ b/zh-cn/package/remote_package.md @@ -0,0 +1,395 @@ + +这个在2.2.2版本后已经初步支持,用法上更加的简单,只需要设置对应的依赖包就行了,例如: + +```lua +add_requires("tbox 1.6.*", "libpng ~1.16", "zlib") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("tbox", "libpng", "zlib") +``` + +上面的`add_requires`用于描述当前项目需要的依赖包,而`add_packages`用于应用依赖包到test目标,只有设置这个才会自动追加links, linkdirs, includedirs等设置。 + +然后直接执行编译即可: + +```console +$ xmake +``` + +xmake会去远程拉取相关源码包,然后自动编译安装,最后编译项目,进行依赖包的链接,具体效果见下图: + + + +关于包依赖管理的更多相关信息和进展见相关issues:[Remote package management](https://github.com/xmake-io/xmake/issues/69) + +## 目前支持的特性 + +* 语义版本支持,例如:">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" +* 提供官方包仓库、自建私有仓库、项目内置仓库等多仓库管理支持 +* 跨平台包编译集成支持(不同平台、不同架构的包可同时安装,快速切换使用) +* debug依赖包支持,实现源码调试 + +## 依赖包处理机制 + +这里我们简单介绍下整个依赖包的处理机制: + + + +1. 优先检测当前系统目录、第三方包管理下有没有存在指定的包,如果有匹配的包,那么就不需要下载安装了 (当然也可以设置不使用系统包) +2. 检索匹配对应版本的包,然后下载、编译、安装(注:安装在特定xmake目录,不会干扰系统库环境) +3. 编译项目,最后自动链接启用的依赖包 + +## 快速上手 + +新建一个依赖tbox库的空工程: + +```console +$ xmake create -t console_tbox test +$ cd test +``` + +执行编译即可,如果当前没有安装tbox库,则会自动下载安装后使用: + +```console +$ xmake +``` + +切换到iphoneos平台进行编译,将会重新安装iphoneos版本的tbox库进行链接使用: + +```console +$ xmake f -p iphoneos +$ xmake +``` + +切换到android平台arm64-v8a架构编译: + +```console +$ xmake f -p android [--ndk=~/android-ndk-r16b] +$ xmake +``` + +## 语义版本设置 + +xmake的依赖包管理是完全支持语义版本选择的,例如:"~1.6.1",对于语义版本的具体描述见:[https://semver.org/](https://semver.org/) + +一些语义版本写法: + +```lua +add_requires("tbox 1.6.*", "pcre 1.3.x", "libpng ^1.18") +add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0") +``` + +目前xmake使用的语义版本解析器是[uael](https://github.com/uael)贡献的[sv](https://github.com/uael/sv)库,里面也有对版本描述写法的详细说明,可以参考下:[版本描述说明](https://github.com/uael/sv#versions) + +当然,如果我们对当前的依赖包的版本没有特殊要求,那么可以直接这么写: + +```lua +add_requires("tbox", "libpng", "zlib") +``` + +这会使用已知的最新版本包,或者是master分支的源码编译的包,如果当前包有git repo地址,我们也能指定特定分支版本: + +```lua +add_requires("tbox master") +add_requires("tbox dev") +``` + +## 额外的包信息设置 + +### 可选包设置 + +如果指定的依赖包当前平台不支持,或者编译安装失败了,那么xmake会编译报错,这对于有些必须要依赖某些包才能工作的项目,这是合理的。 +但是如果有些包是可选的依赖,即使没有也可以正常编译使用的话,可以设置为可选包: + +```lua +add_requires("tbox", {optional = true}) +``` + +### 禁用系统库 + +默认的设置,xmake会去优先检测系统库是否存在(如果没设置版本要求),如果用户完全不想使用系统库以及第三方包管理提供的库,那么可以设置: + +```lua +add_requires("tbox", {system = false}) +``` + +### 使用调试版本的包 + +如果我们想同时源码调试依赖包,那么可以设置为使用debug版本的包(当然前提是这个包支持debug编译): + +```lua +add_requires("tbox", {debug = true}) +``` + +如果当前包还不支持debug编译,可在仓库中提交修改编译规则,对debug进行支持,例如: + +```lua +package("openssl") + on_install("linux", "macosx", function (package) + os.vrun("./config %s --prefix=\"%s\"", package:debug() and "--debug" or "", package:installdir()) + os.vrun("make -j4") + os.vrun("make install") + end) +``` + +### 传递额外的编译信息到包 + +某些包在编译时候有各种编译选项,我们也可以传递进来,当然包本身得支持: + +```lua +add_requires("tbox", {configs = {small=true}}) +``` + +传递`--small=true`给tbox包,使得编译安装的tbox包是启用此选项的。 + +## 第三方依赖包安装 + +2.2.5版本之后,xmake支持对对第三方包管理器里面的依赖库安装支持,例如:conan,brew, vcpkg等 + +### 添加homebrew的依赖包 + +```lua +add_requires("brew::zlib", {alias = "zlib"}}) +add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("pcre2", "zlib") +``` + +### 添加vcpkg的依赖包 + +```lua +add_requires("vcpkg::zlib", "vcpkg::pcre2") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("vcpkg::zlib", "vcpkg::pcre2") +``` + +### 添加conan的依赖包 + +```lua +add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) +add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", + configs = {options = "OpenSSL:shared=True"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("openssl", "zlib") +``` + +执行xmake进行编译后: + +```console +ruki:test_package ruki$ xmake +checking for the architecture ... x86_64 +checking for the Xcode directory ... /Applications/Xcode.app +checking for the SDK version of Xcode ... 10.14 +note: try installing these packages (pass -y to skip confirm)? + -> CONAN::zlib/1.2.11@conan/stable (debug) + -> CONAN::OpenSSL/1.0.2n@conan/stable +please input: y (y/n) + + => installing CONAN::zlib/1.2.11@conan/stable .. ok + => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok + +[ 0%]: ccache compiling.release src/main.c +[100%]: linking.release test +``` + +### 添加clib的依赖包 + +clib是一款基于源码的依赖包管理器,拉取的依赖包是直接下载对应的库源码,集成到项目中编译,而不是二进制库依赖。 + +其在xmake中集成也很方便,唯一需要注意的是,还需要自己添加上对应库的源码到xmake.lua,例如: + +```lua +add_requires("clib::clibs/bytes@0.0.4", {alias = "bytes"}) + +target("test") + set_kind("binary") + add_files("clib/bytes/*.c") + add_files("src/*.c") + add_packages("bytes") +``` + +## 使用自建私有包仓库 + +如果需要的包不在官方仓库[xmake-repo](https://github.com/xmake-io/xmake-repo)中,我们可以提交贡献代码到仓库进行支持。 +但如果有些包仅用于个人或者私有项目,我们可以建立一个私有仓库repo,仓库组织结构可参考:[xmake-repo](https://github.com/xmake-io/xmake-repo) + +比如,现在我们有一个一个私有仓库repo:`git@github.com:myrepo/xmake-repo.git` + +我们可以通过下面的命令进行仓库添加: + +```console +$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git +``` + +或者我们直接写在xmake.lua中: + +```lua +add_repositories("my-repo git@github.com:myrepo/xmake-repo.git") +``` + +如果我们只是想添加一两个私有包,这个时候特定去建立一个git repo太小题大做了,我们可以直接把包仓库放置项目里面,例如: + +``` +projectdir + - myrepo + - packages + - t/tbox/xmake.lua + - z/zlib/xmake.lua + - src + - main.c + - xmake.lua +``` + +上面myrepo目录就是自己的私有包仓库,内置在自己的项目里面,然后在xmake.lua里面添加一下这个仓库位置: + +```lua +add_repositories("my-repo myrepo") +``` + +这个可以参考[benchbox](https://github.com/tboox/benchbox)项目,里面就内置了一个私有仓库。 + +我们甚至可以连仓库也不用建,直接定义包描述到项目xmake.lua中,这对依赖一两个包的情况还是很有用的,例如: + +```lua +package("libjpeg") + + set_urls("http://www.ijg.org/files/jpegsrc.$(version).tar.gz") + + add_versions("v9c", "650250979303a649e21f87b5ccd02672af1ea6954b911342ea491f351ceb7122") + + on_install("windows", function (package) + os.mv("jconfig.vc", "jconfig.h") + os.vrun("nmake -f makefile.vc") + os.cp("*.h", package:installdir("include")) + os.cp("libjpeg.lib", package:installdir("lib")) + end) + + on_install("macosx", "linux", function (package) + import("package.tools.autoconf").install(package) + end) + +package_end() + +add_requires("libjpeg") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("libjpeg") +``` + +## 包管理命令使用 + +包管理命令`$ xmake require` 可用于手动显示的下载编译安装、卸载、检索、查看包信息。 + +### 安装指定包 + +```console +$ xmake require tbox +``` + +安装指定版本包: + +```console +$ xmake require tbox "~1.6" +``` + +强制重新下载安装,并且显示详细安装信息: + +```console +$ xmake require -f -v tbox "1.5.x" +``` + +传递额外的设置信息: + +```console +$ xmake require --extra="debug=true,config={small=true}" tbox +``` + +安装debug包,并且传递`small=true`的编译配置信息到包中去。 + +### 卸载指定包 + +```console +$ xmake require --uninstall tbox +``` + +这会完全卸载删除包文件。 + +### 查看包详细信息 + +```console +$ xmake require --info tbox +``` + +### 在当前仓库中搜索包 + +```console +$ xmake require --search tbox +``` + +这个是支持模糊搜素以及lua模式匹配搜索的: + +```console +$ xmake require --search pcr +``` + +会同时搜索到pcre, pcre2等包。 + +### 列举当前已安装的包 + +```console +$ xmake require --list +``` + +## 仓库管理命令使用 + +上文已经简单讲过,添加私有仓库可以用(支持本地路径添加): + +```console +$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git +``` + +v2.2.3开始,支持添加指定分支的repo,例如: + +```console +$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git dev +``` + +我们也可以移除已安装的某个仓库: + +```console +$ xmake repo --remove myrepo +``` + +或者查看所有已添加的仓库: + +```console +$ xmake repo --list +``` + +如果远程仓库有更新,可以手动执行仓库更新,来获取更多、最新的包: + +```console +$ xmake repo -u +``` + +## 提交包到官方仓库 + +目前这个特性刚完成不久,目前官方仓库的包还不是很多,有些包也许还不支持部分平台,不过这并不是太大问题,后期迭代几个版本后,我会不断扩充完善包仓库。 + +如果你需要的包,当前的官方仓库还没有收录,可以提交issues或者自己可以在本地调通后,贡献提交到官方仓库:[xmake-repo](https://github.com/xmake-io/xmake-repo) + +详细的贡献说明,见:[CONTRIBUTING.md](https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md) + diff --git a/zh-cn/package/system_package.md b/zh-cn/package/system_package.md new file mode 100644 index 00000000..eda893e9 --- /dev/null +++ b/zh-cn/package/system_package.md @@ -0,0 +1,73 @@ + +如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。 + +目前此接口支持以下一些包管理支持: + +* vcpkg +* homebrew +* pkg-config + +并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包: + +```lua +local packages = find_packages("openssl", "zlib") +``` + +返回的结果如下: + +```lua +{ + {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, + {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +} +``` + +如果查找成功,则返回一个包含所有包信息的table,如果失败返回nil + +这里的返回结果可以直接作为`target:add`, `option:add`的参数传入,用于动态增加`target/option`的配置: + +```lua +option("zlib") + set_showmenu(true) + before_check(function (option) + option:add(find_packages("openssl", "zlib")) + end) +``` + +```lua +target("test") + on_load(function (target) + target:add(find_package("openssl", "zlib")) + end) +``` + +如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。 + +另外,我们也可以从指定的包管理器查找包: + +```lua +find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") +``` + +更完整的使用描述,请参考:[find_packages](/zh-cn/manual/builtin_modules?id=find_packages)接口文档。 + +## homebrew集成支持 + +由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。 + +## vcpkg集成支持 + +目前xmake v2.2.2版本已经支持了vcpkg,用户只需要装完vcpkg后,执行`$ vcpkg integrate install`,xmake就能自动从系统中检测到vcpkg的根路径,然后自动适配里面包。 + +当然,我们也可以手动指定vcpkg的根路径来支持: + +```console +$ xmake f --vcpkg=f:\vcpkg +``` + +或者我们可以设置到全局配置中去,避免每次切换配置的时候,重复设置: + +```console +$ xmake g --vcpkg=f:\vcpkg +``` + -- cgit v1.2.3