概述
仓颉编程语言是一款面向全场景智能的新一代编程语言,主打原生智能化、天生全场景、高性能、强安全。主要应用于鸿蒙原生应用及服务应用等场景中,为开发者提供良好的编程体验。
今天,我们介绍一下仓颉语言在Linux mint 22.1上的安装。
下载
- https://cangjie-lang.cn/download
考虑到截止目前为止还没有一个可用的长期稳定版本,所以,我们这里下载半年更新版。
对于PC电脑来说,目前基本上都是x64架构,也称为AMD64架构,所以,我们选择下载Cangjie-0.53.18-linux_x64.tar.gz
。
解压
下载结束以后,我们将其解压到用户目录下的目录.cangjie中。
tar -zxvf Cangjie-0.53.18-linux_x64.tar.gz
mv cangjie ~/.cangjie
配置
解压后的目录结构如下:
lwk@qwfys:~$ ll .cangjie/
total 48
drwxr-x--- 8 lwk lwk 4096 Mar 16 18:10 ./
drwxr-x--- 38 lwk lwk 4096 Mar 16 18:30 ../
drwxr-x--- 2 lwk lwk 4096 Feb 28 2023 bin/
-rwxr-x--- 1 lwk lwk 1458 Feb 28 2023 envsetup.sh*
drwxr-x--- 4 lwk lwk 4096 Feb 28 2023 lib/
drwxr-x--- 4 lwk lwk 4096 Feb 28 2023 modules/
-rwxr-x--- 1 lwk lwk 9078 Feb 28 2023 README.md*
drwxr-x--- 3 lwk lwk 4096 Feb 28 2023 runtime/
drwxr-x--- 4 lwk lwk 4096 Feb 28 2023 third_party/
drwxr-x--- 5 lwk lwk 4096 Feb 28 2023 tools/
lwk@qwfys:~$
envsetup.sh
是一个环境变量初始化脚本,执行命令
source ~/.cangjie/envsetup.sh
以后,在当前会话中,就可以正常使用仓颉的命令行工具了。
为方便每次登录账号以后,系统都能自动帮我们完成仓颉语言环境变量的初始化工作,我们其添加到用户目录的.bashrc
文件的末尾。命令如下:
tee -a ~/.bashrc <<-EOF
export CANGJIE_DIR="$HOME/.cangjie"
[[ -s "$HOME/.cangjie/envsetup.sh" ]] && source "$HOME/.cangjie/envsetup.sh"
EOF
查看
通过上述配置,我们退出当前账号,重新登录一次,就可以正常使用了。
cjc
查看一下cjc命令是否可以正常使用。
lwk@qwfys:~$ cjc --help
Usage:cjc [option] file...Options:--diagnostic-format <value> Diagnostic format. Candidate modes: <value>=json <value>=noColor <value>=default --scan-dependency Get the package(s) which the current package depends on--no-sub-pkg The package doesn't have sub-packages--cfg <value> User defined contion to compile--debug-macro Enable debug macro--parallel-macro-expansion Enable parallel macro expansion-g Enable compile debug version target--trimpath <value> Remove a specified path prefix in debuginfo-s, --strip-all Strip the symbol table from executable and dynamic library--test Enable compile test--mock <value> Specify whether mock features are enabled, or disabled, or a runtime exception is thrown when trying to use mock features<value>=on <value>=off <value>=runtime-error -o, --output <value> Specify product name or output directory when compiling a package--output-dir <value> Specify output directory (it affects '--output' option)--static-std Statically link packages of the std module--dy-std Dynamically link packages of the std module--static-libs Statically link packages of other modules except std--dy-libs Dynamically link packages of other modules except std--lto <value> Enable LTO to either 'full' or 'thin' (Not available for Windows target)<value>=full <value>=thin --profile-compile-time Print time spent of all phases in the compilation--profile-compile-memory Print memory usage of all phases in the compilation--fchir-constant-propagationEnable constant propagation optimizaion in CHIR--fno-chir-constant-propagationDisable constant propagation optimizaion in CHIR--fchir-function-inlining Enable function inlining optimizaion in CHIR--fno-chir-function-inliningDisable function inlining optimizaion in CHIR--fchir-devirtualization Enable devirtualization optimizaion in CHIR--fno-chir-devirtualization Disable devirtualization optimizaion in CHIR--sanitizer-coverage-inline-8bit-countersEnable sanitizer-coverage-inline-8bit-counters in CHIR--sanitizer-coverage-inline-bool-flagEnable sanitizer-coverage-inline-bool-flag in CHIR--sanitizer-coverage-trace-pc-guardEnable sanitizer-coverage-trace-pc-guard in CHIR--sanitizer-coverage-pc-tableEnable sanitizer-coverage-pc-table in CHIR--sanitizer-coverage-stack-depthEnable sanitizer-coverage-stack-depth in CHIR--sanitizer-coverage-trace-comparesEnable sanitizer-coverage-trace-compares in CHIR--sanitizer-coverage-trace-memcmpEnable sanitizer-coverage-trace-memcmp in CHIR--sanitizer-coverage-level=0sancov level 0--sanitizer-coverage-level=1sancov level 1--sanitizer-coverage-level=2sancov level 2--sanitizer-coverage-level <value>Set sanitizer-coverage level--int-overflow <value> Specify default integer overflow strategy: <value>=throwing <value>=wrapping <value>=saturating --fast-math Enable fast-math mode--link-options <value> Options directly passed to linker-L, --library-path <value> Add directory to library search path-l, --library <value> Link library-B, --toolchain <value> Use toolchain binaries and object files at the given directory--target <value> Generate code for the given target platform--target-cpu <value> Generate instructions for the given target processor (Experimental)--sysroot <value> Set the system root directory under which bin, lib and include can be found--output-type <value> Specify output file type<value>=exe emit executable (default)<value>=staticlib emit static library<value>=dylib emit dynamic library-O0 Optimization level 0 (default)-O, -O1 Optimization level 1-O2 Optimization level 2-Os Optimization level s, like -O2 with extra optimizations for size-Oz Optimization level z, like -Os but reduces code size further-O<value> Set Optimization level--module-name <value> Tell compiler name of the module-p, --package Specify package directory to be compiled--import-path <value> Add .cjo search path--incremental-compile Enable incremental compilation.--save-temps <value> Save intermediate compilation results. <value>: path to save temp files.-Woff, --warn-off <value> Suppress a specific group of warning<value>=all <value>=unused <value>=driver-arg <value>=deprecated <value>=unsupport-compile-source <value>=package-import <value>=parser <value>=semantics <value>=interpreter -Won, --warn-on <value> Report a specific group of warning<value>=all <value>=unused <value>=driver-arg <value>=deprecated <value>=unsupport-compile-source <value>=package-import <value>=parser <value>=semantics <value>=interpreter --error-count-limit <value> Emit specified <number> of errors only. Available options: all, <number> (8 by default)-V, --verbose Enable verbose-v, --version Print compiler version information -h, --help Show usage--compile-macro Options to compile the macro define package--coverage Enable coverage--experimental Enable experimental options-j, --jobs <value> Number of tasks to run at once--apc, --aggressive-parallel-compileEnable agrressive parallel compile--fobf-string Enable string literal obfuscation--fno-obf-string Disable string literal obfuscation--fobf-const Enable constant literal obfuscation--fno-obf-const Disable constant literal obfuscation--fobf-layout Enable code layout obfuscation--fno-obf-layout Disable code layout obfuscation--fobf-cf-flatten Enable control flow flatten obfuscation--fno-obf-cf-flatten Disable control flow flatten obfuscation--fobf-cf-bogus Enable control flow bogus obfuscation--fno-obf-cf-bogus Disable control flow bogus obfuscation--fobf-all Enable all obfuscations--fobf-export-symbols Obfuscate export symbols when layout obfuscation is enabled--fno-obf-export-symbols Don't obfuscate export symbols when layout obfuscation is enabled--obf-sym-input-mapping <value>Specify the input files of symbol mapping for layout obfuscation--obf-sym-output-mapping <value>Specify the output file of symbol mapping for layout obfuscation--obf-apply-mapping-file <value>Supply user-defined symbol mapping file for layout obfuscation--obf-sym-prefix <value> Specify the prefix of obfuscated symbols for layout obfuscation--fobf-source-path Obfuscate source path of symbols when layout obfuscation is enabled--fno-obf-source-path Don't obfuscate source path of symbols when layout obfuscation is enabled--fobf-line-number Obfuscate line number of symbols when layout obfuscation is enabled--fno-obf-line-number Don't obfuscate line number of symbols when layout obfuscation is enabled--obf-config <value> Specify obfuscation configure file--obf-level <value> Specify obfuscation level. Available value: 1 to 10 (5 by default)--obf-seed <value> Specify random seed for obfuscation algorithm. Available value: <number>--disable-reflection Disable reflection--stack-trace-format <value>Specify stack trace format<value>=default <value>=simple <value>=all --pgo-instr-gen PGO instrumentation--pgo-instr-use <value> Read PGO instrumentation profile--discard-eh-frame Discard the eh_frame section
lwk@qwfys:~$
lwk@qwfys:~$ cjpm --help
Cangjie Package ManagerUsage:cjpm [subcommand] [option]Available subcommands:init Init a new cangjie modulecheck Check the dependenciesupdate Update cjpm.locktree Display the package dependencies in the source codebuild Compile the current modulerun Compile and run an executable producttest Unittest a local package or moduleclean Clean up the target directoryinstall Install a cangjie binaryuninstall Uninstall a cangjie binaryAvailable options:-h, --help help for cjpm-v, --version version for cjpmUse "cjpm [subcommand] --help" for more information about a command.
lwk@qwfys:~$
cjpm
我们再来查看一下命令cjpm是否可以正常使用:
lwk@qwfys:~$ cjpm --help
Cangjie Package ManagerUsage:cjpm [subcommand] [option]Available subcommands:init Init a new cangjie modulecheck Check the dependenciesupdate Update cjpm.locktree Display the package dependencies in the source codebuild Compile the current modulerun Compile and run an executable producttest Unittest a local package or moduleclean Clean up the target directoryinstall Install a cangjie binaryuninstall Uninstall a cangjie binaryAvailable options:-h, --help help for cjpm-v, --version version for cjpmUse "cjpm [subcommand] --help" for more information about a command.
lwk@qwfys:~$
小结
今天我们带领大家完成了仓颉语言运行时环境的在Linux mint 22.1上的安装。以下几点,大家需要着重注意:
- 版本
从实践角度来说,我们在生产环境始终需要注意的就是安装长期维护版,即LTS。由于截止目前为止,LTS还没有发布,所以这时暂且安装半年维护版。
- cjpm
仓颉语言提供了仓颉包管理工具cjpm
,日后,关于仓颉包管理就可以借助它管理起来。这个包管理工具日后与npm、pip、canda是类似的。