Skip to content

Commit

Permalink
build: use moc to build distributed canisters; move canister source i…
Browse files Browse the repository at this point in the history
…nto a single directory (#822)

Build the distributed canisters (just assetstorage, at this point) with `moc` directly, rather than with `dfx`.

This means we won't have to build `dfx` twice when building, opening a nix shell, etc.

Removed the `dfx-minimal` derivation and consolidated the `assets-minimal` derivation into `assets`.
  • Loading branch information
ericswanson-dfinity authored Jul 27, 2020
1 parent 7a45d07 commit 3ff6757
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 110 deletions.
21 changes: 0 additions & 21 deletions assets-minimal.nix

This file was deleted.

11 changes: 6 additions & 5 deletions assets.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 2 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
29 changes: 0 additions & 29 deletions dfx-minimal.nix

This file was deleted.

53 changes: 23 additions & 30 deletions distributed-canisters.nix
Original file line number Diff line number Diff line change
@@ -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 --release \
--package base $base
done
''
File renamed without changes.
20 changes: 0 additions & 20 deletions src/distributed/assetstorage/dfx.json

This file was deleted.

0 comments on commit 3ff6757

Please sign in to comment.