Skip to content

3.6. Project Files (.dqproj)

Some projects may require a large amount of compiler options to compile. In order to make the complex project compilation easier the DQ compiler supports project files.

The DQ project files are basically a set of compiler options in a more manageable way.

The project files use the .dqproj extension:

Example usage:

dq-comp application.dqproj
dq-comp -O0 -g -o build/application application.dqproj

(the dq-comp options provided in the command line override the options in the .dqproj file)

Unless output or -o selects another path, the executable is named after the project file and written beside it. Build artifacts are kept below the project directory's .dqbuild directory, independently of the main source location.

3.6.1 Project File Example

// application.dqproj

pkg_path = 'packages'
var BOARD_SUPPORT = PackagePath('board_support')

include '\{BOARD_SUPPORT}/project/stm32f746.dqproj'

main      = 'src/application.dq'
output    = 'build/\{PROJECT_NAME}.elf'
target    = 'arm_m7f-bare'
cpu_features = '+no-movt'
compiler_runtime = 'libgcc'
c_runtime = 'newlib-nano'
link      = true
optlevel  = 2
debuginfo = true
lto       = false

define BOARD_NUCLEO_F746
define CPU_CLOCK_HZ = 216000000

linkobject = '\{BOARD_SUPPORT}/lib/startup.o'
linkoption = '--gc-sections'

arm_m7f-bare selects the Cortex-M7 single-precision FPU and makes float 32-bit. Use arm_m7fd-bare for Cortex-M7 devices with a double-precision FPU; on that target float is 64-bit. The explicit float32 and float64 types do not change with the target.

Use dq-comp --targets for the canonical target list and detailed defaults. The additional hosted Linux targets are armhf-linux, arm64-linux, and rv64g-linux; select the target distribution or SDK root with sysroot when linking for one of them. The additional cross targets are wasm32-wasi, wasm32-bare, and rv32imac-bare. WASI exceptions are unsupported, so a project selecting wasm32-wasi must not set exceptions = true.

An included fragment might contain the shared target and linker configuration:

// board_support/project/stm32f746.dqproj

linkerpath = '\{THIS_DIR}/../lib'
linkscript = '\{THIS_DIR}/../ld/stm32f746.ld'

3.6.2 Lexical Rules

The format uses DQ-like identifiers, strings, comments, and statement terminators. Property and keyword names are case-sensitive.

An identifier starts with an ASCII letter or _ and may continue with ASCII letters, decimal digits, or _:

FEATURE
CPU_CLOCK_HZ
board2

Strings may use single or double quotes. They must end on the same physical line on which they begin.

'src/main.dq'
"arm_m7f-bare"

The recognized string escapes are:

Escape Result
\n newline character
\r carriage return
\t tab
\\ backslash
\" double quote
\' single quote

An unrecognized escape is preserved as a backslash followed by the escaped character.

Both DQ comment forms are supported:

// line comment

/* block
   comment */

An unterminated string or block comment is an error.

Statements normally end at a newline. A semicolon is optional at the end of a statement and is required between multiple statements on the same line:

main = 'main.dq'
output = 'app'

main = 'main.dq'; output = 'app'

The parts of one statement, including =, its value, and the arguments of PackagePath(), may not continue onto another line.

3.6.3 Statements

A project consists of property assignments and three special statements: define, var, and include.

property = value
define NAME
define NAME = value
var NAME = value
include 'file.dqproj'

Unknown properties, invalid value types, trailing tokens, and duplicate single-value properties are errors.

3.6.3.1 Properties

Property Value Repetition Meaning
main path string once, required DQ source file compiled as the project entry module.
output path string once, optional Final executable or object filename. Normal compiler output defaults apply when omitted.
target string once, optional Compiler target name, using the same names accepted by --target.
build_tag nonempty string once, optional Base name of the .dqbuild artifact directory; defaults to the selected target name.
build_suffix nonempty string once, optional Append -<suffix> to the selected build tag.
sysroot path string once, optional Target system root passed to the Clang linker driver for hosted cross builds.
cpu_features string once, optional Append LLVM CPU feature flags to the target defaults, separated by commas.
pkg_path path string repeatable Add a DQ package search root (packagepath is a compatibility alias).
pkg name:directory string repeatable Map one package directly to a source directory; overrides all search roots.
link boolean once, optional Force linking when true; compile only when false.
static boolean once, optional Pass -static to the linker when true, equivalent to --static or --linker-arg=-static. Defaults to false, which adds no linker argument.
exceptions boolean once, optional Enable or disable DQ exception handling. Defaults to enabled on hosted targets and disabled on bare targets; wasm32-wasi always disables and rejects enabling exceptions.
dynstrings boolean once, optional Enable or disable heap-backed dynamic strings. Defaults to enabled on hosted targets and disabled on bare targets.
compiler_runtime string once, optional Bare-target compiler support runtime: libgcc (default) or none.
c_runtime string once, optional Bare-target C runtime: newlib-nano (default) or none.
linkobject path string repeatable Add an existing object or other positional linker input.
linkerpath path string repeatable Pass --library-path=<path> to the linker.
linkoption string repeatable Pass one argument directly to the linker.
linkscript path string once, optional Pass --script=<path> to the linker.
debuginfo boolean once, optional Enable or disable debug information.
optlevel integer or string 0 through 3, or string 's' or 'z' once, optional Set the optimization level. Numeric levels may be quoted or unquoted; 's' and 'z' optimize for size.
lto boolean once, optional Enable full LTO when true; disable LTO when false.

main is required only after the top-level file and all its includes have been assembled. An included fragment therefore does not need its own main. output is always optional.

For example:

build_tag = 'stm32f746'
build_suffix = 'debug'

This selects .dqbuild/stm32f746-debug/. Either property may be used alone, and both support project-variable expansion such as \{PROJECT_NAME}.

The cpu, abi, and floatabi property names are reserved for future target tuning. They are currently rejected as unsupported. They are not silently ignored.

Without a link property, the compiler retains its automatic link mode:

  • A hosted target links a module that contains *Main.
  • A bare target produces an object by default.

link = true is equivalent to explicitly selecting --link. It can force a bare target to link an ELF image. link = false is equivalent to -c and always requests compile-only output.

3.6.3.3 Exception Handling

Exception handling is enabled by default for hosted targets and disabled by default for bare targets. Projects can override the target default explicitly:

exceptions = false

When enabled, the compiler defines EXCEPTIONS in the @def scope, so source and RTL code can select exception-dependent code with #ifdef EXCEPTIONS. Disabling exceptions removes native unwind generation and rejects try, except, finally, and raise; runtime checks remain enabled and report through the RuntimeError hook.

3.6.3.4 Dynamic Strings

Dynamic strings are enabled by default for hosted targets and disabled by default for bare targets. Projects can override the target default explicitly:

dynstrings = true

When enabled, the compiler defines DYNSTRINGS in the @def scope. When disabled, heap-owning str declarations, conversions, concatenation, and methods are rejected with DynStringsDisabled. Non-owning and bounded text facilities—text literals, rostr, strslice, and bounded embstr—remain available.

3.6.3.5 Bare-Metal Runtimes

For supported bare-metal targets, the compiler selects bundled libraries that match the target CPU and floating-point ABI. The defaults are equivalent to:

compiler_runtime = 'libgcc'
c_runtime = 'newlib-nano'

compiler_runtime supplies compiler-generated ABI helper routines and, when exceptions are enabled, the C++ exception ABI support and target unwinder. c_runtime supplies Newlib Nano and its no-system fallback stubs, and makes the matching bundled math library available to #linklib('m'). Static archive members are included only when referenced. Board or application implementations override the fallback stubs and must provide functional system calls where the application requires them.

Either property may be set to none when the application supplies that part of the runtime explicitly. These properties are rejected for hosted targets, whose runtime libraries continue to be selected by the system linker driver.

3.6.3.6 Defines

define creates a symbol in the compiler's @def scope:

define FEATURE
define LOGGING = true
define TRACE = false
define BUFFER_SIZE = 4096
define OFFSET = -16

A define without a value has boolean value true. Explicit values are limited to true, false, or a signed 64-bit decimal integer. Strings, hexadecimal integers, expressions, and variables are not accepted as define values.

Define names are identifiers and must be unique throughout the assembled project, including all included files. A command-line -DNAME or -DNAME=value replaces the project define with the same name.

Project defines are inherited by imported child modules.

3.6.4 Paths

The following properties contain paths:

  • main
  • output
  • pkg_path
  • The directory part of pkg
  • linkobject
  • linkerpath
  • linkscript
  • include

After variable expansion, a relative path is resolved against the directory of the file containing that statement. The result is converted to an absolute, lexically normalized path. This rule applies independently to every included file.

For example, in project/boards/board.dqproj:

linkscript = '../ld/board.ld'

the path is relative to project/boards, not to the process working directory or the top-level project directory.

The project parser requires included files, mapped pkg directories, and PackagePath() results to exist. It does not check the existence of main, output, pkg_path, linkobject, linkerpath, or linkscript; the compiler, filesystem, or linker reports problems with those paths when they are used.

3.6.5 Variables

A variable stores a path for later substitution. Its value must be either a quoted path string or the result of PackagePath():

var SOURCE_DIR = 'src'
var SDK = PackagePath('sdk')

main = '\{SOURCE_DIR}/main.dq'
include '\{SDK}/project/common.dqproj'

A relative quoted value is resolved against the directory of the file that declares the variable. Consequently, it keeps the same meaning when it is used later from a different included file.

Variable references use only the explicit \{NAME} form. Expansion is performed inside all quoted project values, including path properties, target, linkoption, include paths, and PackagePath() arguments.

Variable names are case-sensitive, must be declared before use, and are shared through includes. A variable cannot be declared more than once. User variables also cannot redefine a built-in variable:

Variable Meaning
\{PROJECT_NAME} Name of the top level .dqproj file, without extension
\{PROJECT_DIR} Directory containing the top-level .dqproj file.
\{THIS_DIR} Directory containing the file with the current statement.

The project language does not expand environment variables, ~, $NAME, or %NAME%. Dollar signs have no special meaning. Write \\{NAME} to insert literal \{NAME} text without expanding a variable.

3.6.6 Package Lookup

PackagePath() locates a package using the same package-root resolver as a DQ use statement:

var SDK = PackagePath('sdk')

The argument must expand to one identifier. If /opt/dq/packages/sdk is the selected package, the function returns the absolute normalized path /opt/dq/packages/sdk, not /opt/dq/packages.

Packages are selected using the following precedence, highest first:

  1. Command-line --pkg mappings for that package name.
  2. Project pkg mappings already encountered for that package name.
  3. Command-line --pkg_path roots.
  4. Project pkg_path roots already encountered.
  5. Compiler default package roots.

Within each level, the last matching entry wins. Explicit mappings always take priority over search roots, including a project mapping over a command-line root.

Command-line package roots and mappings are collected before the project is evaluated, so they are available to every PackagePath() call regardless of command-line position. Project pkg_path and pkg settings become available only after their statements are evaluated. Includes follow the same textual ordering rule.

For example:

pkg_path = '../dqpkg'
pkg = 'board:../boards/adcif'
var BOARD = PackagePath('board')

This binds board to ../boards/adcif, even if a search root contains another board directory. use board selects ../boards/adcif/board.dq, while use board/pins selects ../boards/adcif/pins.dq. Package-qualified includes, ^/ paths, and language-server navigation use the same mapping.

The mapping is split at the first colon. The name must be one identifier; variable expansion applies to the whole string, and only the directory part is resolved relative to the file containing the statement. Spaces and further colons are part of the directory, including Windows drive prefixes.

A missing or inaccessible mapped directory is an error when the declaration is processed. A missing module or include inside a mapped package does not fall back to search roots. A missing PackagePath() package is also a project error.

The old project spelling packagepath remains an alias for pkg_path. On the command line, --pkg_path and --pkg accept either --option=value or --option value; --pkg-path remains an alias for --pkg_path. CLI directory paths are relative to the process working directory.

3.6.7 Includes

An include inserts another .dqproj file at the point of the statement:

include 'common.dqproj'
include '\{SDK}/project/board.dqproj'

The path is expanded and resolved relative to the including file. Included files must also use the .dqproj extension.

Includes behave like textual insertion with file-local path anchoring:

  • Variables declared before an include are visible inside it.
  • Variables declared by an included file remain visible after it returns.
  • pkg_path and pkg statements affect later PackagePath() calls.
  • Single-property, variable, and define duplicate checks span all files.
  • Repeatable property ordering follows statement order across includes.

The same file may be included again after its earlier inclusion has completed. Normal duplicate rules still apply to the repeated statements. Including a file that is already active is a cycle and is rejected with the canonical include chain.

3.6.8 Linker Argument Ordering

linkerpath, linkscript, linkoption, and static = true produce linker arguments in their assembled project statement order. Included statements retain their position in that order. Command-line --linker-arg=<arg> and --static entries follow all project linker arguments.

The compiler constructs linker inputs in this order:

  1. The object generated for main.
  2. Objects generated for imported DQ modules.
  3. Project linkobject inputs, in statement order.
  4. -o and the final output filename.
  5. Libraries requested by DQ modules.

Each project or command-line linker argument is passed through the compiler driver as one linker argument before those positional inputs. -static is passed directly to the driver so it also selects static startup files and runtime libraries.

Project parsing does not verify that linker objects, library paths, or linker scripts exist. Such errors are reported by the linker.

3.6.9 Command-Line Precedence

The project is parsed before normal command-line option evaluation and before target-dependent compiler initialization. Project values act as defaults; explicit command-line selections are then applied on top.

Setting Precedence
Target --target overrides target; otherwise the project target overrides the host default.
Build tag --build or its alias --build-tag overrides build_tag; otherwise the selected target name is used when build_tag is absent.
Build suffix --build-suffix overrides build_suffix. The effective suffix is appended once to the effective build tag, including a tag selected by --build.
CPU features --cpu-features= overrides cpu_features; the effective value is appended to the selected target defaults.
Output -o overrides output; otherwise normal output defaults apply when the property is absent.
Optimization -O0 through -O3, -Os, and -Oz override optlevel.
Debug information -g enables debug information even when debuginfo = false. There is currently no command-line option to force it off.
LTO --lto or --lto=full|off overrides lto.
Exceptions --exceptions or --no-exceptions overrides exceptions; the last command-line flag wins.
Dynamic strings --dynstrings or --no-dynstrings overrides dynstrings; the last command-line flag wins.
Link mode The first explicit -c or --link replaces the project mode. Conflicting subsequent command-line link modes are errors.
Defines The first command-line definition of a name removes the project definition of that name.
Package roots Command-line roots have higher lookup precedence than project and default roots.
Linker arguments Project arguments precede command-line --linker-arg and --static entries.

The project target is selected early enough to initialize target-dependent built-in types correctly. Imported child modules inherit the effective target, optimization level, debug and LTO settings, defines, build settings, and package roots through compiler arguments. Child compilations receive the resolved .dq source file and do not parse the project again.

3.6.10 Errors and Diagnostics

Project evaluation stops at the first error. Diagnostics identify the file, line, column, diagnostic identifier, and message:

/work/app/application.dqproj(12,8) ERROR(ProjectValue): optlevel must be 0 through 3, 's', or 'z'

Project errors include, among others:

  • unreadable project or include files;
  • wrong project extensions;
  • malformed strings, comments, or statements;
  • unknown, duplicate, or unsupported properties;
  • invalid property types or values;
  • duplicate or unknown variables;
  • duplicate project defines;
  • missing packages;
  • include cycles;
  • an assembled project without main.

3.6.11 Compact Grammar

The following grammar is descriptive. newline or ; terminates a statement, and the final statement may end at end-of-file.

project       := { terminator | statement terminator } [ statement ] EOF

statement     := property '=' property-value
               | 'define' identifier [ '=' define-value ]
               | 'var' identifier '=' variable-value
               | 'include' string

property      := 'main' | 'output' | 'target' | 'build_tag' | 'build_suffix'
               | 'pkg_path' | 'packagepath' | 'pkg'
               | 'link' | 'static' | 'linkobject' | 'linkerpath' | 'linkoption'
               | 'linkscript' | 'debuginfo' | 'optlevel' | 'lto'
               | 'exceptions' | 'dynstrings' | 'cpu_features'

property-value := string | boolean | signed-decimal-integer
variable-value := string | 'PackagePath' '(' string ')'
define-value   := boolean | signed-decimal-integer
boolean        := 'true' | 'false'
terminator     := newline | ';'

Whitespace and comments may occur between tokens as long as they do not move the remainder of the current statement onto another line.