首页 > 其他分享 >Manifest使用示例4 - Binarycaching使用缓存文件

Manifest使用示例4 - Binarycaching使用缓存文件

时间:2022-10-18 17:44:38浏览次数:95  
标签:cmake Binarycaching -- 示例 x64 Manifest windows vcpkg

在多人开发环境中,我们仅希望一个人管理项目需要的所有第三方库,并使用服务器部署和分发vcpkg中已编译的库,此时可以使用vcpkg的Binary source特性。

VCPKG 默认开启 Binarycaching 特性,默认情况下,依赖库的缓存文件存放在以下第一个路径下;如果没有设置第一个环境变量,则将放在第二个路径下;同样的,如果没有设置 第一个 和 第二个 环境变量,将会存放在第三个路径下。

  • Windows
  1. %VCPKG_DEFAULT_BINARY_CACHE%
  2. %LOCALAPPDATA%\vcpkg\archives
  3. %APPDATA%\vcpkg\archives
  • 非 Windows
  1. $VCPKG_DEFAULT_BINARY_CACHE
  2. $XDG_CACHE_HOME/vcpkg/archives
  3. $HOME/.cache/vcpkg/archives

一、服务器主机:

1. 首先设置环境变量 VCPKG_DEFAULT_BINARY_CACHE 至公共目录:

PS F:\vcpkg> $env:VCPKG_DEFAULT_BINARY_CACHE=F:/Manifest-Binary/cache

 

2. 使用vcpkg的install命令安装需要的依赖库:

PS F:\vcpkg> ./vcpkg install sqlite3:x64-windows

 

3. 在公共目录 "F:\Manifest-Binary\cache" 下查看vcpkg缓存:

PS F:Manifest-Binary\cache> dir

Directory: G:\binarycaching


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/10/2022 5:24 PM 4f

PS F:\Manifest-Binary\cache>cd 4f
PS F:\Manifest-Binary\cache\4f>dir

Directory: F:\Manifest-Binary\cache\4f


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/10/2022 5:23 PM 3329642 4f95bcae2db85409ba2e8c189788b17c6049ba1d07e51502081c10e159536083.zip

二、开发端主机:

 此示例中开发端主机的CMake工程test2依赖于sqlite3。

1. 在工程文件夹中创建manifest文件并写入依赖内容

文件结构如下 (根目录为 F:/Manifest-Binary):
| --test/
| ----build
| ----CMakeLists.txt
| ----main.cpp
| ----vcpkg.json

 

相应文件内容为:
vcpkg.json

{
    "name": "test2",
    "version-string": "0.0.1",
    "dependencies": [
        "sqlite3"
    ]
}

 

main.cpp

#include <sqlite3.h>
#include <stdio.h>

int main()
{
    printf("%s\n", sqlite3_libversion());
    return 0;
}

 

CMakeLists.txt

cmake_minimum_required(VERSION 3.18)

project(versionstest2 CXX)

add_executable(main main.cpp)

find_package(unofficial-sqlite3 CONFIG REQUIRED)

target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

 

2. Clone vcpkg

PS F:\> git clone https://github.com/microsoft/vcpkg.git
PS F:\> cd vcpkg
PS F:\vcpkg> .\bootstrap-vcpkg.bat
PS F:\vcpkg> .\vcpkg.exe integrate install

Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=F:/vcpkg/scripts/buildsystems/vcpkg.cmake"

All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.

 

3. 配置CMake工程,将Binarycaching参数 "--binarysource=clear;--binarysource=files,F:\\Manifest-Binary\cache,read" 添加到cmake命令行中运行以下命令:

"C:\Program Files\CMake\bin\cmake.exe" .. -G "Visual Studio 16 2019" -A x64 -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=F:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_INSTALL_OPTIONS="--binarysource=clear;--binarysource=files,F:\\Manifest-Binary\cache,read"

输出:

-- Running vcpkg install
Detecting compiler hash for triplet x64-windows...
The following packages will be built and installed:
sqlite3[core]:x64-windows -> 3.39.2
* vcpkg-cmake[core]:x64-windows -> 2022-08-18
* vcpkg-cmake-config[core]:x64-windows -> 2022-02-06#1
Additional packages (*) will be modified to complete this operation.
Restored 1 package(s) from F:\\Manifest-Binary\cache in 120.4 ms. Use --debug to see more details.
Installing 1/3 vcpkg-cmake-config:x64-windows...
Building vcpkg-cmake-config[core]:x64-windows...
-- Installing: F:/vcpkg/packages/vcpkg-cmake-config_x64-windows/share/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
-- Installing: F:/vcpkg/packages/vcpkg-cmake-config_x64-windows/share/vcpkg-cmake-config/vcpkg-port-config.cmake
-- Installing: F:/vcpkg/packages/vcpkg-cmake-config_x64-windows/share/vcpkg-cmake-config/copyright
-- Performing post-build validation
-- Performing post-build validation done
Elapsed time to handle vcpkg-cmake-config:x64-windows: 72.18 ms
Installing 2/3 vcpkg-cmake:x64-windows...
Building vcpkg-cmake[core]:x64-windows...
-- Installing: F:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg_cmake_configure.cmake
-- Installing: F:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg_cmake_build.cmake
-- Installing: F:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg_cmake_install.cmake
-- Installing: F:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/vcpkg-port-config.cmake
-- Installing: F:/vcpkg/packages/vcpkg-cmake_x64-windows/share/vcpkg-cmake/copyright
-- Performing post-build validation
-- Performing post-build validation done
Elapsed time to handle vcpkg-cmake:x64-windows: 116 ms
Installing 3/3 sqlite3:x64-windows...
Elapsed time to handle sqlite3:x64-windows: 52.98 ms

Total elapsed time: 2.706 s
sqlite3 provides CMake targets:

# this is heuristically generated, and may not be correct
find_package(unofficial-sqlite3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

-- Running vcpkg install - done
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The CXX compiler identification is MSVC 19.29.30146.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: F:/Manifest-Binary/test2/build

从上面的构建日志中我们可以看到,开发端主机成功使用了共享路径 "F:\Manifest-Binary\cache" 下已经构建好的sqlite3缓存文件,大大节省了时间。

 

4. 构建CMake工程

"C:\Program Files\CMake\bin\cmake.exe" --build .

输出:

Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Checking Build System
Building Custom Rule F:/Manifest-Binary/test2/CMakeLists.txt
main.cpp
main.vcxproj -> F:\Manifest-Binary\test2\build\Debug\main.exe
Building Custom Rule F:/Manifest-Binary/test2/CMakeLists.txt

 

5. 运行CMake工程

.\Debug\main.exe

输出:

3.39.2

注意:如果想通过Visual Studio在Manifest模式下使用Binarycaching,唯一需要注意的是CMakeSettings.json文件的设置:

{
    "configurations": [
        {
            "name": "x64-Debug",
            "generator": "Visual Studio 16 2019 Win64",
            "configurationType": "Debug",
            "inheritEnvironments": [ "msvc_x64_x64" ],
            "buildRoot": "${projectDir}\\out\\build\\${name}",
            "installRoot": "${projectDir}\\out\\install\\${name}",
            "cmakeCommandArgs": "",
            "buildCommandArgs": "",
            "ctestCommandArgs": "",
            "variables": [
                {
                    "name": "CMAKE_TOOLCHAIN_FILE",
                    "value": "F:/Manifest-Binary/vcpkg/scripts/buildsystems/vcpkg.cmake"
                },
                {
                    "name": "VCPKG_INSTALL_OPTIONS",
                    "value": "--binarysource=clear;--binarysource=\"files,F:/Manifest-Binary/cache,read\""
                }
            ]
        }
    ]
}

 

Msbuild工程使用Manifest和Binarycaching,参考 https://www.cnblogs.com/vcpkg/p/15019899.html

标签:cmake,Binarycaching,--,示例,x64,Manifest,windows,vcpkg
From: https://www.cnblogs.com/vcpkg/p/16791097.html

相关文章

  • 华为AirEngine 5760-22W Web示例(V200R021C00SPC200版本):NAT网关模式(DHCP方式入网)【
    说明:此版本存在一些默认的WLAN无线业务配置,AP上电启动后,默认创建名称为“HUAWEI-XXXX”的SSID,其中XXXX是APMAC地址的后四位。默认无线业务覆盖使用无认证方式,用户搜索到该......
  • Java基于解释器模式实现定义一种简单的语言功能示例
    本文实例讲述了Java基于解释器模式实现定义一种简单的语言功能。分享给大家供大家参考,具体如下:一模式定义解释器模式:就是给定一个语言的文法表示,并且定义一个解释器,用来......
  • C语言怎么使用爬虫ip代码示例
    数据抓取工作必不可少的就是需要海量爬虫ip支持,那么使用爬虫ip怎么配合C语言来运行项目?下列文档的代码可以供大家参考下。#include#include#include#include"curl/curl.......
  • 【精品】seata综合示例:订单-库存-扣款
    有关seata的安装,请参看博客:https://blog.51cto.com/lianghecai/5759100业务需求:下单—减库存—扣钱—改订单状态当用户下单时,会在订单服务中创建一个订单,然后通过远程调用......
  • C Sharp运行使用华科HTTP示例
    CSharp,是2000年6月发布的一种面向对象编程语言。CSHARP拥有C/C++的强大功能以及VisualBasic简易使用的特性,是第一个组件导向(Component-oriented)的程序语言,和C++与Java一......
  • python精灵模块示例代码
    精灵模块是一个基于pygame的游戏模块,可以让我们使用python时轻松实现动画效果和游戏,下面给出一些例子:背景化身弹球.rar:https://url18.ctfile.com/f/7715018-694756249-4ee......
  • linux Traffic Control Configuration example 限速 配置示例 进出双方向
    linuxTrafficControlConfigurationexample限速配置示例进出双方向背景公司的公网是没有限速设备的,导致公网带宽相互抢占,奈何有个大佬业务线说自己的产品架构脆弱,经......
  • 5. CSS注释(附带示例)
    1.前言在代码中合理的添加注释是个非常好的习惯,通过注释您可以对代码加以解释说明(例如描述某段代码的功能、使用方法等),浏览器会自动忽略注释的内容。注释对开发人员非常......
  • nginx负载均衡示例讲解
    有任何问题都可以留言咨询。 常用的几种负载均衡方法1、round-robin轮询方法。默认的负载均衡方法。顾名思义就是循环的一个个来。把应用程序的请求,循环的分发到不......
  • ASP中查询数据库记录写入XML文件示例
    把下面代码保存为Asp_XML.asp运行即可:<%'By Dicky 2005-03-22 21:52:18 AM QQ:25941 E-mail:[email protected] IsSql = ......