Cpp 使用 Conan 包管理工具

前提知识

cmake 的基本流程

1
2
3
mkdir build
cmake -B build -S .         # 相当于 `cmake ..`
cmake --build build -j16    # 相当于 `make -j16`

cmake preset

  • CMakePresets.json: 一般是要 git 跟踪的。
  • CMakeUserPresets.json: 一般是 gitignore 的。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
  "version": 6,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 19,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "make-release",
      "displayName": "Release (Unix Makefiles)",
      "generator": "Unix Makefiles",
      "binaryDir": "${sourceDir}/build/release",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_EXPORT_COMPILE_COMMANDS": true
      }
    },
    {
      "name": "make-debug",
      "displayName": "Debug (Unix Makefiles)",
      "generator": "Unix Makefiles",
      "binaryDir": "${sourceDir}/build/debug",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug",
        "CMAKE_EXPORT_COMPILE_COMMANDS": true
      }
    }
  ],
  "buildPresets": [
    {
      "name": "make-release",
      "configurePreset": "make-release",
      "jobs": 16
    },
    {
      "name": "make-debug",
      "configurePreset": "make-debug",
      "jobs": 16
    }
  ]
}

使用 cmake presets:

记录一次部署lx-Music-Sync-Server

asdf 安装相应版本 go, node

安装 asdf 之后, 安装 go node

1
2
3
4
5
asdf plugin list all
asdf plugin add node

asdf list all nodejs
asdf install nodejs 16.20.2

编译 lx-music-sync-server 并测试

1
2
3
4
5
6
7
8
git clone https://github.com/lyswhut/lx-music-sync-server.git --depth 1
cd lx-music-sync-server

asdf set nodejs 16.20.2
asdf current

npm ci
npm run build

pm2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
npm i -g pm2

cd ~/Workspace/lx-music-sync-server

pm2 restart lx-music-sync-server  # 重启服务
pm2 logs

# lx-music-sync-server 服务开机启动
pm2 save
pm2 startup

测试

config.js:

Rust 的宏

宏的种类

Rust 的宏系统是其强大功能之一,允许你在编译时生成代码。Rust 有两种主要类型的宏:

  1. 声明式宏(Declarative Macros) - 使用 macro_rules! 语法
  2. 过程宏(Procedural Macros) - 更强大也更复杂,分为三种:
    • 自定义派生(#[derive] 宏)
    • 属性式宏
    • 函数式宏

声明式宏

使用 macro_rules! 定义。