Name
dk - Launch tools that run or access `dk` coder scripts.
Synopsis
dk [OPTION]… ENTRY_MODULE_ID [ARG]…
dk [OPTION]… SCRIPT_MODULE_FILE [ARG]…
dk [OPTION]… TOOL_MODULE_ID [ENTRY_MODULE_ID] [ARG]…
dk [OPTION]… gc [ARG]…
The first two forms above use the `StdStd_Std.Run` tool to run the ENTRY_MODULE_ID or SCRIPT_MODULE_FILE.
The third form explicitly selects the TOOL_MODULE_ID, which embeds both which tool is to be used and which version of the tool. The TOOL_MODULE_ID has the format `StdStd_<toolversion>.<toolname>`. The tools are documented in the TOOLS section.
The fourth form `dk gc [ARG]…` does garbage collection in cache and data directories. See `dk gc --help` for more details.
Tools
A tool is code that, given an analysis of a script module or a project, performs an action on that script module or that project. The default tool is `StdStd_Std.Run` which runs a script module.
You must use the `dk [OPTION]… TOOL_MODULE_ID [ENTRY_MODULE_ID] [ARG]…` command line form to change the tool. For example:
dk StdStd_Std.Run YouLibrary_Std.RunMe
dk StdStd_Std.REPL YouLibrary_Std.RunMe
dk StdStd_Std.Exe YouLibrary_Std.RunMe
dk StdStd_Std.SBOM
are all ways to run different tools on the same script module (`YouLibrary_Std.RunMe`) or on the entire project.
See the TOOL VERSIONING section for how to select a specific version of a tool.
`StdStd_Std.Run` is the fully-qualified module id for the tool which has a short alias `Run` to save typing. So the following are equivalent:
dk StdStd_Std.Run YouLibrary_Std.RunMe
dk Run YouLibrary_Std.RunMe
The other official tools all have short aliases as well, and are documented below.
`dk StdStd_Std.Run ENTRY_MODULE_ID`
Short form: `dk Run ENTRY_MODULE_ID`. Since StdStd_Std.Run is the default tool, another form is `dk ENTRY_MODULE_ID`. StdStd_Std.Run runs the script module.
`dk StdStd_Std.REPL ENTRY_MODULE_ID`
Short form: `dk REPL ENTRY_MODULE_ID`. StdStd_Std.REPL compiles the script module for use in a Read-Eval-Print-Loop environment where you can interact with the scripts.
`dk StdStd_Std.Exe ENTRY_MODULE_ID`
Short form: `dk Exe ENTRY_MODULE_ID`. StdStd_Std.Embed creates executables for different operating systems.
`dk StdStd_Std.Embed ENTRY_MODULE_ID`
Short form: `dk Embed ENTRY_MODULE_ID`. StdStd_Std.Embed creates a library suitable for embedding the script module in a C-based language.
`dk StdStd_Std.SBOM`
Short form: `dk SBOM`. StdStd_Std.SBOM creates a Software Bill of Materials for the project. This feature is under development.
Tool versioning
The version of the tool is embedded in the TOOL_MODULE_ID when you run `dk [OPTION]… TOOL_MODULE_ID [ENTRY_MODULE_ID] [ARG]…`. Using an older or explicit version means that you can migrate your project and its script modules on your timeline (subject to the version's end-of-life policies).
The TOOL_MODULE_ID format is `StdStd_<toolversion>.<toolname>` where <toolversion> is either:
Std
Use the latest installed version of <toolname>
V<major>_<minor>
Use the major and minor version (ex. `V2_3`) for <toolname>.
Env
(Advanced) Use the version of <toolname> from a local environment. See the `--env-url-base DIR` option for more details.
Aliases
Often a module with `Std` in its module id has a short form (an alias) that can be typed on the command line. That is why the tool `StdStd_Std.Run` can be typed as `Run`.
The rules are that all of the `Std` parts of the library id may be omitted if the `Std` are present consecutively on the right-hand side of the library id. That is quite wordy so let's see some examples:
ALIAS FULLY QUALIFIED ID
----- ------------------
Run StdStd_Std.Run
Our.ReadMe OurStd_Std.ReadMe
OurTests.Suite OurTests_Std.Suite
Ml.Init MlStd_Std.Init
Aliases can only be used if the `Std` are on the right hand side of the library. With `StdStd_Env.Run`, for example, the right-hand side of the library id is `Env` not `Std`, so there is no alias for `StdStd_Env.Run`.
Adhoc modules
These options are only used with the Run, Exe, Embed and REPL tools described in the TOOLS section.
The contents of a script module can be specified on the command line instead of pre-existing on the filesystem. These options are `--struct` (`-S`), `--struct-url` (`-s`), `--expr-unit` (`-U`) and `--expr-unit-url` (`-u`). Each of these options is transformed and then concatenated into a single "adhoc" script module.
Your adhoc script module is treated just like any other `You` module. In particular, your adhoc script module has access to all your project code and to external `Us` and `Them` libraries.
The main use-case is to quickly try out expressions and code without having to go to a text editor or IDE. In particular, a user should be able to copy-and-paste a multi-line `dk Run -S "..."` command line from an intranet/Internet site, and have it behave identically regardless of how their browser handles tabs and newlines.
If you are posting a multi-line `dk Run -S "..."` command line, follow the format below to make it work in both PowerShell and a standard Unix shell. The format relies enclosing each `-S` and `-E` option with a double quote; most shells allow double quotes across multiple lines.
dk -S "
(* the contents of a struct without any double quotes *)
let print_endline = Tr1Stdlib_V414Io.StdIo.print_endline
" -U "
(* the expression without any double quotes or exclamation points.
Use {|...|} for strings. *)
print_endline {|okay line 1|};
print_endline {|okay line 2|}
" Run
-s URL, --struct-url=URL
Enqueue the contents of URL to an adhoc script module that will be passed to the DkCoder tool. The contents of URL must be OCaml code that can be placed as the `...` in a `struct ... end` construct. Often URL is a conventional `.ml` file. See the documentation section ADHOC MODULE SEQUENCING for how this option contributes to the adhoc module.
-S STRUCTURE, --struct=STRUCTURE
Enqueue STRUCTURE for addition to an adhoc script module that will be passed to the DkCoder tool. The STRUCTURE must be OCaml code that can be placed as the `...` in a `struct ... end` construct. See the documentation section ADHOC MODULE SEQUENCING for how this option contributes to the adhoc module.
-u URL, --expr-unit-url=URL
Enqueue the contents of URL to an adhoc script module that will be passed to the DkCoder tool. The contents of URL must be OCaml code that can be placed as the `...` in a `let () = ...` unit expression statement. Conventional `.ml` files are not expressions, so they can't be used in this command line option. See the documentation section ADHOC MODULE SEQUENCING for how this option contributes to the adhoc module.
-U UNIT_EXPRESSION, --expr-unit=UNIT_EXPRESSION
Enqueue UNIT_EXPRESSION for addition to an adhoc script module that will be passed to the DkCoder tool. The UNIT_EXPRESSION must be OCaml code that can be placed as the `...` in a `let () = ...` unit expression statement. See the documentation section ADHOC MODULE SEQUENCING for how this option contributes to the adhoc module.
Adhoc module sequencing
The sequence of steps to create the adhoc module is as follows:
The adhoc script module starts out empty.
1. Gather all the `--struct` (`-S`) from left to right as they appear on the command line, and then gather the `--struct-url` (`-s`). Each `--struct-url` (`-s`) is fetched if the execution policy allows it, but otherwise the contents of the fetched `--struct-url` are treated identically to a `--struct`.
2. Each `--struct`, and the content of each fetched `--struct-url`, are formatted with the ocamlformat code formatter for copy-and-paste resiliency, and then added to the adhoc module.
3. Gather all the `--expr-unit` (`-U`) from left to right as they appear on the command line, and then gather the `--expr-unit-url` (`-u`). Each `--expr-unit-url` (`-e`) is fetched if the execution policy allows it, but otherwise the contents of the fetched `--expr-unit-url` are treated identically to a `--expr-unit`.
4. Each `--expr-unit`, and the content of each fetched `--expr-unit-url`, are converted to `let __init (context: DkCoder_Std.Context.t) = (* the expression *); __init context` statements, then formatted with the ocamlformat code formatter, and then added to the adhoc module.
5. The adhoc module is saved into a cache directory as `ZzZz_Zz/Adhoc.ml`. The cache directory is keyed by the contents of the adhoc module. Because the contents were processed with a code formatter, the cache contents should be identical across different users even if copy-and-pasted from an intranet/Internet forum.
Build mode
These options are only used with the Exe tool described in the TOOLS section.
DkCoder's build mode (`-O` or `--optimize`) controls how fast and how big the generated executables are.
Debug
Optimizations off and debug symbols on (default). The generated Windows executables can only run on PCs with Visual Studio installed.
ReleaseSmall
Size optimizations on and debug symbols off. The size optimizations remove dead functions and OCaml back traces.
ReleaseWithDebugInfo
Size optimizations on and debug symbols on except Windows targets have minimal debug symbols. The size optimizations remove dead functions for non-Windows targets and removes OCaml back traces. For Windows targets a PDB file will be generated; however, Microsoft C runtime debug symbols are off and most C libraries will have no debug symbols. For Windows, the advantage of ReleaseWithDebugInfo compared to Debug is ReleaseWithDebugInfo's generated Windows executables do not need Visual Studio installed.
The DkCoder build mode was influenced by Zig's build mode. However, unlike Zig, DkCoder has no modes that reduce safety checks.
-O BUILDMODE, --optimize=BUILDMODE (absent=Debug)
Build mode. `Debug` is optimizations off and debug information enabled (default). `ReleaseSmall` is size optimizations on and debug information disabled. `ReleaseWithDebugInfo` is size optimizations on and debug information enabled except the Windows targets where minimal debug information enabled. BUILDMODE must be one of Debug, ReleaseSmall or ReleaseWithDebugInfo. Similar to Zig's build mode with no mode but no lowering of safety.
Compiler options
These options are only used with the Run, Exe, Embed and REPL tools described in the TOOLS section.
--preclean
Cleans the build directory before running the command. Ordinarily the build directory is re-used for the same command as a performance optimization. However, re-using compiled artifacts in a build directory can cause `make inconsistent assumptions over interface` errors in OCaml if something outside of `./dk` compiles incompatible code inside these directories. Enable this for CI and when you get any `inconsistent assumptions` errors.
--project-dir=VAL (absent DKCODER_PROJECT_DIR env)
The project directory. Defaults to the current directory. Running `./dk` and `./dk.cmd` (but not `dk`) sets the current directory to the directory containing `./dk` and `./dk.cmd`, so that directory is the default project directory. The dune-ide generator places the Dune output into the `_build` subfolder of the project directory. There are and will be many other uses of the project directory.
--recompile-project-name=VAL
(Advanced) The name of the project being recompiled.
--you-dir=VAL
A directory containing libraries of You scripts for the project. More than one directory may be specified by repeating the --you-dir option. If none are specified, defaults to the `{sources: you: []}` JSON array in `dkproject.jsonc`. If the JSON array is not present or is empty, then defaults to the `src/` subdirectory of the project directory. All script directories must be descendants of the project directory.
Generators
These options are only used with the Run, Exe, Embed and REPL tools described in the TOOLS section.
There are a couple generators that can be selected with the --generator option.
Build script generator. Defaults to `dune-ide` unless there is a non-DkCoder `dune-project` file present in the project directory.
Generator: dune
This generator creates build files for the Dune build tool. All of those files are generated inside the generator build directory. This is the generator is to use for the highest reproducibility and for publishing (tweaks will be needed) to an opam repository. It is also the generator that is the most similar to an upcoming native-code generator.
Generator: dune-ide
This generator creates build files for the Dune build tool, configured to work with Merlin-based IDEs like Visual Studio Code with the OCaml Platform plugin. The generator:
- places the Dune project file `.z-dk-dune-project` inside the project tree (you should add it to `.gitignore`)
- places the Merlin configuration `.merlin` inside the project tree (you should add it to `.gitignore`)
- places `dune-file` files in `#s` inside the project tree (you should add `#s` to `.gitignore`)
- uses the conventional `_build/` subfolder for Dune compilation (you should add it to `.gitignore`)
- does not generate `.opam` files (to not pollute the project tree)
- does not generate a `.dkcodermeta` metadata file (to not pollute the project tree)
You directories
The --you-dir option, which can be repeated, takes precedence for specifying the You directories.
The project's `dkproject.jsonc`, if it is present, can contain a `{sources: you: [...]}` JSON array. The directories in the array, if non-empty, will be the You directories if the --you-dir option was not specified.
The default You directory is the project directory's `src/` folder when all other search paths are empty.
Regardless of the You search path, if you specified a script as an absolute path (ex. `./dk test/Xy_Std/Hi.ml`) then the parent directory of the library (ex. `Xy_Std`) is added as the first You directory. In the example, the `test/` directory would be the first You directory.
Response files
@response_file
A response file can contain any options, commands and arguments that you would specify on the command line. This can be useful if your command-line arguments exceed 127 characters or contain unusual symbols. Response files are UTF-8 or UTF-16 encoded and each term is separated by whitespace (including carriage returns and newlines). If a term itself has whitespace, use single quotes. There are no escape characters. It is possible to specify the @ option from within a response file so that a response file embeds another response file. From the command line you can specify as many response file options (for example, @respfile1.rsp @respfile2.rsp) as you want.
Data home directory
The data home directory is the directory containing DkCoder-specific data files. It can be specified by the `--data-home DIR` option but will use a default from the rule list below, highest precedence to lowest precedence:
1.
`$DKCODER_DATA_HOME` if envvar DKCODER_DATA_HOME present and non-empty.
2.
`.z-dk/tools` but only if envvar $CI=true.
3.
`/opt/diskuv/$XDG_DATA_HOME/dkcoder` if envvar XDG_DATA_HOME present and non-empty and `/opt/diskuv/$XDG_DATA_HOME` exists. Unix-only.
4.
`/opt/diskuv/$HOME/.local/share/dkcoder` if envvar HOME present and non-empty and `/opt/diskuv/$HOME` exists. Unix-only.
5.
`/opt/diskuv/usr/share/dkcoder` if it exists. Unix-only.
6.
`$XDG_DATA_HOME/dkcoder` if envvar XDG_DATA_HOME present and non-empty.
7.
`$HOME/.local/share/dkcoder` if envvar HOME present and non-empty. Unix-only.
8.
`$LOCALAPPDATAProgramsDkCoder` if the known folder FOLDERID_LocalAppData from the Windows Registry is present and its value `$LOCALAPPDATA` is present and non-empty. As a security measure the Registry rather than the envvar LOCALAPPDATA is consulted. Windows-only.
Options
--data-home=VAL (absent=/builds/diskuv/distributions/1.0/dksdk-coder/build/dkcoder/data or DKCODER_DATA_HOME env)
Directory with DkCoder-specific data files. The directory will be created if it does not exist. If not specified, a default will be taken from the list in the
DATA HOME DIRECTORY section. Relative paths are evaluated relative to `
--pwd DIR` or the default current directory. When there is no default
--data-home is required.
--executable-name=VAL (absent DKCODER_ARG0 env)
The name of the executable or script that launched DkCoder.
--man-format=FMT (absent=pager)
Show output in format FMT. The value FMT must be one of auto, pager, groff or plain. With auto, the format is pager or plain whenever the TERM env var is dumb or undefined.
--pwd=VAL (absent=/builds/diskuv/distributions/1.0/dksdk-coder or DKCODER_PWD env)
The directory of the shell or other user process that launched DkCoder. Defaults to the environment value DKCODER_PWD or failing that the current directory. The wrapper scripts ./dk and ./dk.cmd will set the DKCODER_PWD value to the current directory that was active at the time the ./dk and ./dk.cmd wrappers were invoked.
--tool-debug-solver
Enable debug logging of the solver
--tool-log-level=LEVEL
Set the verbosity of log messages for the tool, not the dk executable. If the option is repeated the last LEVEL is used. LEVEL must be one of ERROR, WARNING, INFO or DEBUG.
--tty=VAL (absent=auto or DKCODER_TTY env)
Specify if attached to a console terminal (known as 'tty' in Unix). must be one of 0, disable, false, 1, enable or true.
Common options
--color=WHEN (absent=auto)
Colorize the output. WHEN must be one of auto, always or never.
--help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of auto, pager, groff or plain. With auto, the format is pager or plain whenever the TERM env var is dumb or undefined.
-l LEVEL, --log-level=LEVEL
Set the verbosity of log messages. If the option is repeated the last LEVEL is used. LEVEL must be one of ERROR, WARNING, INFO or DEBUG.
-q, --quiet
Be quiet. Takes precedence over -l and --log-level options.
--version
Show version information.
Advanced options
--dump-config
Dump build configuration.
--env-url-base=VAL (absent DKTOOL_ENV_URL_BASE env)
The base URL for the DkCoder installation archive. Used for offline and local development for DkSDK subscribers. The base URL must contain the URL `<base URL>/stdexport-HOSTABI.zip`. On this machine the required file is stdexport-linux_x86_64.zip. DkSDK subscribers can clone the `dksdk-coder` project and build their own customizations for DkCoder; the base URL should then be `file://<path to dksdk-coder>`
--fixed-length-modules=VAL (absent=true)
Enable fixed length modules. Fixed length modules are represented on disk with a short module name derived from the module's fully qualified package identifier; module aliases are introduced so the shortened module names are accessed with the true module names. Currently the Dune and Merlin tools require a correspondence between source filenames and build filenames for navigation, so fixed length modules are not recommended within IDEs.
Exit status
dk exits with:
0
on success.
123
on indiscriminate errors reported on standard error.
124
on command line parsing errors.
125
on unexpected internal errors (bugs).
Environment
These environment variables affect the execution of dk:
DKCODER_ARG0
See option --executable-name.
DKCODER_DATA_HOME
See option
--data-home. Other environment variables `CI`, `LOCALAPPDATA`, `XDG_DATA_HOME` and `HOME` are used when
DKCODER_DATA_HOME is not present. See the
DATA HOME DIRECTORY section for more details.
DKCODER_PROJECT_DIR
See option --project-dir.
DKCODER_PWD
See option --pwd.
DKCODER_TTY
See option --tty.
DKTOOL_ENV_URL_BASE
See option --env-url-base.
Bugs
Check feature requests and bugs at https://github.com/diskuv/dk/issues
See also
https://diskuv.com/dk/help/latest/