Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add nix-shell and cargo at the root of SDK #41

Merged
merged 7 commits into from
Sep 24, 2019
Merged

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Sep 20, 2019

This was driving me cray-cray.

Copy link
Contributor

@paulyoung paulyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reservations about moving Cargo-specific things to the root since not everything in the SDK will be written in Rust but maybe the workspace makes sense. In any case, we'd need to change how nix builds things and use the workspace instead.

The existing shell.nix should already be doing what we want. Is that not working for you?

@hansl
Copy link
Contributor Author

hansl commented Sep 21, 2019

My IDE (IntelliJ with the rust plugin) is not Nix aware (outside of highlighting and running) and without a Cargo at the root it fails to read the workspace.

This allows nix-shell from the root and then you can build rust (or javascript). We should support a workflow where nix-build or nix-shell at the root of the repo merges all possible shell states between the different projects. There are plenty of work (and PRs) that should cover all our languages.

@paulyoung
Copy link
Contributor

We should support a workflow where nix-build or nix-shell at the root of the repo merges all possible shell states between the different projects.

The existing nix-shell already does that

This adds CI, formatting and clippy (linting) to the whole project's
rust code, so some fixes in the lib/ folder are necessary. The tests
still passes, nix-shell and nix-build works (with build outputting
the right expected format).
@hansl
Copy link
Contributor Author

hansl commented Sep 24, 2019

@paulyoung please take another look. I'm going to rebase my other PR on this.

@hansl
Copy link
Contributor Author

hansl commented Sep 24, 2019

@chenyan-dfinity Please take a look at this as it will need to be merged (and probably conflict) with what you're doing. It should be the same code, just respecting the formatter and linter we use. Your other PR will have to pass CI now, but rebasing it on this one should run CI. So once this is in master you should probably merge or rebase the other PR.

Copy link
Collaborator

@chenyan-dfinity chenyan-dfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for doing this!

Copy link
Contributor

@paulyoung paulyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to get feedback from @jwiegley and/or @basvandijk on the nix changes.

Maybe we should try to use https://github.com/dfinity-lab/common, but I'm not sure if that's ready yet.

@@ -4,6 +4,9 @@ result*
build/
target/

# Nix-related directories.
.cargo-home/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember setting an environment variable in the old package.nix file so that .cargo was used instead of .cargo-home.

I don't know enough about Cargo to know the difference between the two directories but at the time I made the change it seemed obvious that something was looking for things in .cargo-build that were in .cargo

Not sure if that is relevant; maybe we need to make sure that env var is still set? or unset it if we want to use .cargo-home?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.cargo is used by cargo for its configuration, I think? .cargo-home could be named anything that's not used. That's just what they use in the main repo. This is to avoid using a global cargo cache when using nix-shell then cargo build.

jobset.nix Outdated
@@ -2,5 +2,5 @@
, crossSystem ? null
, config ? {}
}: {
inherit (import ./. { inherit system crossSystem config; }) dfinity-sdk;
inherit (import ./. { inherit system crossSystem config; }) rust-workspace;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want to build everything in the SDK on CI. This would only build the rust workspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I would expect you add another inherit in this file when adding JavaScript.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to say "build the SDK" (dfinity-sdk) and then update what's in the SDK.

default.nix Outdated
let pkgs = import ./nix/nixpkgs.nix args; in {
inherit pkgs;

inherit (pkgs.dfinity-sdk.packages) rust-workspace;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could just build everything under packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My knowledge of nix is limited enough that I don't have an answer for you, unfortunately. I can inherit an attribute, I can list attributes, but I don't know how to inherit all attributes (using a for loop of some sort?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work?

let pkgs = import ./nix/nixpkgs.nix args; in
{ inherit pkgs; } // pkgs.dfinity-sdk.packages

@@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["chenyan-dfinity <yan.chen@dfinity.org>"]

[lib]
name = "dfx_derive"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off topic, but why is "dfx" part of the name in these? Isn't their use broader than that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenyan-dfinity can answer this.

nix/overlays/dfinity-sdk.nix Outdated Show resolved Hide resolved
export PATH="${rustc}/bin''${PATH:+:}$PATH"

# Set CARGO_HOME to minimize interaction with any environment outside nix
export CARGO_HOME=${pkgs.lib.dfinityRoot}/.cargo-home
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comment about .cargo-home

## best to ignore it for now.
# postDoc = ''
# cargo graph | dot -Tsvg > ./target/doc/dfx/cargo-graph.svg
# '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the dfinity repo get around this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relevant for any licensing concerns? e.g. so it's easy to see where a crate is coming from if something shows up with an incompatible license

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea (seriously). I looked into it and gave up after a while. They use the same versions of cargo and cargo-graph.

I modified my lock file to have the right fields and ran cargo graph manually and it gave me a single node.

nix/rust-workspace.nix Outdated Show resolved Hide resolved
nix/rust-workspace.nix Outdated Show resolved Hide resolved
shell.nix Show resolved Hide resolved
@basvandijk
Copy link
Contributor

I'll look at this PR tomorrow. Note that I expect https://github.com/dfinity-lab/common and https://github.com/dfinity-lab/dfinity/pull/1266 will be ready some time tomorrow. I already started moving this sdk repo over to use common.

inherit dfx;
packages = {
inherit rust-workspace;
rust-workspace-debug = rust-workspace.override (_: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this builds when running nix-build and on CI, in addition to a release build.

Should we move it to shells?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this right, moving this to shells would prevent it from running on CI. Correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not actually, since part of the motivation for shells is to build on CI. Let's figure it out later.

, release ? true # is it a "release" build, as opposed to "debug" ?
, doClippy ? false
, doFmt ? false
, doDoc ? false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want doClippy ? true, doFmt ? true so they run by default? Right now they're not running on CI.

Copy link
Contributor Author

@hansl hansl Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way it's setup in the DFINITY repo. From a separate conversation:

  • the idea might be that there's no use running those twice on CI
  • and/or that you don't want to block a release of a product if it fails formatting (but PRs should not be accepted anyway)
  • and/or that some #[cfg()] might remove code that won't be checked in clippy (as it actually evaluates those) in release (although the same can be said the other way)

Copy link
Contributor

@paulyoung paulyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving so we can make some progress, and follow up with @basvandijk tomorrow

@hansl
Copy link
Contributor Author

hansl commented Sep 24, 2019

@basvandijk @jwiegley Let's move discussions and reviews of this PR to the JIRA ticket about unifying the build of everyone.

I think the general idea here should be that:

  • the repo directory structure does not separate per language, but per product / project
  • ideally, we should have a nix derivation per product / project that handles dependencies internally, and have a separate Cargo for the root for IDEs.
  • That setup is more complicated than we can maintain at the current state (we're in full feature development until at least 0.5.0), and as such we just going to duct-tape it until we have cycles to fix it properly. So for now, rust is its own Nix derivation (similar to the main repo IIRC), and JavaScript / Other products will be their own Nix derivation separately.
  • the Nix package at the root of the repo should be the union of all the different Nix derivations

@hansl
Copy link
Contributor Author

hansl commented Sep 24, 2019

Sorry for the fixups (and the upcoming force push). This PR found a lot of linting and formatting errors, and apparently clippy doesn't thoroughly go through all nodes of the AST (ie. fixing some linting errors might uncover more linting errors, even in unrelated functions).

@hansl hansl merged commit 28a0814 into master Sep 24, 2019
@hansl hansl deleted the hansl/root-cargo branch September 24, 2019 21:28
hansl added a commit that referenced this pull request Nov 9, 2020
commit 7c5e71488df430b89de637a15b56814db196e752
Author: Islam El-Ashi <ielashi@users.noreply.github.com>
Date:   Sat Nov 7 00:30:05 2020 +0100

    feat: DER-encode public key and principal ID when using Plain Authentication. (#48)

    BREAKING CHANGE

    If a developer relies on the inner work of SenderPubKey or manually instanciate Principal, the API changed.

commit a254861ae4bfe608734c8c190e4033cfe39f047b
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:32 2020 -0800

    chore(deps): bump node-fetch from 2.6.0 to 2.6.1 in /e2e/node (#49)

    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 694849109bc28fea80119388504127e889b36d15
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:14 2020 -0800

    chore(deps-dev): bump node-fetch from 2.6.0 to 2.6.1 in /packages/agent (#50)

    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 88af47f79b5e9f3a5e08abbf0ce03b3140357fc0
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:16:53 2020 -0800

    chore(deps-dev): bump node-fetch in /packages/bootstrap (#51)

    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit ba4b082e5795150176f7adad989c3613edceb85f
Author: Hans <hans@larsen.online>
Date:   Thu Nov 5 12:49:59 2020 -0800

    test: add ic-ref, ci e2e and lerna support to repo (#47)

    This refactors the repository to use lerna to manage its monorepo's packages. It also adds the e2e tests from the SDK repo that we previously had to remove. More e2e tests will be added later, but this unblocks working with DER and Identity work as we can now at least run some e2e tests now (instead of mocking the http connection).

commit 8baa1cfc227d003c2806df1057b92009159df250
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:36 2020 -0800

    feat: use anonymous principal by default in HttpAgent (#46)

    If the auth transform is missing and the principal is anonymous, use an
    anonymous auth transform. Otherwise, use the auth transform as normal.

    # BREAKING CHANGE
    Before, an auth transform would not be called if it was missing, now it
    results as an error if the principal is not anonymous. This was because
    just using the packet as is without putting it in an envelope was a bug
    and should never be sent to a replica anyway. Now this is explicit.

commit 1a714e6c53f5e467112b964b71204b6d2eb545ef
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:15 2020 -0800

    feat: add a getPrincipal() method to Agents (#40)

commit 324e856944adb7f79a2afa2cffbdb6d144b35ab4
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 08:49:44 2020 -0800

    feat: add the canister ID to the window.ic object (#41)

    This can be useful to know the canister ID of the current frontend.

commit 8680a2cf4994b45c6e00ffb0b5a12b379f5ff919
Author: Hans <hans@larsen.online>
Date:   Mon Nov 2 21:57:21 2020 -0800

    feat: add a cache bust hash at the end of javascript output (#39)

commit 9f2ed968b7cc9f4b854af5e23edca19d34124909
Author: Benjamin Goering <benjamin.goering@dfinity.org>
Date:   Tue Sep 22 15:28:49 2020 -0700

    docs: polish docs/npm-publish.md per @hansl feedback (#37)

    via: pr feedback on dfinity/agent-js#36
mergify bot pushed a commit that referenced this pull request Nov 10, 2020
commit 19c28008db5fa1582da573088b17d0bdee9e8bc2
Author: Hans <hans@larsen.online>
Date:   Mon Nov 9 14:47:25 2020 -0800

    revert: Remove lerna (PR #47) (#59)
    
    This removes lerna, but attempt to not remove the e2e tests and the
    new packages/files that were added after the last PR.

commit 426a94f356bc4e27f50c8bec55071b82105adbd1
Author: Hans <hans@larsen.online>
Date:   Mon Nov 9 13:54:04 2020 -0800

    feat: use anonymous for the first retrieve (#53)
    
    Also include some cleanup of the scripts that arent used, and add a diagram for the
    bootstrapping process.
    
    This does not affect the worker yet. Only the first retrieve of the index.js on
    localhost.
    
    BREAKING CHANGE
    
    If a canister has a retrieve() method that relies on Principal, the principal used
    will change.
    
    Co-authored-by: Benjamin Goering <benjamin.goering@dfinity.org>

commit b795d8b34ce38dd35e1bcf2b80e33108cf74161d
Author: Andrew Wylde <2126677+codelemur@users.noreply.github.com>
Date:   Mon Nov 9 09:41:13 2020 -0800

    feat(idp): add identity-provider package to repository (#52)
    
    adds plain HTML/ts and test setup for project

commit 7c5e71488df430b89de637a15b56814db196e752
Author: Islam El-Ashi <ielashi@users.noreply.github.com>
Date:   Sat Nov 7 00:30:05 2020 +0100

    feat: DER-encode public key and principal ID when using Plain Authentication. (#48)
    
    BREAKING CHANGE
    
    If a developer relies on the inner work of SenderPubKey or manually instanciate Principal, the API changed.

commit a254861ae4bfe608734c8c190e4033cfe39f047b
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:32 2020 -0800

    chore(deps): bump node-fetch from 2.6.0 to 2.6.1 in /e2e/node (#49)
    
    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 694849109bc28fea80119388504127e889b36d15
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:14 2020 -0800

    chore(deps-dev): bump node-fetch from 2.6.0 to 2.6.1 in /packages/agent (#50)
    
    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 88af47f79b5e9f3a5e08abbf0ce03b3140357fc0
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:16:53 2020 -0800

    chore(deps-dev): bump node-fetch in /packages/bootstrap (#51)
    
    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit ba4b082e5795150176f7adad989c3613edceb85f
Author: Hans <hans@larsen.online>
Date:   Thu Nov 5 12:49:59 2020 -0800

    test: add ic-ref, ci e2e and lerna support to repo (#47)
    
    This refactors the repository to use lerna to manage its monorepo's packages. It also adds the e2e tests from the SDK repo that we previously had to remove. More e2e tests will be added later, but this unblocks working with DER and Identity work as we can now at least run some e2e tests now (instead of mocking the http connection).

commit 8baa1cfc227d003c2806df1057b92009159df250
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:36 2020 -0800

    feat: use anonymous principal by default in HttpAgent (#46)
    
    If the auth transform is missing and the principal is anonymous, use an
    anonymous auth transform. Otherwise, use the auth transform as normal.
    
    # BREAKING CHANGE
    Before, an auth transform would not be called if it was missing, now it
    results as an error if the principal is not anonymous. This was because
    just using the packet as is without putting it in an envelope was a bug
    and should never be sent to a replica anyway. Now this is explicit.

commit 1a714e6c53f5e467112b964b71204b6d2eb545ef
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:15 2020 -0800

    feat: add a getPrincipal() method to Agents (#40)

commit 324e856944adb7f79a2afa2cffbdb6d144b35ab4
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 08:49:44 2020 -0800

    feat: add the canister ID to the window.ic object (#41)
    
    This can be useful to know the canister ID of the current frontend.

commit 8680a2cf4994b45c6e00ffb0b5a12b379f5ff919
Author: Hans <hans@larsen.online>
Date:   Mon Nov 2 21:57:21 2020 -0800

    feat: add a cache bust hash at the end of javascript output (#39)

commit 9f2ed968b7cc9f4b854af5e23edca19d34124909
Author: Benjamin Goering <benjamin.goering@dfinity.org>
Date:   Tue Sep 22 15:28:49 2020 -0700

    docs: polish docs/npm-publish.md per @hansl feedback (#37)
    
    via: pr feedback on dfinity/agent-js#36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants