Open CyberTailor opened 2 years ago
So write (and contribute!) a tool that translates the json file into whatever format that you need.
So write (and contribute!) a tool that translates the json file into whatever format that you need.
I haven't found a command that generates file's dependencies. Does it exist?
The json file is always produced in nimcache.
Hmm. nim c --genScript:on main
generates such list of files
(main.depend
). So I guess a tool can be used to convert it to a
depfile and we call it a day.
However if its format was standard depfile and it was allowed to set a custom output path for that file, things would be simpler.
Nonstandard formats will not be understood by ninja / cmake / meson unless you "write (and contribute!) a tool" that both runs the compiler and converts the nonstandard format.
Makefile rules are inherently embedded shell scripts, so you can write an inline Makefile wrapper script that first runs the compiler, then runs the tool, which isn't as bad. But this doesn't work generically.
If the goal is for the compiler to support "all common build systems" then there is no alternative and no half measure -- you need the compiler itself to support the standard format.
If the goal is for "all common build systems" to specifically support the compiler, then each build system would need to have a feature request opened + accepted + implemented to have the build system support the nonstandard format. This might prove challenging.
and it was allowed to set a custom output path for that file
While it is more flexible to support a custom output path for the depfile, it isn't really required. Neither ninja nor make nor cmake nor meson require that the depfile path appear as part of the compiler rule -- they merely require that the rule ultimately creates the depfile, and that the build system knows which path to look for the depfile at. For example,
gcc -MD path/to/foo.c -c -o path/to/foo.o
defaults to creating a depfile at path/to/foo.d
.
-MF alternative/path/to/foo.o.d
--output-dep-file
which for output files like path/to/moc_foo.cpp
defaults to create path/to/moc_foo.cpp.d
.
--dep-file-path alternative/path/to/moc_foo.d
So:
--nimcache
might be needed. It might be wanted regardless...Implemented in PR https://github.com/nim-lang/Nim/pull/19960
https://github.com/status-im/nimbus-eth2/blob/unstable/tools/generate_makefile.nim - here's an example a tool that generates makefile rules from the json
uninteresting, per comment below
There seems to be a misunderstanding here. The depfile
needs to show a list of files that Nim read during the compilation process, not the list of compiled C sources. As a specific example, an included nim file should be part of the depfile, but it won't be mentioned at all in the json file. Slurped files, config files, etc are other build process inputs that belong to the depfile.
I've just learned that the --run
option produces a proper list of depfiles stored in the nimcache json, so it looks like it just needs to be wired to a separate new option.
I've just learned that the --run option produces a proper list of depfiles stored in the nimcache json, so it looks like it just needs to be wired to a separate new option.
@zah Hi, -d:nimBetterRun
exists, which produces proper depfiles and doesn't actually run the executable.
Title
Depfile
Abstract
Add a new command-line option (e.g.
--depfile
) for thenim compile
command. It accepts an argument (output path for a depfile, generated for a given target).Motivation
This change would improve Nim integrations with language-independent build systems. Particularly, get better edit-compile cycle times.
Currently a build system needs to rebuild a binary if any of source files has been changed, even if they aren't used by the binary. The full list of files that a given source file depends on can only be discovered by the compiler.
It doesn't need to be a standalone command because if the file has never been compiled, it must be built anyway, generating dependencies as a side effect.
Description
Downside: growing number of command-line flags :)
Similar proposal: #412. However custom JSON format will not be understood by build systems.
Depfile file format
From GCC manual (
-M
option):Or, in the BNF notation:
https://cmake.org/cmake/help/latest/command/add_custom_command.html
It is recognized by all common build systems.
Code Examples
Before
(no command to produce a depfile)
After
Use the depfile in Makefile
Use the depfile in Ninja
Use the depfile in CMake
Use the depfile in Meson
Backwards Compatibility
This RFC introduces no backward-incompatible changes.