From 104c769bcc3fa268792b06f84cf325315c25b61f Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Sat, 25 Nov 2023 16:54:46 +0100 Subject: [PATCH] Simplify bootstrapping with dune (#1792) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Simplify bootstrapping with dune Hi folks 👋🏼 just got around this page and thought it could be simplified a little. Feel free to dismiss if it doesn't meet the expected guidelines/style. * Update data/tutorials/platform/bp_00_bootstrap_project.md Co-authored-by: Cuihtlauac Alvarado --------- Co-authored-by: Cuihtlauac Alvarado --- .../platform/bp_00_bootstrap_project.md | 59 ++++++++----------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/data/tutorials/platform/bp_00_bootstrap_project.md b/data/tutorials/platform/bp_00_bootstrap_project.md index 742fbc691f..e5bdb9f806 100644 --- a/data/tutorials/platform/bp_00_bootstrap_project.md +++ b/data/tutorials/platform/bp_00_bootstrap_project.md @@ -8,58 +8,47 @@ category: "Best Practices" # Bootstrapping a Project with Dune -[Dune](https://dune.readthedocs.io/en/stable/overview.html) is recommended for bootstrapping projects using `dune init`. If `opam` or `dune` are not installed, please see [the OCaml install page](/install). +[Dune](https://dune.readthedocs.io/en/stable/overview.html) is recommended for bootstrapping projects. To install `dune`, please see [the OCaml install page](/install). -> dune init --help -> -> **dune init {library,executable,test,project} NAME [PATH]** initialize a -> new dune component of the specified kind, named NAME, with fields -> determined by the supplied options. - -As shown above, `dune init` accepts a _kind_, `NAME`, and optional `PATH` to scaffold new code. Let's try it out: +To start a new project, you can run: ```sh -dune init project hello ~/src/ocaml-projects - -Success: initialized project component named hello +$ dune init project hello_world +Success: initialized project component named hello_world ``` -In the above example, we use: +You can now build and run your new project: -- "project" as the _kind_ -- "hello" as the _name_, and -- "~/src/ocaml-projects" as the _path_ to generate the content in +```sh +$ cd hello_world +$ dune exec bin/main.exe +Hello, world! +``` -The `project` _kind_ creates a `library` in `./lib`, an `executable` in `./bin`, and links them together in `bin/dune`. Additionally, the command creates a test executable and an opam file. +To create a new library in the current project, use: ```sh -tree ~/src/ocaml-projects/hello/ - -/home/user/src/ocaml-projects/hello/ -├── bin -│   ├── dune -│   └── main.ml -├── hello.opam -├── lib -│   └── dune -└── test - ├── dune - └── hello.ml +$ dune init lib my_lib ./path/to/my_lib +Success: initialized library component named my_lib ``` -At this point, you can build the project and run the binary: +To create a new executable in the current project, use: ```sh -cd /home/user/src/ocaml-projects/hello/ -dune exec bin/main.exe +$ dune init exec my_bin ./path/to/my_bin +Success: initialized executable component named my_bin +``` -Hello, world! +To create a new test in the current project, use: + +```sh +$ dune init test my_test ./path/to/my_test +Success: initialized test component named my_test ``` -Thus, `dune init` can rapidly scaffold new projects, with minimal content. It can also be used to add components (kinds) incrementally to existing projects. +## More Comprehensive Scaffolding -Various community projects offer more comprehensive project scaffolding than `dune` as well. -The following projects are not formally supported by the OCaml Platform, but may be of interest to the reader: +If you're looking for project templates that include more than the basics, there are other community projects that offer more comprehensive project scaffolding: - [spin](https://github.com/tmattio/spin) - [drom](https://ocamlpro.github.io/drom/sphinx/about.html)