|
1 |
| -### Default packaging format |
| 1 | +### Generate local package |
2 | 2 |
|
3 | 3 | After version 2.5.5, we have provided a new local package packaging solution that will seamlessly integrate `add_requires` and `add_packages`.
|
4 | 4 |
|
@@ -76,6 +76,120 @@ Here is the complete [test example](https://github.com/xmake-io/xmake/blob/dev/t
|
76 | 76 | -Wl,-x -lfoo -lsub -ladd -lz
|
77 | 77 | ```
|
78 | 78 |
|
| 79 | +#### Step by Step Local Packaging Tutorial |
| 80 | + |
| 81 | +In this tutorial we will package a static library called foo, upload it to a GitHub repository and consume it similar to a manner of CMake FetchContent |
| 82 | + |
| 83 | +- Create an xmake project |
| 84 | + |
| 85 | +```bash |
| 86 | +$ xmake create -P package_origin |
| 87 | +``` |
| 88 | + |
| 89 | +- Imitate this filetree to prepare files for your package |
| 90 | + |
| 91 | +```bash |
| 92 | +│ .gitignore |
| 93 | +│ xmake.lua |
| 94 | +└───src |
| 95 | + │ main.cpp |
| 96 | + ├───inc |
| 97 | + │ └───foo |
| 98 | + │ foo.hpp |
| 99 | + └───lib |
| 100 | + └───foo |
| 101 | + foo.cpp |
| 102 | +``` |
| 103 | + |
| 104 | +- Create static library target in xmake |
| 105 | + |
| 106 | +```lua |
| 107 | +target("foo") |
| 108 | + set_kind("static") |
| 109 | + add_files("src/lib/foo/*.cpp") |
| 110 | + add_headerfiles("src/inc/foo/*.hpp") |
| 111 | + add_includedirs("src/inc/foo", {public = true}) |
| 112 | +``` |
| 113 | + |
| 114 | +- Implement the functionality of your target |
| 115 | + |
| 116 | +foo.hpp |
| 117 | + |
| 118 | +```cpp |
| 119 | +void foo(); |
| 120 | +``` |
| 121 | + |
| 122 | +foo.cpp |
| 123 | + |
| 124 | +```cpp |
| 125 | +#include <iostream> |
| 126 | +#include "foo.hpp" |
| 127 | + |
| 128 | +void foo() { |
| 129 | + std::cout << "foo"; |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +- Build your project and create the package |
| 134 | + |
| 135 | +```bash |
| 136 | +$ xmake build |
| 137 | +$ xmake package foo |
| 138 | +``` |
| 139 | + |
| 140 | +- Move packages artifacts to a custom package repository. |
| 141 | + |
| 142 | +```bash |
| 143 | +$ mkdir my_custom_binary_package_repo |
| 144 | +$ cp -r build/packages my_custom_binary_package_repo/packages |
| 145 | +$ cd my_custom_binary_package_repo |
| 146 | +$ git init |
| 147 | +$ git add . |
| 148 | +$ git commit -a -m "init" |
| 149 | +``` |
| 150 | + |
| 151 | +Then push this new package repository to your custom repository, e.g. `https://github.com/xxx/my_custom_binary_package_repo.git` |
| 152 | + |
| 153 | +- Create a project where you intend on consuming the package |
| 154 | + |
| 155 | +```bash |
| 156 | +$ xmake create package_consumption |
| 157 | +``` |
| 158 | + |
| 159 | +- Consume the package by adding the repository, finding the package and then linking the package to target of your choosing |
| 160 | + |
| 161 | +```lua |
| 162 | +add_repositories("foo https://github.com/xxx/my_custom_binary_package_repo.git") |
| 163 | +add_requires("foo") |
| 164 | + |
| 165 | +target("package_consumption") |
| 166 | + set_kind("binary") |
| 167 | + add_files("src/*.cpp") |
| 168 | + add_packages("foo") |
| 169 | +``` |
| 170 | + |
| 171 | +you can also use local repository. |
| 172 | + |
| 173 | +```lua |
| 174 | +add_repositories("foo /localpath/my_custom_binary_package_repo") |
| 175 | +``` |
| 176 | + |
| 177 | +```cpp |
| 178 | +#include "foo.hpp" |
| 179 | +int main() { |
| 180 | + foo(); |
| 181 | + return 0; |
| 182 | +} |
| 183 | +``` |
| 184 | + |
| 185 | +Congratulations, you have packaged a library and consumed it xmake! |
| 186 | + |
| 187 | +```bash |
| 188 | +$ xmake build |
| 189 | +$ xmake run |
| 190 | +foo |
| 191 | +``` |
| 192 | + |
79 | 193 | ### Generate remote package
|
80 | 194 |
|
81 | 195 | Out of the local package format, `xmake package` now also supports generating remote packages, so that users can quickly submit them to remote warehouses.
|
@@ -121,6 +235,146 @@ $ xmake package -f remote --url=https://xxxx/xxx.tar.gz --shasum=xxxxx --homepag
|
121 | 235 |
|
122 | 236 | xmake will also read the relevant configuration information from the target's `set_license` and `set_version` configurations.
|
123 | 237 |
|
| 238 | +#### Step by Step Remote Packaging Tutorial |
| 239 | + |
| 240 | +##### Introduction |
| 241 | + |
| 242 | +A remote package is a package that is compiled from source. If you're developing cross-platform libraries, remote packages allow you to avoid manually compiling for every library and platform. |
| 243 | + |
| 244 | +To create remote packages: |
| 245 | +1. Upload your source code to a repository. |
| 246 | +2. In a **separate repository**, create a remote package manifest that points to your source repository. |
| 247 | + |
| 248 | +To consume remote packages, you need to add the repository that contains the remote package manifest to your project, find the package, and then add it to your desired target. |
| 249 | + |
| 250 | +##### Example |
| 251 | + |
| 252 | +In this example, we’ll create a remote package for a static library named `foo`, built using **Windows with MSVC**, and then **consume it on MSYS2 using Clang**. |
| 253 | + |
| 254 | +- Create an xmake project |
| 255 | + |
| 256 | +```bash |
| 257 | +xmake create package_remote_origin |
| 258 | +``` |
| 259 | + |
| 260 | +- Imitate this filetree to prepare files for your package |
| 261 | + |
| 262 | +```bash |
| 263 | +│ |
| 264 | +├── .gitignore |
| 265 | +├── xmake.lua |
| 266 | +└── src |
| 267 | + ├── main.cpp |
| 268 | + ├── inc |
| 269 | + │ └── foo |
| 270 | + │ └── foo.hpp |
| 271 | + └── lib |
| 272 | + └── foo |
| 273 | + └── foo.cpp |
| 274 | +``` |
| 275 | + |
| 276 | +- Create static library target in xmake |
| 277 | + |
| 278 | +```lua |
| 279 | +target("foo") |
| 280 | + set_kind("static") |
| 281 | + add_files("src/lib/foo/*.cpp") |
| 282 | + add_headerfiles("src/inc/foo/*.hpp") |
| 283 | + add_includedirs("src/inc/foo", {public = true}) |
| 284 | +``` |
| 285 | + |
| 286 | +- Implement the functionality of your target |
| 287 | + |
| 288 | +foo.hpp |
| 289 | + |
| 290 | +```cpp |
| 291 | +void foo(); |
| 292 | +``` |
| 293 | + |
| 294 | +foo.cpp |
| 295 | + |
| 296 | +```cpp |
| 297 | +#include <iostream> |
| 298 | +#include "foo.hpp" |
| 299 | + |
| 300 | +void foo() { |
| 301 | + std::cout << "foo"; |
| 302 | +} |
| 303 | +``` |
| 304 | + |
| 305 | +- Create a package and point to your source repository in the config file |
| 306 | + |
| 307 | +```bash |
| 308 | +xmake package -f remote foo |
| 309 | +``` |
| 310 | + |
| 311 | +- Create a source repository for your package with a version tag |
| 312 | + |
| 313 | +For example, you can pust to `https://github.com/xxx/foo_remote_package_source.git` with tag v1.0.0 |
| 314 | + |
| 315 | +Then edit package configuration to add the given version. |
| 316 | + |
| 317 | +```lua |
| 318 | +package("foo") |
| 319 | + add_urls("https://github.com/xxx/foo_remote_package_source.git") |
| 320 | + add_versions("1.0.0", "v1.0.0") |
| 321 | +``` |
| 322 | + |
| 323 | +Or you can use .tar.gz as git url and add it's sha256 sum to versions. |
| 324 | + |
| 325 | +- Create a package config repository for your package |
| 326 | + |
| 327 | +```bash |
| 328 | +$ mkdir mycustom_remote_package_repo |
| 329 | +$ mv build/packages mycustom_remote_package_repo |
| 330 | +$ cd mycustom_remote_package_repo |
| 331 | +$ git init |
| 332 | +$ git add . |
| 333 | +$ git commit -a -m "init repository" |
| 334 | +``` |
| 335 | + |
| 336 | +You can push this repository to https://github.com/xxx/mycustom_remote_package_repo.git |
| 337 | + |
| 338 | +- Create a project where you intend on consuming the package |
| 339 | + |
| 340 | +```bash |
| 341 | +$ xmake create package_consumption |
| 342 | +``` |
| 343 | + |
| 344 | +- Consume the package by adding the repository, finding the package and then linking the package to target of your choosing |
| 345 | + |
| 346 | +```lua |
| 347 | +add_repositories("foo https://github.com/xxx/mycustom_remote_package_repo.git") |
| 348 | +add_requires("foo") |
| 349 | + |
| 350 | +target("package_consumption") |
| 351 | + set_kind("binary") |
| 352 | + add_files("src/*.cpp") |
| 353 | + add_packages("foo") |
| 354 | +``` |
| 355 | + |
| 356 | +you can also use local repository. |
| 357 | + |
| 358 | +```lua |
| 359 | +add_repositories("foo /localpath/mycustom_remote_package_repo") |
| 360 | +``` |
| 361 | + |
| 362 | +```cpp |
| 363 | +#include "foo.hpp" |
| 364 | +int main() { |
| 365 | + foo(); |
| 366 | + return 0; |
| 367 | +} |
| 368 | +``` |
| 369 | + |
| 370 | +Congratulations, you have packaged a library and consumed it xmake! |
| 371 | + |
| 372 | +```bash |
| 373 | +$ xmake build |
| 374 | +$ xmake run |
| 375 | +foo |
| 376 | +``` |
| 377 | + |
124 | 378 | ### Find packages from CMake
|
125 | 379 |
|
126 | 380 | Now cmake is the de facto standard, so the find_package provided by CMake can already find a large number of libraries and modules. We fully reuse this part of cmake's ecology to expand xmake's integration of packages.
|
@@ -246,117 +500,3 @@ xmake will automatically append the following configuration internally when it l
|
246 | 500 | ```cmake
|
247 | 501 | find_package(ABC CONFIG REQUIRED)
|
248 | 502 | ```
|
249 |
| - |
250 |
| -#### Step by Step Local Packaging Tutorial |
251 |
| - |
252 |
| -In this tutorial we will package a static library called foo, upload it to a GitHub repository and consume it similar to a manner of CMake FetchContent |
253 |
| - |
254 |
| -- Create an xmake project |
255 |
| - |
256 |
| -```bash |
257 |
| -$ xmake create -P package_origin |
258 |
| -``` |
259 |
| - |
260 |
| -- Imitate this filetree to prepare files for your package |
261 |
| - |
262 |
| -```bash |
263 |
| -│ .gitignore |
264 |
| -│ xmake.lua |
265 |
| -└───src |
266 |
| - │ main.cpp |
267 |
| - ├───inc |
268 |
| - │ └───foo |
269 |
| - │ foo.hpp |
270 |
| - └───lib |
271 |
| - └───foo |
272 |
| - foo.cpp |
273 |
| -``` |
274 |
| - |
275 |
| -- Create static library target in xmake |
276 |
| - |
277 |
| -```lua |
278 |
| -target("foo") |
279 |
| - set_kind("static") |
280 |
| - add_files("src/lib/foo/*.cpp") |
281 |
| - add_headerfiles("src/inc/foo/*.hpp") |
282 |
| - add_includedirs("src/inc/foo", {public = true}) |
283 |
| -``` |
284 |
| - |
285 |
| -- Implement the functionality of your target |
286 |
| - |
287 |
| -foo.hpp |
288 |
| - |
289 |
| -```cpp |
290 |
| -void foo(); |
291 |
| -``` |
292 |
| - |
293 |
| -foo.cpp |
294 |
| - |
295 |
| -```cpp |
296 |
| -#include <iostream> |
297 |
| -#include "foo.hpp" |
298 |
| - |
299 |
| -void foo() { |
300 |
| - std::cout << "foo"; |
301 |
| -} |
302 |
| -``` |
303 |
| - |
304 |
| -- Build your project and create the package |
305 |
| - |
306 |
| -```bash |
307 |
| -$ xmake build |
308 |
| -$ xmake package foo |
309 |
| -``` |
310 |
| - |
311 |
| -- Move packages artifacts to a custom package repository. |
312 |
| - |
313 |
| -```bash |
314 |
| -$ mkdir xmake_local_package_tutorial |
315 |
| -$ cp -r build/packages xmake_local_package_tutorial/packages |
316 |
| -$ cd xmake_local_package_tutorial |
317 |
| -$ git init |
318 |
| -$ git add . |
319 |
| -$ git commit -a -m "init" |
320 |
| -``` |
321 |
| - |
322 |
| -Then push this new package repository to your custom repository, e.g. `https://github.com/xxx/xmake_local_package_tutorial.git` |
323 |
| - |
324 |
| -- Create a project where you intend on consuming the package |
325 |
| - |
326 |
| -```bash |
327 |
| -$ xmake create package_consumption |
328 |
| -``` |
329 |
| - |
330 |
| -- Consume the package by adding the repository, finding the package and then linking the package to target of your choosing |
331 |
| - |
332 |
| -```lua |
333 |
| -add_repositories("foo https://github.com/xxx/xmake_local_package_tutorial.git") |
334 |
| -add_requires("foo") |
335 |
| - |
336 |
| -target("package_consumption") |
337 |
| - set_kind("binary") |
338 |
| - add_files("src/*.cpp") |
339 |
| - add_packages("foo") |
340 |
| -``` |
341 |
| - |
342 |
| -you can also use local repository. |
343 |
| - |
344 |
| -```lua |
345 |
| -add_repositories("foo /localpath/xmake_local_package_tutorial") |
346 |
| -``` |
347 |
| - |
348 |
| -```cpp |
349 |
| -#include "foo.hpp" |
350 |
| -int main() { |
351 |
| - foo(); |
352 |
| - return 0; |
353 |
| -} |
354 |
| -``` |
355 |
| - |
356 |
| -Congratulations, you have packaged a library and consumed it xmake! |
357 |
| - |
358 |
| -```bash |
359 |
| -$ xmake build |
360 |
| -$ xmake run |
361 |
| -foo |
362 |
| -``` |
|
0 commit comments