当前位置:   article > 正文

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

仓颉sdk

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博客》 

然后用 命令行工具测试下 

  1. C:\Users\Administrator>cjc --help
  2. Usage:
  3. cjc [option] file...
  4. Options:
  5. --diagnostic-format <value> Diagnostic format. Candidate modes:
  6. <value>=json
  7. <value>=noColor
  8. <value>=default
  9. --scan-dependency Get the package(s) which the current package depends on
  10. --conditional-compilation-config <value>
  11. User defined contion to compile
  12. --debug-macro Enable debug macro
  13. --parallel-macro-expansion Enable parallel macro expansion
  14. -g Enable compile debug version target
  15. --trimpath <value> Remove a specified path prefix in debuginfo
  16. -s, --strip-all Strip the symbol table from executable and dynamic library
  17. --test Enable compile test
  18. --mock <value> Specify whether mock features are enabled, or disabled, or a runtime exception is thrown when trying to use mock features
  19. <value>=on
  20. <value>=off
  21. <value>=runtime-error
  22. -o, --output <value> Specify product name or output directory when compiling a package
  23. --output-dir <value> Specify output directory (it affects '--output' option)
  24. --static-std Statically link packages of the std module
  25. --dy-std Dynamically link packages of the std module
  26. --static-libs Statically link packages of other modules except std
  27. --dy-libs Dynamically link packages of other modules except std
  28. --lto <value> Enable LTO to either 'full' or 'thin'
  29. <value>=full
  30. <value>=thin
  31. --enable-ad, --enable-auto-differentiation
  32. Enables automatic differentiation
  33. --enable-chir2-devirtualization
  34. Enable CHIR 2 devirtualization.
  35. --enable-opaque Enable opaque pointer
  36. --fchir-constant-propagation
  37. Enable constant propagation optimizaion in CHIR
  38. --fno-chir-constant-propagation
  39. Disable constant propagation optimizaion in CHIR
  40. --fchir-function-inlining Enable function inlining optimizaion in CHIR
  41. --fno-chir-function-inlining
  42. Disable function inlining optimizaion in CHIR
  43. --fchir-devirtualization Enable devirtualization optimizaion in CHIR
  44. --fno-chir-devirtualization Disable devirtualization optimizaion in CHIR
  45. --sanitizer-coverage-inline-8bit-counters
  46. Enable sanitizer-coverage-inline-8bit-counters in CHIR
  47. --sanitizer-coverage-inline-bool-flag
  48. Enable sanitizer-coverage-inline-bool-flag in CHIR
  49. --sanitizer-coverage-trace-pc-guard
  50. Enable sanitizer-coverage-trace-pc-guard in CHIR
  51. --sanitizer-coverage-pc-table
  52. Enable sanitizer-coverage-pc-table in CHIR
  53. --sanitizer-coverage-stack-depth
  54. Enable sanitizer-coverage-stack-depth in CHIR
  55. --sanitizer-coverage-trace-compares
  56. Enable sanitizer-coverage-trace-compares in CHIR
  57. --sanitizer-coverage-trace-memcmp
  58. Enable sanitizer-coverage-trace-memcmp in CHIR
  59. --sanitizer-coverage-level=0
  60. sancov level 0
  61. --sanitizer-coverage-level=1
  62. sancov level 1
  63. --sanitizer-coverage-level=2
  64. sancov level 2
  65. --sanitizer-coverage-level <value>
  66. Set sanitizer-coverage level
  67. --int-overflow <value> Specify default integer overflow strategy:
  68. <value>=throwing
  69. <value>=wrapping
  70. <value>=saturating
  71. --fast-math Enable fast-math mode
  72. --link-options <value> Options directly passed to linker
  73. -L, --library-path <value> Add directory to library search path
  74. -l, --library <value> Link library
  75. -B, --toolchain <value> Use toolchain binaries and object files at the given directory
  76. --target <value> Generate code for the given target platform
  77. --target-cpu <value> Generate instructions for the given target processor (Experimental)
  78. --sysroot <value> Set the system root directory under which bin, lib and include can be found
  79. --output-type <value> Specify output file type
  80. <value>=exe emit executable (default)
  81. <value>=staticlib emit static library
  82. <value>=dylib emit dynamic library
  83. -O0 Optimization level 0 (default)
  84. -O, -O1 Optimization level 1
  85. -O2 Optimization level 2
  86. -Os Optimization level s, like -O2 with extra optimizations for size
  87. -Oz Optimization level z, like -Os but reduces code size further
  88. -O<value> Set Optimization level
  89. --module-name <value> Tell compiler name of the module
  90. -p, --package Specify package directory to be compiled
  91. --import-path <value> Add .cjo search path
  92. --incremental-compile Enable incremental compilation.
  93. --save-temps <value> Save intermediate compilation results. <value>: path to save temp files.
  94. -Woff, --warn-off <value> Suppress a specific group of warning
  95. <value>=all
  96. <value>=unused
  97. <value>=driver-arg
  98. <value>=deprecated
  99. <value>=unsupport-compile-source
  100. <value>=package-import
  101. <value>=parser
  102. <value>=semantics
  103. <value>=interpreter
  104. -Won, --warn-on <value> Report a specific group of warning
  105. <value>=all
  106. <value>=unused
  107. <value>=driver-arg
  108. <value>=deprecated
  109. <value>=unsupport-compile-source
  110. <value>=package-import
  111. <value>=parser
  112. <value>=semantics
  113. <value>=interpreter
  114. --error-count-limit <value> Emit specified <number> of errors only. Available options: all, <number> (8 by default)
  115. -V, --verbose Enable verbose
  116. -v, --version Print compiler version information
  117. -h, --help Show usage
  118. --macro-lib <value> Options directly passed to macro library, put the value into "" when there is space in it
  119. --compile-macro Options to compile the macro define package
  120. --coverage Enable coverage
  121. --experimental Enable experimental options
  122. -j, --jobs <value> Number of tasks to run at once
  123. --apc, --aggressive-parallel-compile
  124. Enable agrressive parallel compile
  125. --sanitize <value> Enable sanitizer:
  126. <value>=address
  127. <value>=thread
  128. --fobf-string Enable string literal obfuscation
  129. --fno-obf-string Disable string literal obfuscation
  130. --fobf-const Enable constant literal obfuscation
  131. --fno-obf-const Disable constant literal obfuscation
  132. --fobf-layout Enable code layout obfuscation
  133. --fno-obf-layout Disable code layout obfuscation
  134. --fobf-cf-flatten Enable control flow flatten obfuscation
  135. --fno-obf-cf-flatten Disable control flow flatten obfuscation
  136. --fobf-cf-bogus Enable control flow bogus obfuscation
  137. --fno-obf-cf-bogus Disable control flow bogus obfuscation
  138. --fobf-all Enable all obfuscations
  139. --obf-config <value> Specify obfuscation configure file
  140. --obf-level <value> Specify obfuscation level. Available value: 1 to 10 (5 by default)
  141. --obf-seed <value> Specify random seed for obfuscation algorithm. Available value: <number>
  142. --disable-reflection Disable reflection
  143. --stack-trace-format <value>
  144. Specify stack trace format
  145. <value>=default
  146. <value>=simple
  147. <value>=all
  148. --pgo-instr-gen PGO instrumentation
  149. --pgo-instr-use <value> Read PGO instrumentation profile
  150. --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 内容 

  1. main(): Int64 {
  2. println("hello world")
  3. return 0
  4. }

 cjpm.toml  内容

  1. [dependencies]
  2. [package]
  3. cjc-version = "0.51.4"
  4. compile-option = ""
  5. description = "nothing here"
  6. link-option = ""
  7. name = "HelloTest"
  8. output-type = "executable"
  9. src-dir = ""
  10. target-dir = ""
  11. version = "1.0.0"
  12. package-configuration = {}

 

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

  1. main() {
  2. println("你好,仓颉")
  3. }

 运行

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

chcp 65001

再次运行

cjpm run

3.2 txt文本 开发编译测试

  1. main() {
  2. println("hello cangjie")
  3. }

 编译

cjc hello.cj -o hello.out

参考资料

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/1009890
推荐阅读
相关标签
  

闽ICP备14008679号