仓颉——申请内测、环境搭建、编译测试

2024年6月21日,华为仓颉正式公开发布。

不少同学看过仓颉白皮书后,都在找SDK从哪下载,HelloWorld怎么跑。仓颉公众号也及时发布了内测的方式,我也亲自走了一遍整个流程,

一,申请内测

关注“仓颉编程语言”微信公众号,回复“SDK”关键词,填写内测申请问卷(姓名、邮箱、gitcode地址等)。【建议提前注册gitcode,github可直接授权登录】

接下来就是等待邮件回复,2-3个工作日, 

管理审核成功后,即可访问仓颉社区:仓颉SDKGitCode是面向全球开发者的开源社区,包括原创博客,开源代码托管,代码协作,项目管理等。与开发者社区互动,提升您的研发效率和质量。icon-default.png?t=N7T8https://gitcode.com/Cangjie 仓颉支持VSCode开发环境,社区提供了VSCode插件CangjieVSCodePlugin,以及Linux/Windows/MacOS版本的SDK。 

二,环境搭建

2.1 Windows平台搭建仓颉环境

2.1.1 下载SDK

从你送到的邮箱里面点击Windows版本的仓颉lSDK链接

点击exe或者 zip都行,exe需要安装,zip解压可用

我这里用的zip,直接解压

2.1.2 安装,配置系统环境

2.1.2.1 exe安装

如果你下载的SDK是exe格式,直接点击安装就好,安装时会自动将所需环境变量配置好。

选 all user 

 

 

 

 

2.1.2.2 zip 解压 配置环境变量 (可在IDE中做配置)

我这里的解压到 c:\cangjie\

右键  我的电脑---->属性---->高级系统设置---->环境变量

 

然后找到下方  系统变量---->双击Path

 将 

c:\cangjie\bin

c:\cangjie\tools\bin

c:\cangjie\runtime\lib\windows_x86_64_llvm

c:\cangjie\debugger\bin

添加到环境变量

遇到环境变量超过2047 请参考《解决:此环境变量太大。此对话框允许将值设置为最长2047个字符-CSDN博客》 

然后用 命令行工具测试下 

C:\Users\Administrator>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
  --conditional-compilation-config <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'
    <value>=full
    <value>=thin
  --enable-ad, --enable-auto-differentiation
                              Enables automatic differentiation
  --enable-chir2-devirtualization
                              Enable CHIR 2 devirtualization.
  --enable-opaque             Enable opaque pointer
  --fchir-constant-propagation
                              Enable constant propagation optimizaion in CHIR
  --fno-chir-constant-propagation
                              Disable constant propagation optimizaion in CHIR
  --fchir-function-inlining   Enable function inlining optimizaion in CHIR
  --fno-chir-function-inlining
                              Disable function inlining optimizaion in CHIR
  --fchir-devirtualization    Enable devirtualization optimizaion in CHIR
  --fno-chir-devirtualization Disable devirtualization optimizaion in CHIR
  --sanitizer-coverage-inline-8bit-counters
                              Enable sanitizer-coverage-inline-8bit-counters in CHIR
  --sanitizer-coverage-inline-bool-flag
                              Enable sanitizer-coverage-inline-bool-flag in CHIR
  --sanitizer-coverage-trace-pc-guard
                              Enable sanitizer-coverage-trace-pc-guard in CHIR
  --sanitizer-coverage-pc-table
                              Enable sanitizer-coverage-pc-table in CHIR
  --sanitizer-coverage-stack-depth
                              Enable sanitizer-coverage-stack-depth in CHIR
  --sanitizer-coverage-trace-compares
                              Enable sanitizer-coverage-trace-compares in CHIR
  --sanitizer-coverage-trace-memcmp
                              Enable sanitizer-coverage-trace-memcmp in CHIR
  --sanitizer-coverage-level=0
                              sancov level 0
  --sanitizer-coverage-level=1
                              sancov level 1
  --sanitizer-coverage-level=2
                              sancov 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
  --macro-lib <value>         Options directly passed to macro library, put the value into "" when there is space in it
  --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-compile
                              Enable agrressive parallel compile
  --sanitize <value>          Enable sanitizer:
    <value>=address
    <value>=thread
  --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
  --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

2.2 VS Code  Cangjie插件安装

  1. 这个链接中下载VS Code的插件。下载下来并解压。得到一个Cangjie-0.51.4.vsix文件,之后会用到。

  2. 打开VS Code,如图点击左侧Extensions -> Views and More Actions -> Install from VSIX,找到刚才解压出来的Cangjie-0.51.4.vsix文件。安装成功。

 

 

开发环境搭建完成。 

三,项目创建、编译

3.1 VS Code 创建项目编译运行

在VS Code界面中使用快捷键ctrl + shift + p 

在搜索框里输入关键字搜索Create Cangjie Project并选择 

下一步选择Create CJNative Cangjie Project

选择Create Executable Output Cangjie Project 

在弹出的文件夹选择窗里选择工程存放的目录

回到之前界面,在上方输入框中输入工程的名称,并回车

在左侧目录结构中找到src -> main.cj可以看到默认创建的一段helloworld代码

main.cj 内容 

main(): Int64 {
    println("hello world")
    return 0
}

 cjpm.toml  内容

[dependencies]

[package]
  cjc-version = "0.51.4"
  compile-option = ""
  description = "nothing here"
  link-option = ""
  name = "HelloTest"
  output-type = "executable"
  src-dir = ""
  target-dir = ""
  version = "1.0.0"
  package-configuration = {}

 

代码 main.cj 我们用中文试试

main() {
	println("你好,仓颉")
}

 运行

汉字编码有问题,暂时的解决方案是运行chcp 65001命令

chcp 65001

再次运行

cjpm run

3.2 txt文本 开发编译测试

main() {
	println("hello cangjie")
}

 编译

cjc hello.cj -o hello.out

参考资料

  1. 仓颉官网:仓颉-鸿蒙原生应用编程语言-华为开发者联盟
  2. 仓颉社区:GitCode - 全球开发者的开源社区,开源代码托管平台
  3. 仓颉编程语言白皮书:文档中心

CJK仓颉输入法数据库是指为仓颉输入法提供收录和管理汉字字符及其相应输入码的数据库。仓颉输入法是一种用于输入中文字符的输入法,它采用了古代汉字字形和笔画的组合规则来生成每个汉字的输入码。输入码是指在键盘上输入的一组字符以唤出对应的汉字。 CJK是指"Chinese, Japanese, Korean" 的缩写,表示支持中日韩三国语言的输入法系统。因为中文输入码的设计能够应用于这三个语言,所以CJK仓颉输入法数据库也用于日语和韩语的输入。 仓颉输入法数据库包含了大量的汉字和其对应的输入码数据。这些数据可以根据仓颉输入法的规则和要求进行生成和维护。数据库中的每个汉字都对应一个输入码,通过输入码的组合方式可以准确地输入出所需的汉字。数据库的管理者会不断收录和更新汉字及其输入码,确保数据库的完整性和实用性。 仓颉输入法数据库的作用非常重要。它是仓颉输入法正常运作的基础,决定了仓颉输入法用户能够输入哪些汉字。数据库中的数据还会随着时间的推移不断增加和完善,以适应新的汉字的加入和使用需求的变化。 总之,CJK仓颉输入法数据库是一个为仓颉输入法提供汉字和输入码数据的数据库,对于保证仓颉输入法的准确性和实用性起到了重要作用。通过合理的管理和维护,该数据库能够为用户提供全面且准确的中文输入服务。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值