Skip to content

Commit

Permalink
Fix C reverse example for dfx 0.6.12. (dfinity#62)
Browse files Browse the repository at this point in the history
Signed-off-by: John Plevyak <[email protected]>
  • Loading branch information
jplevyak authored Oct 21, 2020
1 parent 81fcb3b commit 15f0912
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
18 changes: 12 additions & 6 deletions c/reverse/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ wasm binary with:
Then package the binary so `dfx` can install and run it:

$ echo '{"canisters":{"reverse":{"main":"reverse"}}}' > dfx.json
$ mkdir build
$ mkdir build/reverse
$ cp reverse.wasm build/reverse/
$ head -c 8 /dev/urandom > build/reverse/_canister.id

The script `build.sh` performs the above steps.

To test the app, run `dfx start` in another terminal, then:

$ dfx canister create reverse
$ cp reverse.wasm .dfx/local/canisters/
$ dfx canister install --all
$ dfx canister call reverse go --type string repaid
$ dfx canister call reverse go '("repaid")'

Ignoring the error message about a missing ".did" file, we see:
The script `start.sh` performs the above steps.

We see:

("diaper")

To stop and delete the canister:

$ dfx canister stop --all
$ dfx canister delete --all

The script `stop.sh` performs the above steps.
6 changes: 2 additions & 4 deletions c/reverse/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env bash
set -e
wld="wasm-ld-8 --no-entry --export-dynamic --allow-undefined"
wcc="clang-8 --target=wasm32 -c -O3"
wld="wasm-ld --no-entry --export-dynamic --allow-undefined"
wcc="clang --target=wasm32 -c -O3"
$wcc reverse.c
$wld reverse.o -o reverse.wasm
echo '{"canisters":{"reverse":{"main":"src/reverse"}}}' > dfx.json
install -D reverse.wasm build/reverse/reverse.wasm
head -c 8 /dev/urandom > build/reverse/_canister.id
6 changes: 6 additions & 0 deletions c/reverse/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
dfx canister create reverse
cp reverse.wasm .dfx/local/canisters/
dfx canister install --all
dfx canister call reverse go '("repaid")'
2 changes: 1 addition & 1 deletion motoko/echo/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"main": "src/main.mo"
}
},
"dfx": "0.6.10"
"dfx": "0.6.12"
}

0 comments on commit 15f0912

Please sign in to comment.