-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update dfinity for "Hello, {name}!" Wasm * Update actorscript * Extract copying assets for use in multiple places * Make executable assets available in shell.nix * Add start command * Use nix store path for assets * Add conversion from serde_cbor & serde_json errors * Add build command, examples dir
- Loading branch information
Showing
21 changed files
with
627 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
result* | ||
|
||
# Building | ||
build/ | ||
target/ | ||
|
||
# IDEs | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
[package] | ||
name = "dfx" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
authors = ["DFINITY Team"] | ||
edition = "2018" | ||
build = "assets/build.rs" | ||
|
||
[[bin]] | ||
name = "dfx" | ||
path = "src/main.rs" | ||
|
||
[build-dependencies] | ||
tar = "0.4.26" | ||
flate2 = "1.0.11" | ||
|
||
[dependencies] | ||
clap = "2.33.0" | ||
futures = "0.1" | ||
reqwest = "0.9" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_bytes = "0.11" | ||
serde_cbor = "0.10" | ||
serde_repr = "0.1" | ||
console = "0.7.7" | ||
flate2 = "1.0.11" | ||
futures = "0.1.28" | ||
reqwest = "0.9.20" | ||
serde = "1.0" | ||
serde_bytes = "0.11.2" | ||
serde_cbor = "0.10.1" | ||
serde_repr = "0.1.5" | ||
serde_json = "1.0.40" | ||
tar = "0.4.26" | ||
tokio = "0.1" | ||
|
||
[dev-dependencies] | ||
env_logger = "0.6" | ||
mockito = "0.20" | ||
mockito = "0.20.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
= Assets | ||
|
||
The `files/` directory contains all the files of a new project. This is tar gzipped at build time | ||
and injected into the binary. | ||
|
||
The following strings are replaced: | ||
|
||
- `{project_name}` => the project name. | ||
- `{dfx_version}` => the DFX version used to create the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use flate2::write::GzEncoder; | ||
use flate2::Compression; | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::Path; | ||
|
||
fn add_assets(f: &mut File, path: &str) -> () { | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let tgz_path = Path::new(&out_dir).join(format!("{}.tgz", path)); | ||
let tar_gz = File::create(&tgz_path).unwrap(); | ||
let enc = GzEncoder::new(tar_gz, Compression::default()); | ||
let mut tar = tar::Builder::new(enc); | ||
tar.append_dir_all("", path).unwrap(); | ||
|
||
f.write_all( | ||
format!( | ||
" | ||
pub fn assets() -> Result<Archive<GzDecoder<Cursor<Vec<u8>>>>> {{ | ||
let mut v = Vec::new(); | ||
v.extend_from_slice(include_bytes!(\"{path}.tgz\")); | ||
let tar = GzDecoder::new(std::io::Cursor::new(v)); | ||
let archive = Archive::new(tar); | ||
Ok(archive) | ||
}} | ||
", | ||
path = path | ||
) | ||
.as_bytes(), | ||
) | ||
.unwrap(); | ||
} | ||
|
||
fn main() { | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let loader_path = Path::new(&out_dir).join("load_assets.rs"); | ||
let mut f = File::create(&loader_path).unwrap(); | ||
|
||
f.write_all( | ||
b" | ||
use flate2::read::GzDecoder; | ||
use std::io::{Cursor, Result}; | ||
use std::vec::Vec; | ||
use tar::Archive; | ||
", | ||
) | ||
.unwrap(); | ||
|
||
let path = env::var("DFX_ASSETS").unwrap(); | ||
add_assets(&mut f, &path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
actor { | ||
public func main(name : Text) : async Text { | ||
return "Hello, " # name # "!"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"canisters": { | ||
"hello": { | ||
"main": "app/canisters/hello/main.as" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
{ pkgs ? import ../. {} }: | ||
|
||
let dfx = pkgs.dfinity-sdk.dfx; in | ||
|
||
pkgs.mkCiShell { | ||
name = "dfinity-sdk-dfx-env"; | ||
inputsFrom = [ | ||
pkgs.dfinity-sdk.dfx | ||
dfx | ||
]; | ||
DFX_ASSETS = dfx.DFX_ASSETS; | ||
} |
Oops, something went wrong.