From 4faa02c2487f07cf6d5da1c67a43c8bde11cc801 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 15 Jul 2020 15:28:23 -0700 Subject: [PATCH 1/2] build: use moc to build distributed canisters; move canister source into a single dir --- assets-minimal.nix | 21 -------- assets.nix | 11 ++-- default.nix | 7 +-- dfx-minimal.nix | 29 ---------- distributed-canisters.nix | 53 ++++++++----------- .../{assetstorage => }/assetstorage.mo | 0 src/distributed/assetstorage/dfx.json | 20 ------- 7 files changed, 31 insertions(+), 110 deletions(-) delete mode 100644 assets-minimal.nix delete mode 100644 dfx-minimal.nix rename src/distributed/{assetstorage => }/assetstorage.mo (100%) delete mode 100644 src/distributed/assetstorage/dfx.json diff --git a/assets-minimal.nix b/assets-minimal.nix deleted file mode 100644 index bc33c1fe17..0000000000 --- a/assets-minimal.nix +++ /dev/null @@ -1,21 +0,0 @@ -# We need to build some canisters with dfx and include them in $DFX_ASSETS. -# However, dfx needs some of the contents of $DFX_ASSETS in order to build -# even the simplest canister. -# This derivation provides the minimal assets required to build canisters -# that use the base library and do not have a frontend. -{ pkgs ? import ./nix {} -}: -pkgs.runCommandNoCCLocal "assets-minimal" { - inherit (pkgs.motoko) didc rts; - moc = pkgs.motoko.moc-bin; - base = pkgs.motoko.base-src; -} '' - mkdir -p $out - - cp $moc/bin/moc $out - cp $didc/bin/didc $out - cp $rts/rts/mo-rts.wasm $out - - mkdir $out/base - cp -R $base/. $out/base -'' diff --git a/assets.nix b/assets.nix index 4cc512c04e..03e1ee565c 100644 --- a/assets.nix +++ b/assets.nix @@ -1,18 +1,19 @@ { pkgs ? import ./nix {} , agent-js ? import ./src/agent/javascript { inherit pkgs; } , bootstrap-js ? import ./src/bootstrap { inherit pkgs agent-js; } -, assets-minimal ? import ./assets-minimal.nix { inherit pkgs; } -, distributed-canisters ? import ./distributed-canisters.nix { inherit pkgs assets-minimal; } +, distributed-canisters ? import ./distributed-canisters.nix { inherit pkgs; } }: pkgs.runCommandNoCCLocal "assets" {} '' mkdir -p $out - cp -R ${assets-minimal}/* $out - cp ${pkgs.dfinity.ic-replica}/bin/replica $out cp ${pkgs.dfinity.ic-starter}/bin/ic-starter $out - cp ${pkgs.motoko.mo-ide}/bin/mo-ide $out + cp -R ${pkgs.motoko.base-src} $out/base + cp ${pkgs.motoko.didc}/bin/didc $out cp ${pkgs.motoko.mo-doc}/bin/mo-doc $out + cp ${pkgs.motoko.mo-ide}/bin/mo-ide $out + cp ${pkgs.motoko.moc-bin}/bin/moc $out + cp ${pkgs.motoko.rts}/rts/mo-rts.wasm $out # Install agent mkdir $out/js-user-library diff --git a/default.nix b/default.nix index 9bc587aaad..b1e099c7f5 100644 --- a/default.nix +++ b/default.nix @@ -20,12 +20,9 @@ rec { cargo-audit = import ./cargo-audit.nix { inherit pkgs; }; - assets = import ./assets.nix { inherit pkgs agent-js assets-minimal bootstrap-js distributed-canisters; }; - assets-minimal = import ./assets-minimal.nix { inherit pkgs; }; + assets = import ./assets.nix { inherit pkgs agent-js bootstrap-js distributed-canisters; }; - dfx-minimal = import ./dfx-minimal.nix { inherit pkgs assets-minimal; }; - - distributed-canisters = import ./distributed-canisters.nix { inherit pkgs assets-minimal dfx-minimal; }; + distributed-canisters = import ./distributed-canisters.nix { inherit pkgs; }; inherit (pkgs) nix-fmt nix-fmt-check; diff --git a/dfx-minimal.nix b/dfx-minimal.nix deleted file mode 100644 index 889244276a..0000000000 --- a/dfx-minimal.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ pkgs ? import ./nix {} -, assets-minimal ? import ./assets-minimal.nix { inherit pkgs; } -}: -let - workspace = pkgs.buildDfinityRustPackage { - repoRoot = ./.; - name = "dfx-minimal-workspace"; - srcDir = ./.; - regexes = [ - ".*/assets/.*$" - ".*\.rs$" - ".*\.lalrpop$" - ".*Cargo\.toml$" - ".*Cargo\.lock$" - "^.cargo/config$" - ]; - cargoTestCommands = _: []; - override = oldAttrs: { - DFX_ASSETS = assets-minimal; - }; - }; - -in -pkgs.lib.standaloneRust - { - drv = workspace.build; - exename = "dfx"; - usePackager = false; - } diff --git a/distributed-canisters.nix b/distributed-canisters.nix index cf40e30a34..85b9b3b197 100644 --- a/distributed-canisters.nix +++ b/distributed-canisters.nix @@ -1,39 +1,32 @@ { pkgs ? import ./nix {} -, assets-minimal ? import ./assets-minimal.nix { inherit pkgs; } -, dfx-minimal ? import ./dfx-minimal.nix { inherit pkgs assets-minimal; } }: let distributed = lib.noNixFiles (lib.gitOnlySource ./. ./src/distributed); lib = pkgs.lib; - workspace = pkgs.runCommandNoCC "distributed-canisters-workspace" {} '' - # We want $HOME/.cache to be in a writable temporary directory. - export HOME=$(mktemp -d -t dfx-distributed-canisters-home-XXXX) - - mkdir -p $out - - for source_root in ${distributed}/*; do - canister_name=$(basename $source_root) - - build_dir=$out/$canister_name - mkdir -p $build_dir - cp -R $source_root/* $build_dir - - ( cd $build_dir ; DFX_ASSETS=${assets-minimal} ${dfx-minimal}/bin/dfx build --check ) - done - ''; - in -pkgs.runCommandNoCCLocal "distributed-canisters" {} '' - for canister_root in ${workspace}/*; do - canister_name=$(basename $canister_root) - - output_dir=$out/$canister_name - mkdir -p $output_dir - - for ext in did wasm - do - cp $canister_root/.dfx/local/canisters/$canister_name/$canister_name.$ext $output_dir - done +pkgs.runCommandNoCCLocal "distributed-canisters" { + inherit (pkgs.motoko) didc rts; + moc = pkgs.motoko.moc-bin; + base = pkgs.motoko.base-src; +} '' + mkdir -p $out + + for canister_mo in ${distributed}/*.mo; do + canister_name=$(basename -s .mo $canister_mo) + + build_dir=$out/$canister_name + mkdir -p $build_dir + + $moc/bin/moc \ + $canister_mo \ + -o $build_dir/$canister_name.did \ + --idl \ + --package base $base + MOC_RTS=$rts/rts/mo-rts.wasm $moc/bin/moc \ + $canister_mo \ + -o $build_dir/$canister_name.wasm \ + -c --debug \ + --package base $base done '' diff --git a/src/distributed/assetstorage/assetstorage.mo b/src/distributed/assetstorage.mo similarity index 100% rename from src/distributed/assetstorage/assetstorage.mo rename to src/distributed/assetstorage.mo diff --git a/src/distributed/assetstorage/dfx.json b/src/distributed/assetstorage/dfx.json deleted file mode 100644 index 64e8de33f6..0000000000 --- a/src/distributed/assetstorage/dfx.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "canisters": { - "assetstorage": { - "main": "assetstorage.mo", - "type": "motoko" - } - }, - "defaults": { - "build": { - "output": "canisters/", - "packtool": "" - } - }, - "networks": { - "local": { - "bind": "127.0.0.1:8000" - } - }, - "version": 1 -} From 87e7c41790a4d61bd219c4884dbcad44aa59956e Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 15 Jul 2020 22:25:45 -0700 Subject: [PATCH 2/2] build with --release rather than --debug --- distributed-canisters.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributed-canisters.nix b/distributed-canisters.nix index 85b9b3b197..b3406068ef 100644 --- a/distributed-canisters.nix +++ b/distributed-canisters.nix @@ -26,7 +26,7 @@ pkgs.runCommandNoCCLocal "distributed-canisters" { MOC_RTS=$rts/rts/mo-rts.wasm $moc/bin/moc \ $canister_mo \ -o $build_dir/$canister_name.wasm \ - -c --debug \ + -c --release \ --package base $base done ''