Skip to content

Commit

Permalink
Update: Support for Compiler 2.0.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptonerdcn committed Jul 17, 2023
1 parent b484130 commit 4b5074f
Show file tree
Hide file tree
Showing 9 changed files with 8,681 additions and 3,314 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,37 @@ jobs:
- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache

- name: Cairo Verify
uses: ./.github/workflows/cairo-verify

- name: Install mdbook
uses: ./.github/workflows/install-mdbook

- name: Build in English
run: |
mdbook build -d book
- name: Copy WASM-Cairo pkg
run: |
cp -r theme/pkg book/html
cp -r theme/js book/html
cp -r theme/pkg book
cp -r theme/js book
- name: Build all translations
run: |
for po_lang in $(cat ./LANGUAGES); do
echo "::group::Building $po_lang translation"
MDBOOK_BOOK__LANGUAGE=$po_lang \
mdbook build -d book/$po_lang
mv book/$po_lang/html book/html/$po_lang
echo "::endgroup::"
done
# - name: Verify Cairo programs
# uses: ./.github/workflows/verify-cairo-programs
- name: Copy WASM-Cairo pkg
run: |
for po_lang in $(cat ./LANGUAGES); do
echo "::group::Copy WASM-Cairo pkg to $po_lang/html"
cp -r theme/pkg book/html/$po_lang
cp -r theme/js book/html/$po_lang
echo "::endgroup::"
done
- name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./book/html
path: ./book

- name: Deploy to GitHub Pages
id: deployment
Expand Down
8 changes: 4 additions & 4 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ title = "The Cairo Programming Language"
[build]
extra-watch-dirs = ["po"]

[preprocessor.gettext]
[preprocessor.cairo]
after = ["links"]

[preprocessor.gettext]
after = ["cairo"]

[output.html]
git-repository-url = "https://github.com/cairo-book/cairo-book.github.io/"
edit-url-template = "https://github.com/cairo-book/cairo-book.github.io/edit/main/{path}"
playground.runnable = true

[output.cairo]
output-dir = "cairo-programs"
11,831 changes: 8,545 additions & 3,286 deletions po/zh-cn.po

Large diffs are not rendered by default.

87 changes: 82 additions & 5 deletions theme/pkg/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,87 @@
<div align="center">

<h1><code>WASM-CAIRO</code></h1>
<h1><code>WASM-Cairo</code></h1>

<strong>A Cairo Webassembly Project.</strong>
<strong>A suite of development tools and an environment for Cairo 1.10, all based on WebAssembly.</strong>

<p>
By CryptonerCN@StarknetAstro
</p>
<sub>Built with 🦀🕸 by <a href="https://twitter.com/cryptonerdcn">cryptonerdcn from Starknet Astro</a></sub>
</div>


## 🚴 Usage


### 🛠️ Build WASM-bindgen's WASM-Cairo Toolkit
With Modules

```
wasm-pack build --release --target --out-dir ./pkg
```

No Modules

```
wasm-pack build --release --target no-modules --out-dir ./pkg
```

You will find `wasm-cairo_bg.wasm` and `wasm-cairo.js` in `pkg` folder.


### 🛠️ Build Astro Editor

```
wasm-pack build --release --target no-modules --out-dir ./dist/pkg --out-name wasm-cairo
```

Then run
```
node app.js
```
For local web instance.

### 🛠️ Build WASMTIME's WASM-Cairo Toolkit

```
cargo build --target wasm32-wasi --release
```

You can test it by using:

Compile Cairo

```
./wasmtime_test.sh compileCairoProgram ./cairo_files/HelloStarknetAstro.cairo ./cairo_files/HelloStarknetAstro.sierra
```

Run
```
./wasmtime_test.sh runCairoProgram ./cairo_files/HelloStarknetAstro.cairo
```

Compile Contract

```
./wasmtime_test.sh compileStarknetContract ./cairo_files/erc20.cairo ./cairo_files/erc20.json
```

## 🔋 Batteries Included

* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
between WebAssembly and JavaScript.
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
for logging panic messages to the developer console.
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
for small code size.
* [`Cairo`](https://github.com/starkware-libs/cairo) for Cairo-lang support.
* `LICENSE-APACHE` and `LICENSE-MIT`: most Rust projects are licensed this way, so these are included for you

## License

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)

### Contribution

Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.
2 changes: 1 addition & 1 deletion theme/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"collaborators": [
"cryptonerdcn <cryptonerdcn@gmail.com>"
],
"version": "0.1.0",
"version": "0.2.1",
"files": [
"wasm-cairo_bg.wasm",
"wasm-cairo.js",
Expand Down
7 changes: 7 additions & 0 deletions theme/pkg/wasm-cairo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ declare namespace wasm_bindgen {
* @returns {string}
*/
export function runCairoProgram(cairo_program: string, available_gas: number | undefined, print_full_memory: boolean, use_dbg_print_hint: boolean): string;
/**
* @param {string} starknet_contract
* @param {boolean} replace_ids
* @returns {string}
*/
export function compileStarknetContract(starknet_contract: string, replace_ids: boolean): string;

}

Expand All @@ -30,6 +36,7 @@ declare interface InitOutput {
readonly greet: (a: number, b: number, c: number) => void;
readonly compileCairoProgram: (a: number, b: number, c: number, d: number) => void;
readonly runCairoProgram: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
readonly compileStarknetContract: (a: number, b: number, c: number, d: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
Expand Down
34 changes: 33 additions & 1 deletion theme/pkg/wasm-cairo.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ __exports.runCairoProgram = function(cairo_program, available_gas, print_full_me
}
};

/**
* @param {string} starknet_contract
* @param {boolean} replace_ids
* @returns {string}
*/
__exports.compileStarknetContract = function(starknet_contract, replace_ids) {
let deferred3_0;
let deferred3_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(starknet_contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.compileStarknetContract(retptr, ptr0, len0, replace_ids);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var r2 = getInt32Memory0()[retptr / 4 + 2];
var r3 = getInt32Memory0()[retptr / 4 + 3];
var ptr2 = r0;
var len2 = r1;
if (r3) {
ptr2 = 0; len2 = 0;
throw takeObject(r2);
}
deferred3_0 = ptr2;
deferred3_1 = len2;
return getStringFromWasm0(ptr2, len2);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
}
};

async function __wbg_load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
Expand Down Expand Up @@ -233,7 +265,7 @@ async function __wbg_load(module, imports) {
function __wbg_get_imports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbg_log_5e41872ca2982e37 = function(arg0, arg1) {
imports.wbg.__wbg_log_65d0b624a75fcb22 = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};

Expand Down
Binary file modified theme/pkg/wasm-cairo_bg.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions theme/pkg/wasm-cairo_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const memory: WebAssembly.Memory;
export function greet(a: number, b: number, c: number): void;
export function compileCairoProgram(a: number, b: number, c: number, d: number): void;
export function runCairoProgram(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
export function compileStarknetContract(a: number, b: number, c: number, d: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
Expand Down

0 comments on commit 4b5074f

Please sign in to comment.