Introduction to cjpm

Cangjie Package Manager (CJPM) is an official Cangjie package management tool. It is used to manage and maintain the module system of Cangjie projects, provide a simpler and unified compilation entry, and support customized compilation commands. The package manager automatically manages dependencies to analyze and combine third-party dependencies of multiple versions. Developers do not need to worry about dependency conflicts between multiple versions, greatly reducing their workload. It also provides a custom build mechanism based on the native Cangjie language, allowing developers to add pre-processing and post-processing steps in different build phases. In this way, the build process can be flexibly customized to meet build requirements in different service scenarios.

Basic cjpm Usage

You can run the cjpm -h command to view the main interface. The main interface consists of the following parts from top to bottom: current command description, usage example, available subcommands, available options, and more prompts.

Cangjie Package Manager

Usage:
  cjpm [subcommand] [option]

Available subcommands:
  init             Init a new cangjie module
  check            Check the dependencies
  update           Update cjpm.lock
  tree             Display the package dependencies in the source code
  build            Compile the current module
  run              Compile and run an executable product
  test             Unittest a local package or module
  clean            Clean up the target directory
  publish          Push a module to the repository
  load             Load a module from the repository
  list             Get module list from the repository
  install          Install a cangjie binary
  uninstall        Uninstall a cangjie binary

Available options:
  -h, --help       help for cjpm
  -v, --version    version for cjpm

Use "cjpm [subcommand] --help" for more information about a command.

The cjpm init command is used to initialize a new Cangjie module or workspace. During module initialization, the cjpm.toml file is created in the current folder by default, and the src source code folder is created. The default main.cj file is generated in src. You can run the cjpm init -h command to view the customized parameter initialization function.

Example:

Input: cjpm init
Output: cjpm init success

The cjpm build command is used to build the current Cangjie project. Before running this command, the system checks the dependencies. After the check is passed, the cjc command is called to build the project. Full compilation, incremental compilation, cross compilation, and parallel compilation are supported. You can run the cjpm build -h command to view more compilation functions. The cjpm build -V command is used to print all compilation commands.

Example:

Input: cjpm build -V
Output:
compile package module1.package1: cjc --import-path target -p "src/package1" --output-type=staticlib -o target/release/module1/libmodule1.package1.a
compile package module1: cjc --import-path target -L target/release/module1 -lmodule1.package1 -p "src" --output-type=exe --output-dir target/release/bin -o main

cjpm build success

cjpm.toml Configuration File

The configuration file cjpm.toml is used to configure basic information, dependencies, compilation options, and other related content. The cjpm primarily relies on this file for parsing and execution.

The code in the configuration file is as follows:

[package] # Single-module configuration field, which cannot coexist with the workspace field.
  cjc-version = "0.49.1" # Minimum required version of 'cjc', which is required.
  name = "demo" # Module name and root package name, which are required.
  description = "nothing here" # Description, which is optional.
  version = "1.0.0" # Module version information, which is required.
  compile-option = "" # Additional compilation command option, which is optional.
  link-option = "" # Transparent transmission option of the linker, which is optional and can transparently transmit secure compilation commands.
  output-type = "executable" # Type of the compilation output product, which is required.
  src-dir = ""# Path for storing the source code, which is optional.
  target-dir = ""# Path for storing the product, which is optional.
  package-configuration = {} # Single-package configuration option, which is optional.

[workspace] # Workspace management field, which cannot coexist with the package field.
  members = [] # Workspace member module list, which is required.
  build-members = [] # List of compiled modules in the workspace, which is optional and must be a subset of the member module list.
  test-members = [] # List of test modules in the workspace, which is optional and must be a subset of the compiled module list.
  compile-option = "" # Additional compilation command option applied to all workspace member modules, which is optional.
  link-option = "" # Transparent transmission option of the linker applied to all workspace member modules, which is optional.
  target-dir = ""# Path for storing the product, which is optional.

[dependencies] # Configuration options of source code dependency.
  aoo = { version = "1.0.0" } # Import the central repository dependency.
  boo = "1.1.0"  # Import the central repository dependency.
  coo = { git = "xxx",branch = "dev" , version = "1.0.0"} # Import the `git` dependency.
  doo = { path = "./pro1" ,version = "1.0.0"} # Import the source code dependency.

[test-dependencies] # Dependency configuration options in the test phase. The format is the same as that of dependencies.

[script-dependencies] # Dependency configuration options of the build script. The format is the same as that of dependencies.

[ffi.c] # Import the `c` library dependency.
  clib1.path = "xxx"

[profile] # Configuration items of the command profile
  build = {}
  test = {}
  customized-option = {}

[target.x86_64-unknown-linux-gnu] # Configuration items for isolating the backend from the platform
  compile-option = "value1" # Additional compilation command option, which is applicable to the compilation process of a specific target and the compilation process of specifying the target as the cross compilation target platform. This is optional.
  link-option = "value2" # Transparent transmission option of the linker, which is applicable to the compilation process of a specific target and the compilation process of specifying the target as the cross compilation target platform. This is optional.

[target.x86_64-w64-mingw32.dependencies] # Configuration item applicable to the source code dependency of the corresponding target. This is optional.

[target.x86_64-w64-mingw32.test-dependencies] # Configuration item applicable to the test phase of the corresponding target. This is optional.

[target.cjvm.bin-dependencies] # Cangjie binary library dependency, which is applicable to the compilation process of a specific target and the compilation process of specifying the target as the cross compilation target platform. This is optional.
  path-option = ["./test/pro0", "./test/pro1"]
[target.cjvm.bin-dependencies.package-option]
  "pro0.xoo" = "./test/pro0/pro0.xoo.cjo"
  "pro0.yoo" = "./test/pro0/pro0.yoo.cjo"
  "pro1.zoo" = "./test/pro1/pro1.zoo.cjo"