Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig build system #204

Closed
8 of 12 tasks
andrewrk opened this issue Oct 6, 2016 · 10 comments
Closed
8 of 12 tasks

zig build system #204

andrewrk opened this issue Oct 6, 2016 · 10 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Oct 6, 2016

This competes with cmake, autotools, ninja, make, etc. The user creates build.zig, a script which imports a library and adds things to build. The idea is for this to actually be an even better way to build even C and C++ projects than cmake, autotools, or make itself. And of course it will support building zig projects.

It should also do package management and resource file management which would provide C and C++ projects a way to have painless dependencies like other languages have.

build.zig can of course have arbitrary logic in it, but at the heart is a library that zig will provide such that targets can be defined in a declarative way, and repeated executions of the build script will do no more work than necessary.

  • hello world build system
  • if build succeeds, delete the ./build program
  • upgrade tetris project to use the build system
  • upgrade clashos project to use the build system
  • make --zig-verbose do the firehose and --verbose just print the commands before executing them
  • use a proper unique filename for linker script and delete it on success
  • build a C project with it
  • support building an object
  • support building a library
  • avoid unnecessary work such as recompiling a zig exe that has not changed, recompiling the build script itself if it has not changed
  • support the concept of multiple targets and arbitrary targets like "Run my tests"
  • add support for build options
@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Oct 6, 2016
@fsaintjacques
Copy link
Contributor

fsaintjacques commented Oct 22, 2016

Would it be possible to create a "tools" label.

@andrewrk andrewrk added the tools label Oct 25, 2016
@andrewrk
Copy link
Member Author

Done.

@fsaintjacques
Copy link
Contributor

What's your opinion on the rust way?

My shopping list would go as follow:

  • Declarative by default, programability should be used in extreme cases
  • Dependency management, possibly with central repository, sources are pulled not object files
  • Mandatory formatting (go fmt)
  • Mandatory documentation (javadoc/doxygen), test phase requires that every pub function/struct is documented
  • Standardize directory structure: {src,examples,tests,README.md}

I do not want that C/C++ build system limitations impede/leak on this tool.

Finally, since this is zig lang, the build tool has to be named zag.

@andrewrk
Copy link
Member Author

Declarative by default, programability should be used in extreme cases

On board. Zig has no preprocessor, no macros, instead has a declarative approach to solving these problems.

Dependency management, possibly with central repository, sources are pulled not object files

Same except no central repository. Instead there will be a variety of ways to obtain source as well as specifying a hash to ensure that correct dependencies were obtained. At any point you can update a dependency or all dependencies which will update the hashes.

Mandatory formatting (go fmt)

Zig compiler will have an error for mis-indented code (see #35). Hard tabs are already a syntax error. Beyond that, I think we will have zig fmt but it will be left up to the user to decide how to integrate this tool into their development process.

Mandatory documentation (javadoc/doxygen), test phase requires that every pub function/struct is documented

We do have a way to specify documentation comments in the source code, but no docs are automatically generated yet (see #21). I doubt that we will make it mandatory as this leads to pointless documentation (window.setMaximized() // this function sets the window to be maximized). Further, it's not Zig's business to tell the user they have to do more work to get their code to run. This is open for discussion, as are all the other assertions I'm making here.

Standardize directory structure: {src,examples,tests,README.md}

At the very least I think that Zig will recommend a directory structure. I haven't thought about how, if at all, this would be enforced.

I'm starting to think that maybe we could have a zig lint command which would lint a package to make it ready for publishing. It wouldn't actually send the code anywhere; it would simply check directory structure, code formatting, whether things were documented, etc, and print an OK message or errors. You could still depend on the package without going through this step.

I do not want that C/C++ build system limitations impede/leak on this tool.

Do you have any specific limitations in mind?

The way that I see it happening is that we have a declarative way to specify C/C++ targets. Not a DSL; just zig library code that integrates into the build system. We could also add to this library knowledge of how to build other language targets. And then finally a custom target interface. Ideally this build system would be useful no matter what language or platform you were building on.

Finally, since this is zig lang, the build tool has to be named zag.

Cute. But it will probably just be a subcommand of zig: zig build.

@andrewrk andrewrk added this to the 0.1.0 milestone Mar 30, 2017
andrewrk added a commit that referenced this issue Mar 31, 2017
 * `zig build --export [obj|lib|exe]` changed to `zig build_obj`,
   `zig build_lib` and `zig build_exe` respectively.
 * `--name` parameter is optional when it can be inferred from the
   root source filename. closes #207
 * `zig build` now looks for `build.zig` which interacts with
   `std.build.Builder` to describe the targets, and then the zig
   build system prints TODO: build these targets. See #204
 * add `@bitcast` which is mainly used for pointer reinterpret
   casting and make explicit casting not do pointer reinterpretation.
   Closes #290
 * fix debug info for byval parameters
 * sort command line help options
 * `std.debug.panic` supports format string printing
 * add `std.mem.IncrementingAllocator`
 * fix const ptr to a variable with data changing at runtime.
   closes #289
andrewrk added a commit that referenced this issue Apr 2, 2017
 * In-progress os.ChildProcess.spawn implementation. See #204
 * Add explicit cast from integer to error. Closes #294
 * fix casting from error to integer
 * fix compiler crash when initializing variable to undefined
   with no type
andrewrk added a commit that referenced this issue Apr 3, 2017
andrewrk added a commit that referenced this issue Apr 3, 2017
 * See #204 - zig build system
 * allow builtin types Os, Environ, Arch to be used at runtime.
   they have zero_bits=false and debug info now.
 * Eradicate use of `@alloca` in std for syscalls. See #225
 * add `std.io.writeFile`
 * `std.debug.panic` adds a newline to format
andrewrk added a commit that referenced this issue Apr 4, 2017
 * add std.buf_map.BufMap
 * add std.buf_set.BufSet
 * add std.mem.split
 * zig build system improvements (See #204)
   - automatically parses NIX_CFLAGS_COMPILE and NIX_LDFLAGS
   - add builder.addCIncludePath
   - add builder.addRPath
   - add builder.addLibPath
   - add exe.linkLibrary
@dumblob
Copy link

dumblob commented Apr 5, 2017

The outlined ideas sound good and I can actually see three directions of development:

  1. A lightweight fully multiplatform cmake/make/configure/... like tool which is totally self-contained and has strong metaprogramming capabilities like Premake (metaprogramming would allow writing a tiny module supporting all the needed specialities like code_fmt/doc_gen/auto_test/... of Zig).
  2. A very own code_fmt/doc_gen/auto_test/... tool written from scratch and fitting just the needs of Zig (e.g. as Dao did with its daomake).
  3. Using Ekam (or rewriting the tool to Zig, but retaining the very same functionality, syntax compatibility and behavior).

My strongest preference would be for the third option (Ekam) as the second option is shit loads of work and testing (will take years due to platform differences as it took daomake) without basically any benefits compared to the other two options. And the first option (Premake) is though a very good one, but still can't catch up with the modern view and simplicity of the third option.

@andrewrk
Copy link
Member Author

andrewrk commented Apr 5, 2017

Ekam works by exploration. For example, when it encounters a file ending in ".cpp", it tries to compile the file, intercepting system calls to find out its dependencies (e.g. included headers). If some of these are missing, Ekam continues to explore...

While I admire the bravado of this approach, it's pretty antithetical to Zig's principles, which is an explicit, straightforward, low complexity approach to solve problems.

Most of what Ekam does is not necessary when compiling Zig software because in Zig there is a single entry point source file which imports explicitly all the other files it will use.

However, Zig is intended to integrate into a legacy C/C++/native project, and as such it is possible that Zig will plug into the build process in the middle of it. Whether the Zig Build System gets to own the whole build process or not, this should work in a way that is well-understood and not up to heuristics.

I'm actually going for something closer to (1) as outlined above. I see it as a bargaining chip to break into legacy projects. "You're not adding a dependency on Zig, you're trading your cmake dependency for it." Then once people have Zig as a dependency, it becomes easier to want to use it more - at first as a package manager, then maybe to write a simple dev tool, and then possibly implementing some of the project in it.

@dumblob
Copy link

dumblob commented Apr 5, 2017

Ekam works by exploration. For example, when it encounters a file ending in ".cpp", it tries to compile the file, intercepting system calls to find out its dependencies (e.g. included headers). If some of these are missing, Ekam continues to explore...

If you read further (and the source code), this is just an icing on the cake. The core is, that you can specify everything (including dependencies and any other stuff unrelated to building, but project management, automation, etc.) and do not need to rely on heuristics. Heuristics was though the initial idea and thus it's mentioned at the beginning. But yeah, Kenton is not a good marketing person, so his description might be misleading. Ekam shall play nicely with other build systems, but is not polished enough yet, so it might undergo pretty significant changes. I mentioned Ekam as it's a very modular and KISS approach offering both leisureness and rigidness if needed.

Anyway, if you lean towards (1), I would advocate for Premake 😉.

andrewrk added a commit that referenced this issue Apr 6, 2017
 * Fix assertion failure when switching on type.
   Closes #310
 * Update zig build system to support user defined options.
   See #204
 * fmt.format supports {sNNN} to set padding for a buffer arg.
 * add std.fmt.bufPrint and std.fmt.allocPrint
 * std.hash_map.HashMap.put returns the previous value
 * add std.mem.startsWith
@andrewrk
Copy link
Member Author

This feature now exists and is a big enough topic that it has its own set of multiple issues.

@0joshuaolson1
Copy link

This feature is not documented. Where should general discussion go?

@andrewrk
Copy link
Member Author

Feel free to open issues discussing anything about it. The lack of documentation issue is #367
Documentation for it is in 2 parts: the overview, which will be in the language reference, and the std lib API, which will be solved with #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
Development

No branches or pull requests

4 participants