The extension library stdx is an extension module provided by the Cangjie programming language (i.e., a non-core standard library, but an official supplementary feature set). It is a key component of the language ecosystem, supplementing Cangjie with more practical capabilities covering multiple domains, including aspect-oriented programming, compression and decompression, security (secure encryption capabilities/message digest algorithms/Asymmetric encryption and decryption and signature algorithms/digital certificate processing functions), encoding and decoding (base64/hex/json/url), networking (http/tls), logging, syntax parsing, unit test extensions, concurrent programming model, non-local control operation and serialization.
Architecture Diagram:
- actors: Provides a concurrent programming model designed to simplify the handling of concurrent tasks.
- aspectCJ: Provides annotations related to aspect-oriented programming in Cangjie.
- compress: Provides compression and decompression functions.
- crypto: Provides a utility library for cryptographic operations.
- effect: Provides a powerful non-local control operation.
- encoding: Provides a basic utility library for data encoding and decoding.
- fuzz: Provides an automated software testing method.
- log: Provides a single logging API.
- logger: Provides log printing functions in text format and JSON format.
- net: Provides network communication and secure transmission functions.
- serialization: Provides the capability of serialization and deserialization.
- syntax: Provides Cangjie source code syntax parsing functions.
- unittest: Provides the capability to supply test data in serialized input formats when writing unit test code for Cangjie projects.
For APIs related to stdx, please refer to API Interface Description. For relevant guidance, please refer to Development Guide.
This repository provides convenient scripts to quickly download and extract binary artifacts for a specific version.
This requires curl and unzip. Please ensure these tools are installed in your environment.
Execute directly in your command line (note the arguments at the end, modify as needed):
bash -c "$(curl -fsSL https://raw.gitcode.com/Cangjie/cangjie_stdx/raw/dev/downloader.sh)" -- 1.0.0.1Before running the script, you may need to adjust the PowerShell execution policy (only needs to be done once).
Please open PowerShell as an administrator and run the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserThen, run the script in a regular PowerShell window (note the arguments at the end, modify as needed):
irm https://raw.gitcode.com/Cangjie/cangjie_stdx/raw/dev/downloader.ps1 -OutFile "$env:TEMP\downloader.ps1"; & "$env:TEMP\downloader.ps1" 1.0.0.1<version>: Required. Specifies the version to download, e.g.,1.0.0.1.-p <platform-arch>: Optional. Specifies the platform and architecture. If omitted, the script will auto-detect the current system.-d <extract-dir>: Optional. Specifies the target path for extraction. If omitted, it defaults to the current directory.
Usage Examples:
# On Linux/macOS, download the ohos-aarch64 version of v1.0.0.1 and extract it to the ./cangjie_libs directory
bash -c "$(curl -fsSL https://raw.gitcode.com/Cangjie/cangjie_stdx/raw/dev/downloader.sh)" -- 1.0.0.1 -p ohos-aarch64 -d ./cangjie_libs# On Windows, download the windows-x64 version of v1.0.0.1 and extract it to the C:\cangjie_libs directory
irm https://raw.gitcode.com/Cangjie/cangjie_stdx/raw/dev/downloader.ps1 -OutFile "$env:TEMP\downloader.ps1"; & "$env:TEMP\downloader.ps1" 1.0.0.1 -p windows-x64 -d C:\cangjie_libsThe following platform and architecture combinations are currently supported:
linux-aarch64linux-x64mac-aarch64mac-x64ohos-aarch64ohos-x64windows-x64
/stdx
├─ build # Directory of Engineering Construction
├─ doc # Directory of STDX library document
├─ figures # architecture pictures
├─ src # Directory of STDX package codes
│ └─ stdx
│ ├── actors # Provides Actors
│ ├── aspectCJ # Provides AOP
│ ├── compress # Provides compression and decompression
│ ├── crypto # Provide security related capabilities
│ ├── effect # Provides user-level APIs for handling the Effect Handler feature. This is an experimental feature and requires the use of a Cangjie compiler that supports this mechanism.
│ ├── dynamicLoader # Openssl dynamic loading module
│ ├── encoding # Provide JSON and string encoding related capabilities
│ ├── fuzz # Provides the Cangjie fuzz engine based on coverage feedback
│ ├── log # Provides logging related
│ ├── logger # Provides log printing functions in text format and JSON format
│ ├── net # Provide network communication and other capabilities
│ ├── serialization # Provides serialization and deserialization
│ ├── syntax # Provides syntax parsing functions
│ └── unittest # Provides unit testing extension
│
├─ third_party # Directory of third-party components
└─ target # Directory of constructed products
Support for building stdx in Ubuntu/MacOS (x86_64, aarch64), Cangjie SDK 1.0.0 and above versions, please refer to the Build Dependency Tools.
Note: Future versions of this extension library may contain incompatible changes, and cross-version backward compatibility is not guaranteed. Please fully assess the version adaptation risks before use.
Configure the Cangjie SDK environment:
source <cangjie sdk path>Execute the following command to verify whether the installation is successful:
cjc -vDownload the source code
git clone https://gitcode.com/Cangjie/cangjie_stdx.gitEnter the project directory, and run the following commands:
python3 build.py clean
python3 build.py build -t release --target-lib=<absolute path of openssl lib>
python3 build.py install-
build.py cleancommand is used to clear temporary files in the workspace. -
build.py buildcommand starts the compilation:-tor--build-type,specifies the type of build artifact, which can be eitherreleaseordebug--target-libspecifies the openssl lib directory
-
build.py installommand installs the build artifacts to theoutputdirectory.
If the compilation is successful, a product directory named target by default will be obtained in the project directory.
For more information, please take a look at the build.py or use --help
For integration building, please refer to the Cangjie SDK Integration Build Guide.
stdx provides two types of binaries: static and dynamic. Both are used independently and developers can reference them according to actual conditions.
Add the following configuration to the cjpm.toml file of the code project:
[target.x86_64-w64-mingw32] # System architecture and OS information
[target.x86_64-w64-mingw32.bin-dependencies]
path-option = ["D:\\cangjiestdx\\windows_x86_64_cjnative\\stdx\\dynamic\\stdx"] # The stdx path is configured according to the actual situationexplain:
-
x86_64-w64-mingw32:This configuration item indicates the operating system architecture information of the machine where the code is compiled. This information can be obtained by executing
cjc -v. Developers should configure according to the actual situation. For example, the output of executingcjc -vis as follows, and the configuration isx86_64-w64-mingw32.Cangjie Compiler: 0.59.4 (cjnative) Target: x86_64-w64-mingw32 -
x86_64-w64-mingw32.bin-dependencies:Please replace x86_64-w64-mingw32 in the configuration with the actual operating system information.
-
path-option:
stdxThe path where the binary is located.
illustrate:
cjpm.tomlis the configuration file of the Cangjie package management tool CJPM. For details, please refer to the Cangjie Programming Language Tool User Guide.- The configuration method is the same for Windows, Linux, and MacOS.
- If you import the static library of
stdxand use the crypto and net packages, you need to add-lcrypt32to thecompile-optionconfiguration item ofcjpm.tomlunder theWindowsoperating system, and-ldlunder theLinuxoperating system, because they need to rely on system symbols.
Configuration example:Assuming the development environment is Windows x86_64, import the dynamic binary of stdx, then the cjpm.toml configuration example is as follows:
[dependencies]
[package]
cjc-version = "0.59.4"
compile-option = ""
description = "nothing here"
link-option = ""
name = "test"
output-type = "executable"
override-compile-option = ""
src-dir = ""
target-dir = ""
version = "1.0.0"
package-configuration = {}
[target.x86_64-w64-mingw32] # System architecture and OS information
[target.x86_64-w64-mingw32.bin-dependencies]
path-option = ["D:\\cangjiestdx\\windows_x86_64_cjnative\\stdx\\dynamic\\stdx"] # The stdx path is configured according to the actual situationIn the Cangjie source code file that needs to use stdx, import the corresponding package provided by stdx through import, and then call the API provided by the package. The import format is:
import stdx.fullPackageName.itemName
fullPackageName is the package name given in package list, itemName is the name of a visible declaration or definition, * means importing all visible top-level declarations or definitions, for example:
- import stdx.net.http.ServerBuilder:Import the top-level declaration of ServerBuilder in the net.http package of the stdx module.
- import stdx.net.http.* :Import the net.http package of the stdx module.
- import stdx.log.* :Import the log package from the stdx module.
Assuming that the developer is developing on Linux and wants to import the static binary of stdx, the cjpm.toml configuration reference is as follows:
[dependencies]
[package]
cjc-version = "0.59.4"
compile-option = "-ldl"
description = "nothing here"
link-option = ""
name = "test"
output-type = "executable"
src-dir = ""
target-dir = ""
version = "1.0.0"
package-configuration = {}
[target.x86_64-unknown-linux-gnu]
[target.x86_64-unknown-linux-gnu.bin-dependencies]
path-option = ["/target/linux_x86_64_cjnative/static/stdx"] # stdx path is configured according to actual situationWrite code: Create an HTTP service using the net.http package.
package test
import stdx.net.http.ServerBuilder
main () {
// 1. Build a Server instance
let server = ServerBuilder()
.addr("127.0.0.1")
.port(8080)
.build()
// 2. Register HttpRequestHandler
server.distributor.register("/index", {httpContext =>
httpContext.responseBuilder.body("Hello 仓颉!")
})
// 3. Start the service
server.serve()
}
Please see LICENSE for more information.
Developers are welcome to make contributions in any form, including but not limited to code, documentation, and issues.