holochain / holochain-rust

DEPRECATED. The Holochain framework implemented in rust with a redux style internal state-model.
GNU General Public License v3.0
1.12k stars 267 forks source link

DNA manifest file (app.json) explicit zome references #1300

Open maackle opened 5 years ago

maackle commented 5 years ago

Proposal

Add a "zomes" field to the DNA manifest (app.json / manifest.json) which explicitly contains info about zome location, like this:

{
  "zomes": {
    "blog": "zomes/blog",
    "another": "some/other/zomes/another"
  }
}

The benefits are several:

1. Freedom of project directory structure

Users could choose a less deeply-nested directory structure, i.e. this:

project/
  dna-src/
    app.json
    zomes/
      blog/
        code/
          src/
            lib.rs

could be replaced with this (or any other conceivable directory structure):

project/
  hcdna.json
  zome-blog/
    code/
      src/
        lib.rs

So, this shaves off two layers of directory nesting. ("dna-src" is a convention we use, but I think it's primarily because of the current prescriptive directory structure.)

Note: To ensure that a package can be unpackaged into its original directory structure, the zome paths must be constrained to be subdirectories of the directory containing the manifest file. (Thanks for pointing out @zippy)

2. Remote zome dependencies

This would also open the possibility of treating the app.json as similar to a package.json or Cargo.toml file for zomes. Rather than a local path, a remote URL could be listed, or even a HCHC hash. For third-party zomes, developers won't want to maintain a local copy

3. Remote DNA dependencies

Currently, for a given project containing DNA source code, there is no sure way to tell which directory to run hc package in, because it's not guaranteed that the root of the project is also the DNA source root.

Using explicit zome directory references like this, it is clear exactly how to build the project. That means that for hApp developers, there can be tooling that points either to a built DNA package (foo.dna.json) -OR- a remote source code repository. This would be helpful for development purposes, where a dev can point to a GH branch when testing a DNA with their team, rather than having to package and upload a .dna.json for every change.


We should also probably rename "app.json" to something more globally recognizable like "hcdna.json" or something, since this would be the canonical way to identify a source code repo as containing DNA source code.

jmday commented 5 years ago

I suggest providing the ability to influence the output .dna.json file as well. Currently, the app.json file has a name: attribute; however, the produced package is named according to the directory rather than the name of the DNA. e.g.

zaphod-2:holochain-dev-core-concepts jmday$ cat app.json
{
  "name": "HelloHolo",
  "description": "A simple hApp using a zome function",
  "authors": [
    {
      "identifier": "Jamison M. Day <jamison.day@holo.host>",
      "public_key_source": "",
      "signature": ""
    }
  ],
  "version": "0.1.0",
  "dht": {},
  "properties": null
}zaphod-2:holochain-dev-core-concepts jmday$ hc package
> cargo build --release --target=wasm32-unknown-unknown --target-dir=target
    Finished release [optimized] target(s) in 0.26s
> cargo build --release --target=wasm32-unknown-unknown --target-dir=target
    Finished release [optimized] target(s) in 0.30s
Created DNA package file at "/Users/jmday/hc/apps/cce/0012/holochain-dev-core-concepts/dist/holochain-dev-core-concepts.dna.json"
DNA hash: QmeKuVLGKMzFPAqZaoEuFHe3CBcvNhABHqE2nraesyuoLN

It may be useful to use the specified DNA name for the output package filename or, optionally, provide a separate attribute to override the filename (and/or preferred directory?).

maackle commented 5 years ago

This is also related to the need for app bundles which reference DNAs. Just as zome dependencies should be flexible for development ease, the DNA dependencies of the app bundles should be as well, and for dependencies on local/remote directories of code, this zome-aware manifest will be necessary.

GildedHonour commented 5 years ago

What does "dna.json" should look like? Is there the full specification? Where should it be stored precisely?

maackle commented 5 years ago

@GildedHonour this PR is talking about the thing currently called "app.json", which is generated by hc init. I also referenced ".dna.json" files, which are the DNA packages created by hc package which look like your-app-name.dna.json. Just to clarify