A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/ziglang/zig/wiki/Contributing below:

Contributing · ziglang/zig Wiki · GitHub

Strict No LLM / No AI Policy

No LLMs for issues

No LLMs for patches / pull requests.

No LLMs for comments on the bug tracker, including translation.

English is encouraged, but not required. You are welcome to post in your native language and rely on others to have their own translation tools of choice to interpret your words.

We are makers, not consumers.

Start a Project Using Zig

One of the best ways you can contribute to Zig is to start using it for a personal project. Great examples can be found on the Community Projects Wiki.

Without fail, these projects lead to discovering bugs and helping flesh out use cases, which lead to further design iterations of Zig. Importantly, each issue found this way comes with real world motivations, making it straightforward to explain the reasoning behind proposals and feature requests.

Ideally, such a project will help you to learn new skills and add something to your personal portfolio at the same time.

Another way to contribute is to write about Zig, speak about Zig at a conference, or do either of those things for your project which uses Zig. Here are some examples:

Programming languages live and die based on the pulse of their ecosystems. The more people involved, the more we can build upon each other's abstractions and build great things.

Finding a Contributor Friendly Issue

The issue label Contributor Friendly exists to help you find issues that are limited in scope and/or knowledge of Zig internals.

Please note that issues labeled Proposal but do not also have the Accepted label are still under consideration, and efforts to implement such a proposal have a high risk of being wasted. If you are interested in a proposal which is still under consideration, please express your interest in the issue tracker, providing extra insights and considerations that others have not yet expressed. The most highly regarded argument in such a discussion is a real world use case.

First, build zig from source.

For a smooth workflow, it is recommended to use CMake with the following settings:

After configuration, there are two scenarios:

  1. Pulling upstream changes and rebuilding.
  2. Building from source after making local changes.

This leaves you with two builds of Zig:

stage4/bin/zig build test -Denable-llvm

This command runs the whole test suite, which does a lot of extra testing that you likely won't always need, and can take upwards of 1 hour. This is what the CI server runs when you make a pull request.

To save time, you can add the --help option to the zig build command and see what options are available. One of the most helpful ones is -Dskip-release. Adding this option to the command above, along with -Dskip-non-native, will take the time down from around 2 hours to about 30 minutes, and this is a good enough amount of testing before making a pull request.

Another example is choosing a different set of things to test. For example, test-std instead of test will only run the standard library tests, and not the other ones. Combining this suggestion with the previous one, you could do this:

stage4/bin/zig build test-std -Dskip-release

This will run only the standard library tests in debug mode for all targets. It will cross-compile the tests for non-native targets but not run them.

When making changes to the compiler source code, the most helpful test step to run is test-behavior. When editing documentation it is docs. You can find this information and more in the zig build --help menu.

Directly Testing the Standard Library with zig test

This command will run the standard library tests under a small number of configurations and is estimated to complete in 3 minutes:

zig build test-std -Dskip-release -Dskip-non-native

However, one may also use zig test directly. From inside the ziglang/zig repo root:

zig test lib/std/std.zig --zig-lib-dir lib

You can add --test-filter "some test name" to run a specific test or a subset of tests. (Running exactly 1 test is not reliably possible, because the test filter does not exclude anonymous test blocks, but that shouldn't interfere with whatever you're trying to test in practice.)

Note that --test-filter filters on fully qualified names, so e.g. it's possible to run only the std.json tests with:

zig test lib/std/std.zig --zig-lib-dir lib --test-filter "json."
Testing Non-Native Architectures with QEMU

The Linux CI server additionally has qemu installed and sets -fqemu. This provides test coverage for, e.g. aarch64 even on x86_64 machines. It's recommended for Linux users to install qemu and enable this testing option when editing the standard library or anything related to a non-native architecture.

Note that QEMU packages provided by some system package managers (such as Debian) may be a few releases old, or may be missing newer targets such as aarch64 and RISC-V. If you're interested in obtaining static binaries of the latest QEMU version, this repo may be of interest: ziglang/qemu-static

Testing Non-Native glibc Targets

Testing foreign architectures with dynamically linked glibc is one step trickier. This requires enabling --glibc-runtimes /path/to/glibc/multi/install/glibcs. This path is obtained by building glibc for multiple architectures. This process for me took an entire day to complete and takes up 65 GiB on my hard drive. The CI server does not provide this test coverage. Instructions for producing this path can be found on the wiki. Just the part with build-many-glibcs.py.

It is understood that most contributors will not have these tests enabled.

Testing Windows from a Linux Machine with Wine

When developing on Linux, another option is available to you: -fwine. This will enable running behavior tests and std lib tests with Wine. It's recommended for Linux users to install Wine and enable this testing option when editing the standard library or anything Windows-related.

Testing WebAssembly using wasmtime

If you have wasmtime installed, take advantage of the -fwasmtime flag which will enable running WASI behavior tests and std lib tests. It's recommended for all users to install wasmtime and enable this testing option when editing the standard library and especially anything WebAssembly-related.

Please read the Editing Source Code section as a prerequisite to this one.

translate-c is a feature provided by Zig that converts C source code into Zig source code. It powers the zig translate-c command as well as @cImport, allowing Zig code to not only take advantage of function prototypes defined in .h files, but also static inline functions written in C, and even some macros.

This feature works by using libclang API to parse and semantically analyze C/C++ files, and then based on the provided AST and type information, generating Zig AST, and finally using the mechanisms of zig fmt to render the Zig AST to a file.

The relevant tests for this feature are:

Legacy translate-c tests:

This feature is self-hosted, even though Zig is not fully self-hosted yet. In the Zig source repo, we maintain a C API on top of Clang's C++ API:

Finally, the actual source code for the translate-c feature is src/translate_c.zig. This code uses the Clang C API exposed by src/clang.zig, and produces Zig AST.

The steps for contributing to translate-c look like this:

  1. Identify a test case you want to improve. Add it as a run-translated-c test case (usually preferable), or as a translate-c test case.

  2. Edit src/translate_c.zig to improve the behavior.

  3. Run your test: ./zig build test-cases -Dtest-filter="my_specific_and_unique_test_file_name"

  4. Run the relevant tests: ./zig build test-cases test-run-translated-c test-translate-c

Autodoc is an interactive, searchable, single-page web application for browsing Zig codebases.

An autodoc deployment looks like this:

index.html
main.js
main.wasm
sources.tar

These artifacts are produced by the compiler when -femit-docs is passed.

The command zig std spawns an HTTP server that provides all the assets mentioned above specifically for the standard library.

The server creates the requested files on the fly, including rebuilding main.wasm if any of its source files changed, and constructing sources.tar, meaning that any source changes to the documented files, or to the autodoc system itself are immediately reflected when viewing docs.

This means you can test changes to Zig standard library documentation, as well as autodocs functionality, by pressing refresh in the browser.

Prefixing the URL with /debug results in a debug build of main.wasm.

While Firefox and Safari support are obviously required, I recommend Chromium for development for one reason in particular:

C/C++ DevTools Support (DWARF)

This makes debugging Zig WebAssembly code a breeze.

The system expects the top level of sources.tar to be the set of modules documented. So for the Zig standard library you would do this: tar cf std.tar std/. Don't compress it; the idea is to rely on HTTP compression.

Any files that are not .zig source files will be ignored by main.wasm, however, those files will take up wasted space in the tar file. For the standard library, use the set of files that zig installs to when running zig build, which is the same as the set of files that are provided on ziglang.org/download.

If the system doesn't find a file named "foo/root.zig" or "foo/foo.zig", it will use the first file in the tar as the module root.

You don't typically need to create sources.tar yourself, since it is lazily provided by the zig std HTTP server as well as produced by -femit-docs.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4