Skip to content

Commit

Permalink
Patch binaries and add CI (#3)
Browse files Browse the repository at this point in the history
* Patchelfing

* Try escaping

* Unconditionally patchelf

* Revert to conditional patchelfing

* Add icx-proxy to the list of binaries

* Attempt to set DFX_CONFIG_ROOT

So that subsequent dfx commands see that the cache is populated and don't try to
unpack new binaries that haven't been patched.

Also check if the initial dfx binary needs patching, since in 0.9.2 it appeared
to use static linking.

* Add .gitignore

* Add default package to flake example

* Add CI job for building flake example

* Unconditionally patch dfx again

* Revert "Unconditionally patch dfx again"

This reverts commit 4cc1517.

* Use local path, update flake.lock

By running `nix flake lock --update-input dfinity-sdk`

* Add newline

* Actually try running dfx start/stop in example

* Add dfx.json to example, fix cache directory

* Fix CI job name
  • Loading branch information
paulyoung authored Mar 26, 2022
1 parent 28bb54d commit 8ea6347
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 19 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Build flake example"
on:
pull_request:
push:
jobs:
nix:
name: Build flake example on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
- uses: cachix/install-nix-action@v15
- run: cd examples/flake && nix build --show-trace
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DFINITY
.dfx/


# Nix
result
result-*
44 changes: 35 additions & 9 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,49 @@ let
"dfx-${version}.tar.gz"
];
};
nativeBuildInputs = [
self.makeWrapper
] ++ self.lib.optional self.stdenv.isLinux [
self.glibc.bin
self.patchelf
self.which
];
# Use `find $(dfx cache show) -type f -executable -print` on macOS to
# help discover what to symlink.
installPhase = ''
export HOME=$TMP
${self.lib.optionalString self.stdenv.isLinux ''
local LD_LINUX_SO=$(ldd $(which iconv)|grep ld-linux-x86|cut -d' ' -f3)
local IS_STATIC=$(ldd ./dfx | grep 'not a dynamic executable')
local USE_LIB64=$(ldd ./dfx | grep '/lib64/ld-linux-x86-64.so.2')
chmod +rw ./dfx
test -n "$IS_STATIC" || test -z "$USE_LIB64" || patchelf --set-interpreter "$LD_LINUX_SO" ./dfx
''}
./dfx cache install
mkdir -p $out/cache
cp --preserve=mode,timestamps -R $(./dfx cache show)/. $out/cache
local CACHE_DIR="$out/.cache/dfinity/versions/${version}"
mkdir -p "$CACHE_DIR"
cp --preserve=mode,timestamps -R $(./dfx cache show)/. $CACHE_DIR
mkdir -p $out/bin
ln -s $out/cache/dfx $out/bin/dfx
ln -s $out/cache/ic-ref $out/bin/ic-ref
ln -s $out/cache/ic-starter $out/bin/ic-starter
ln -s $out/cache/mo-doc $out/bin/mo-doc
ln -s $out/cache/mo-ide $out/bin/mo-ide
ln -s $out/cache/moc $out/bin/moc
ln -s $out/cache/replica $out/bin/replica
for binary in dfx ic-ref ic-starter icx-proxy mo-doc mo-ide moc replica; do
${self.lib.optionalString self.stdenv.isLinux ''
local BINARY="$CACHE_DIR/$binary"
test -f "$BINARY" || continue
local IS_STATIC=$(ldd "$BINARY" | grep 'not a dynamic executable')
local USE_LIB64=$(ldd "$BINARY" | grep '/lib64/ld-linux-x86-64.so.2')
chmod +rw "$BINARY"
test -n "$IS_STATIC" || test -z "$USE_LIB64" || patchelf --set-interpreter "$LD_LINUX_SO" "$BINARY"
''}
ln -s $CACHE_DIR/$binary $out/bin/$binary
done
wrapProgram $CACHE_DIR/dfx --set DFX_CONFIG_ROOT $out
rm $out/bin/dfx
ln -s $CACHE_DIR/dfx $out/bin/dfx
'';
system = resolvedSystem;
inherit version;
Expand Down
10 changes: 10 additions & 0 deletions examples/flake/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"dfx": "0.8.4",
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
}
}
14 changes: 5 additions & 9 deletions examples/flake/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion examples/flake/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
nixpkgs.url = "github:nixos/nixpkgs/21.11";
flake-utils.url = "github:numtide/flake-utils";
dfinity-sdk = {
url = "github:paulyoung/nixpkgs-dfinity-sdk";
# url = "github:paulyoung/nixpkgs-dfinity-sdk";
url = "../../";
flake = false;
};
};
Expand All @@ -24,6 +25,18 @@
})."0.8.4";
in
{
# `nix build`
defaultPackage = pkgs.runCommand "example" {
buildInputs = [
dfinitySdk
];
} ''
cp ${./dfx.json} dfx.json
dfx start --background
dfx stop
touch $out
'';

# `nix develop`
devShell = pkgs.mkShell {
buildInputs = [
Expand Down

0 comments on commit 8ea6347

Please sign in to comment.