Giter VIP home page Giter VIP logo

bld's Introduction

bld

bld is an experimental build tool for monorepos inspired by Bazel, and implemented with Nix. This is meant to evolve and its current form is not the final one.

This tool has two sides: a CLI and a Nix library, that are meant to be able to work together.

Principles

We steal the notion of "targets" from Bazel, making each folder open-ended.

It should be possible to type bld in any folder and get the build output of the current folder (and below?).

It should be possible to build any targets using purely nix-build.

Usage

$ bld --help

Usage: bld <command>

Flags:
  -h, --help     Show context-sensitive help.
      --debug

Commands:
  build [<target>]
    Build target

  list [<target>]
    List available targets

  run [<target>]
    Run executable target

  inspect [<target>]
    Show build information about target

Run "bld <command> --help" for more information on a command.

The following examples are from this repository.

To list all targets.

$ bld list

bin
default
devShell
hello
To build a target.

$ bld build hello

INFO[0000] Building target                               target=hello
/nix/store/9a74wmrh6l9h012xza53ff58v0rx456d-hello
To run a target.

$ bld run hello

/nix/store/9a74wmrh6l9h012xza53ff58v0rx456d-hello
Hello, world!

This can be also used to pass flags:

$ bld run hello -- --help

/nix/store/9a74wmrh6l9h012xza53ff58v0rx456d-hello
Print a friendly, customizable greeting.

  -t, --traditional       use traditional greeting
  -g, --greeting=TEXT     use TEXT as the greeting message

      --help     display this help and exit
      --version  output version information and exit

Report bugs to: [email protected]
GNU Hello home page: <https://www.gnu.org/software/hello/>
General help using GNU software: <https://www.gnu.org/gethelp/>
To inspect a target.

$ bld inspect hello

{
  "/nix/store/bn6wpa9yqibcy83d2iabh1s5k49lcpb7-hello.drv": {
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "builder": "/nix/store/1b9p07z77phvv2hf6gm9f28syp39f1ag-bash-5.1-p16/bin/bash",
    "env": {
      "allowSubstitutes": "",
      "buildCommand": "target=$out'/bin/hello'\nmkdir -p \"$(dirname \"$target\")\"\n\nif [ -e \"$textPath\" ]; then\n  mv \"$textPath\" \"$target\"\nelse\n  echo -n \"$text\" > \"$target\"\nfi\n\neval \"$checkPhase\"\n\n(test -n \"$executable\" && chmod +x \"$target\") || true\n",
      "buildInputs": "",
      "builder": "/nix/store/1b9p07z77phvv2hf6gm9f28syp39f1ag-bash-5.1-p16/bin/bash",
      "checkPhase": "/nix/store/1b9p07z77phvv2hf6gm9f28syp39f1ag-bash-5.1-p16/bin/bash -n -O extglob \"$target\"\n",
      "cmakeFlags": "",
      "configureFlags": "",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "",
      "doInstallCheck": "",
      "enableParallelBuilding": "1",
      "enableParallelChecking": "1",
      "executable": "1",
      "mesonFlags": "",
      "name": "hello",
      "nativeBuildInputs": "",
      "out": "/nix/store/9a74wmrh6l9h012xza53ff58v0rx456d-hello",
      "outputs": "out",
      "passAsFile": "buildCommand text",
      "patches": "",
      "preferLocalBuild": "1",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "stdenv": "/nix/store/p93ivxvrf3c2w02la2c6nppmkgdh08y3-stdenv-linux",
      "strictDeps": "",
      "system": "x86_64-linux",
      "text": "#!/nix/store/1b9p07z77phvv2hf6gm9f28syp39f1ag-bash-5.1-p16/bin/bash\n/nix/store/y4mxrg8c6l09lb2szl69vwl4f6441i5k-hello-2.12.1/bin/hello\n\n"
    },
    "inputDrvs": {
      "/nix/store/6pj63b323pn53gpw3l5kdh1rly55aj15-bash-5.1-p16.drv": [
        "out"
      ],
      "/nix/store/g6qkwa2xaq6i40cwl9bpjxi19m7q8121-hello-2.12.1.drv": [
        "out"
      ],
      "/nix/store/zq638s1j77mxzc52ql21l9ncl3qsjb2h-stdenv-linux.drv": [
        "out"
      ]
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "outputs": {
      "out": {
        "path": "/nix/store/9a74wmrh6l9h012xza53ff58v0rx456d-hello"
      }
    },
    "system": "x86_64-linux"
  }
}

Future ideas

  • Resolve the targets purely with Nix. It should be necessary to connect the BUILD.nix files manually like currently.
  • Snapshot nixpkgs. In order to speed-up nixpkgs, we want to be able to snapshot the build outputs that we are going to use.
  • Add nix evaluation caching to speed-up builds.
  • Introduce incremental rebuild Nix libraries for various languages.
  • Hook in pre-processing tools. It should be possible to update a third-party package hash automatically.

bld's People

Contributors

jfroche avatar mic92 avatar zimbatm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.