创建conan包-打包现有二进制文件

2023-12-05 05:28

本文主要是介绍创建conan包-打包现有二进制文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

创建conan包-打包现有二进制文件

  • 1 Packaging Existing Binaries
    • 1.1 Packaging Pre-built Binaries
    • 1.2 Downloading and Packaging Pre-built Binaries

本文是基于对conan官方文档Packaging Existing Binaries翻译而来, 更详细的信息可以去查阅conan官方文档。

1 Packaging Existing Binaries

There are specific scenarios in which it is necessary to create packages from existing binaries, for example from 3rd parties or binaries previously built by another process or team that are not using Conan. Under these circumstances building from sources is not what you want. You should package the local files in the following situations:
在某些特殊情况下,有必要从现有二进制文件创建软件包,例如从第三方或由其他未使用 Conan 的流程或团队构建的二进制文件。在这种情况下,从源代码构建软件包并不是您想要的。在以下情况下,应打包本地文件:

  • When you cannot build the packages from sources (when only pre-built binaries are available).
  • 无法从源代码构建软件包时(只有预构建的二进制文件可用)。
  • When you are developing your package locally and you want to export the built artifacts to the local cache. As you don’t want to rebuild again (clean copy) your artifacts, you don’t want to call conan create. This method will keep your build cache if you are using an IDE or calling locally to the conan build command.
  • 当您在本地开发软件包,并希望将构建的工件导出到本地缓存时。由于您不想再次重建(清空副本)您的工件,所以您不想调用 conan create。如果您使用集成开发环境或在本地调用 conan build 命令,此方法将保留您的构建缓存。

1.1 Packaging Pre-built Binaries

Running the build() method, when the files you want to package are local, results in no added value as the files copied from the user folder cannot be reproduced. For this scenario, run conan export-pkg command directly.
当要打包的文件是本地文件时,运行 build() 方法不会带来任何附加值,因为从用户文件夹复制的文件无法再现。在这种情况下,请直接运行 conan export-pkg 命令。

A Conan recipe is still required, but is very simple and will only include the package meta information. A basic recipe can be created with the conan new command:
Conan 配方仍是必需的,但非常简单,只包含软件包元信息。可以使用 conan new 命令创建基本配方:

$ conan new hello/0.1 --bare

This will create and store the following package recipe in the local cache:
这将在本地缓存中创建并存储以下软件包配方:

class HelloConan(ConanFile):name = "hello"version = "0.1"settings = "os", "compiler", "build_type", "arch"def package(self):self.copy("*")def package_info(self):self.cpp_info.libs = self.collect_libs()

The provided package_info() method scans the package files to provide end-users with the name of the libraries to link to. This method can be further customized to provide additional build flags (typically dependent on the settings). The default package_info() applies as follows: it defines headers in the “include” folder, libraries in the “lib” folder, and binaries in the “bin” folder. A different package layout can be defined in the package_info() method.
所提供的 package_info() 方法会扫描软件包文件,为最终用户提供要链接的库名称。该方法可进一步定制,以提供额外的构建标志(通常取决于设置)。默认的 package_info() 应用如下:在 "include "文件夹中定义头文件,在 "lib "文件夹中定义库,在 "bin "文件夹中定义二进制文件。可以在 package_info() 方法中定义不同的软件包布局。

This package recipe can be also extended to provide support for more configurations (for example, adding options: shared/static, or using different settings), adding dependencies (requires), and more.
该软件包配方还可以扩展,以支持更多配置(例如,添加选项:共享/静态,或使用不同的设置)、添加依赖项(要求)等。

Based on the above, we can assume that our current directory contains a lib folder with a number binaries for this “hello” library libhello.a, compatible for example with Windows MinGW (gcc) version 4.9:
根据上述情况,我们可以假设当前目录下有一个 lib 文件夹,其中包含 "hello "库 libhello.a 的若干二进制文件,例如与 Windows MinGW (gcc) 4.9 版本兼容:

$ conan export-pkg . hello/0.1@myuser/testing  -s os=Windows -s compiler=gcc -s compiler.version=4.9 ...

Having a test_package folder is still highly recommended for testing the package locally before upload. As we don’t want to build the package from the sources, the flow would be:
我们仍然强烈建议在上传软件包前在本地测试 test_package 文件夹。由于我们不想从源代码构建软件包,因此流程如下

$ conan new hello/0.1 --bare --test
# customize test_package project
# customize package recipe if necessary
$ cd my/path/to/binaries
$ conan export-pkg PATH/TO/conanfile.py hello/0.1@myuser/testing  -s os=Windows -s compiler=gcc -s compiler.version=4.9 ...
$ conan test PATH/TO/test_package/conanfile.py hello/0.1@myuser/testing -s os=Windows -s compiler=gcc -s ...

The last two steps can be repeated for any number of configurations.
最后两个步骤可以重复进行,以获得任意数量的配置。

1.2 Downloading and Packaging Pre-built Binaries

In this scenario, creating a complete Conan recipe, with the detailed retrieval of the binaries could be the preferred method, because it is reproducible, and the original binaries might be traced. Follow our sample recipe for this purpose:
在这种情况下,创建一个完整的conan recipe并详细检索二进制文件可能是首选方法,因为这种方法具有可重复性,而且可以追踪到原始的二进制文件。为此,请参考我们的示例配方:

class HelloConan(ConanFile):name = "hello"version = "0.1"settings = "os", "compiler", "build_type", "arch"def build(self):if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":url = ("https://<someurl>/downloads/hello_binary%s_%s.zip"% (str(self.settings.compiler.version), str(self.settings.build_type)))elif ...:url = ...else:raise Exception("Binary does not exist for these settings")tools.get(url)def package(self):self.copy("*") # assume package as-is, but you can also copy specific files or rearrangedef package_info(self):  # still very useful for package consumersself.cpp_info.libs = ["hello"]

Typically, pre-compiled binaries come for different configurations, so the only task that the build() method has to implement is to map the settings to the different URLs.
通常情况下,预编译的二进制文件会有不同的配置,因此 build() 方法需要执行的唯一任务就是将设置映射到不同的 URL。

Note

  • This is a standard Conan package even if the binaries are being retrieved from elsewhere. The recommended approach is to use conan create, and include a small consuming project in addition to the above recipe, to test locally and then proceed to upload the Conan package with the binaries to the Conan remote with conan upload.
  • 即使二进制文件是从其他地方获取的,这也是一个标准的 Conan 软件包。建议的方法是使用 conan create,并在上述配方中加入一个小型消耗项目,在本地进行测试,然后使用 conan upload 将包含二进制文件的 Conan 软件包上传到远端 Conan。
  • The same building policies apply. Having a recipe fails if no Conan packages are created, and the --build argument is not defined. A typical approach for this kind of packages could be to define a build_policy=“missing”, especially if the URLs are also under the team control. If they are external (on the internet), it could be better to create the packages and store them on your own Conan server, so that the builds do not rely on third party URL being available.
  • 同样的构建策略也适用。如果没有创建conan软件包,也没有定义 --build 参数,配方就会失效。对于这类软件包,典型的方法是定义 build_policy="missing",尤其是当 URL 也在团队控制之下时。如果它们是外部的(在互联网上),最好是创建软件包并将其存储在自己的 Conan 服务器上,这样编译就不会依赖于第三方 URL 的可用性。

这篇关于创建conan包-打包现有二进制文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/456314

相关文章

PyInstaller打包selenium-wire过程中常见问题和解决指南

《PyInstaller打包selenium-wire过程中常见问题和解决指南》常用的打包工具PyInstaller能将Python项目打包成单个可执行文件,但也会因为兼容性问题和路径管理而出现各种运... 目录前言1. 背景2. 可能遇到的问题概述3. PyInstaller 打包步骤及参数配置4. 依赖

Flutter打包APK的几种方式小结

《Flutter打包APK的几种方式小结》Flutter打包不同于RN,Flutter可以在AndroidStudio里编写Flutter代码并最终打包为APK,本篇主要阐述涉及到的几种打包方式,通... 目录前言1. android原生打包APK方式2. Flutter通过原生工程打包方式3. Futte

idea中创建新类时自动添加注释的实现

《idea中创建新类时自动添加注释的实现》在每次使用idea创建一个新类时,过了一段时间发现看不懂这个类是用来干嘛的,为了解决这个问题,我们可以设置在创建一个新类时自动添加注释,帮助我们理解这个类的用... 目录前言:详细操作:步骤一:点击上方的 文件(File),点击&nbmyHIgsp;设置(Setti

Spring 中使用反射创建 Bean 实例的几种方式

《Spring中使用反射创建Bean实例的几种方式》文章介绍了在Spring框架中如何使用反射来创建Bean实例,包括使用Class.newInstance()、Constructor.newI... 目录1. 使用 Class.newInstance() (仅限无参构造函数):2. 使用 Construc

C#原型模式之如何通过克隆对象来优化创建过程

《C#原型模式之如何通过克隆对象来优化创建过程》原型模式是一种创建型设计模式,通过克隆现有对象来创建新对象,避免重复的创建成本和复杂的初始化过程,它适用于对象创建过程复杂、需要大量相似对象或避免重复初... 目录什么是原型模式?原型模式的工作原理C#中如何实现原型模式?1. 定义原型接口2. 实现原型接口3

Python中conda虚拟环境创建及使用小结

《Python中conda虚拟环境创建及使用小结》本文主要介绍了Python中conda虚拟环境创建及使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录0.前言1.Miniconda安装2.conda本地基本操作3.创建conda虚拟环境4.激活c

使用Python创建一个能够筛选文件的PDF合并工具

《使用Python创建一个能够筛选文件的PDF合并工具》这篇文章主要为大家详细介绍了如何使用Python创建一个能够筛选文件的PDF合并工具,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录背景主要功能全部代码代码解析1. 初始化 wx.Frame 窗口2. 创建工具栏3. 创建布局和界面控件4

linux打包解压命令方式

《linux打包解压命令方式》文章介绍了Linux系统中常用的打包和解压命令,包括tar和zip,使用tar命令可以创建和解压tar格式的归档文件,使用zip命令可以创建和解压zip格式的压缩文件,每... 目录Lijavascriptnux 打包和解压命令打包命令解压命令总结linux 打包和解压命令打

将java程序打包成可执行文件的实现方式

《将java程序打包成可执行文件的实现方式》本文介绍了将Java程序打包成可执行文件的三种方法:手动打包(将编译后的代码及JRE运行环境一起打包),使用第三方打包工具(如Launch4j)和JDK自带... 目录1.问题提出2.如何将Java程序打包成可执行文件2.1将编译后的代码及jre运行环境一起打包2

Java中对象的创建和销毁过程详析

《Java中对象的创建和销毁过程详析》:本文主要介绍Java中对象的创建和销毁过程,对象的创建过程包括类加载检查、内存分配、初始化零值内存、设置对象头和执行init方法,对象的销毁过程由垃圾回收机... 目录前言对象的创建过程1. 类加载检查2China编程. 分配内存3. 初始化零值4. 设置对象头5. 执行