Compare commits

..

6 commits

Author SHA1 Message Date
Andrew Kelley
3db960767d Release 0.15.1 2025-08-19 16:20:53 -07:00
Justus Klausecker
43ced7d147 expose darwin.PT in std.c 2025-08-19 16:19:09 -07:00
Carl Åstholm
8af682b13a Fix bugs in Windows readVec implementations 2025-08-19 16:19:06 -07:00
TemariVirus
c3aa650646 std.Io.Writer: fix upper case hex float formatting 2025-08-19 16:01:45 -07:00
Rohlem
6cdbf4223c never advance seek position in std.Io.Reader.peekDelimiterExclusive (#24899)
* extend std.Io.Reader.peekDelimiterExclusive test to repeat successful end-of-stream path (fails)

* fix std.Io.Reader.peekDelimiterExclusive to not advance seek position in successful end-of-stream path
2025-08-19 16:01:40 -07:00
Andrew Kelley
f54f061fb3 start the 0.15.1 release cycle 2025-08-19 16:01:09 -07:00
8290 changed files with 476198 additions and 791692 deletions

View file

@ -1,13 +0,0 @@
contact_links:
- name: Language Proposal
about: "Please do not submit a proposal to change the language"
url: https://ziglang.org/code-of-conduct/#no-language-proposals
- name: Question
about: "Please use one of the community spaces instead for questions or general discussions."
url: https://ziglang.org/community
- name: C Translation
about: "Issues related to `zig translate-c` and `@cImport` are tracked separately."
url: https://codeberg.org/ziglang/translate-c
- name: Copilot and Other LLMs
about: "Please do not use GitHub Copilot or any other LLM to write an issue."
url: https://ziglang.org/code-of-conduct/#strict-no-llm-no-ai-policy

View file

@ -1,303 +0,0 @@
name: ci
on:
pull_request:
push:
branches:
- master
workflow_dispatch:
# This cancels older workflow runs on pull requests while ensuring that there
# are no concurrency limits on pushes and manual workflow dispatches.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
aarch64-freebsd-debug:
runs-on: [self-hosted, aarch64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-freebsd-debug.sh
timeout-minutes: 300
aarch64-freebsd-release:
runs-on: [self-hosted, aarch64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-freebsd-release.sh
timeout-minutes: 240
aarch64-linux-debug:
runs-on: [self-hosted, aarch64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-linux-debug.sh
timeout-minutes: 180
aarch64-linux-release:
runs-on: [self-hosted, aarch64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
timeout-minutes: 120
aarch64-netbsd-debug:
runs-on: [self-hosted, aarch64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-netbsd-debug.sh
timeout-minutes: 300
aarch64-netbsd-release:
runs-on: [self-hosted, aarch64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-netbsd-release.sh
timeout-minutes: 240
aarch64-macos-debug:
runs-on: [self-hosted, aarch64-macos]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-macos-debug.sh
timeout-minutes: 180
aarch64-macos-release:
runs-on: [self-hosted, aarch64-macos]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/aarch64-macos-release.sh
timeout-minutes: 120
loongarch64-linux-debug:
runs-on: [self-hosted, loongarch64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/loongarch64-linux-debug.sh
timeout-minutes: 240
loongarch64-linux-release:
runs-on: [self-hosted, loongarch64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/loongarch64-linux-release.sh
timeout-minutes: 180
powerpc64le-linux-debug:
runs-on: [self-hosted, powerpc64le-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/powerpc64le-linux-debug.sh
timeout-minutes: 360
powerpc64le-linux-release:
runs-on: [self-hosted, powerpc64le-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/powerpc64le-linux-release.sh
timeout-minutes: 240
riscv64-linux-debug:
if: github.event_name != 'pull_request'
runs-on: [self-hosted, riscv64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
timeout-minutes: 660
riscv64-linux-release:
if: github.event_name != 'pull_request'
runs-on: [self-hosted, riscv64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/riscv64-linux-release.sh
timeout-minutes: 540
s390x-linux-debug:
runs-on: [self-hosted, s390x-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/s390x-linux-debug.sh
timeout-minutes: 360
s390x-linux-release:
runs-on: [self-hosted, s390x-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/s390x-linux-release.sh
timeout-minutes: 300
x86_64-freebsd-debug:
runs-on: [self-hosted, x86_64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-freebsd-debug.sh
timeout-minutes: 120
x86_64-freebsd-release:
runs-on: [self-hosted, x86_64-freebsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-freebsd-release.sh
timeout-minutes: 120
x86_64-linux-debug:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-debug.sh
timeout-minutes: 180
x86_64-linux-debug-llvm:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-debug-llvm.sh
timeout-minutes: 360
x86_64-linux-release:
runs-on: [self-hosted, x86_64-linux]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-linux-release.sh
timeout-minutes: 360
x86_64-netbsd-debug:
runs-on: [self-hosted, x86_64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-netbsd-debug.sh
timeout-minutes: 120
x86_64-netbsd-release:
runs-on: [self-hosted, x86_64-netbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-netbsd-release.sh
timeout-minutes: 120
x86_64-openbsd-debug:
runs-on: [self-hosted, x86_64-openbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-openbsd-debug.sh
timeout-minutes: 120
x86_64-openbsd-release:
runs-on: [self-hosted, x86_64-openbsd]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: sh ci/x86_64-openbsd-release.sh
timeout-minutes: 120
x86_64-windows-debug:
runs-on: [self-hosted, x86_64-windows]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: ci/x86_64-windows-debug.ps1
timeout-minutes: 180
x86_64-windows-release:
runs-on: [self-hosted, x86_64-windows]
steps:
- name: Checkout
uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28
with:
fetch-depth: 0
- name: Build and Test
run: ci/x86_64-windows-release.ps1
timeout-minutes: 180

2
.gitattributes vendored
View file

@ -15,8 +15,6 @@ src/Package/Fetch/testdata/** binary
src/Package/Fetch/git/testdata/** binary
lib/compiler/aro/** linguist-vendored
lib/compiler/resinator/** linguist-vendored
lib/compiler/translate-c/** linguist-vendored
lib/include/** linguist-vendored
lib/libc/** linguist-vendored
lib/libcxx/** linguist-vendored

75
.github/CODE_OF_CONDUCT.md vendored Normal file
View file

@ -0,0 +1,75 @@
# Code of Conduct
Hello, and welcome! 👋
The Zig community is decentralized. Anyone is free to start and maintain their
own space for people to gather, and edit
[the Community wiki page](https://github.com/ziglang/zig/wiki/Community) to add
a link. There is no concept of "official" or "unofficial", however, each
gathering place has its own moderators and rules.
This is Andrew Kelley speaking. At least for now, I'm the moderator of the
ziglang organization GitHub repositories and the #zig IRC channel on Libera.chat.
**This document contains the rules that govern these two spaces only**.
The rules here are strict. This space is for focused, on topic, technical work
on the Zig project only. It is everyone's responsibility to maintain a positive
environment, especially when disagreements occur.
## Our Standards
Examples of behavior that contribute to creating a positive environment include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Helping another person accomplish their own goals.
* Showing empathy towards others.
* Showing appreciation for others' work.
* Validating someone else's experience, skills, insight, and use cases.
Examples of unacceptable behavior by participants include:
* Unwelcome sexual attention or advances, or use of sexualized language or
imagery that causes discomfort.
* Trolling, insulting/derogatory comments, and personal attacks. Anything
antagonistic towards someone else.
* Off-topic discussion of any kind - especially offensive or sensitive issues.
* Publishing others' private information, such as a physical or electronic
address, without explicit permission.
* Discussing this Code of Conduct or publicly accusing someone of violating it.
* Making someone else feel like an outsider or implying a lack of technical
abilities.
* Destructive behavior. Anything that harms Zig or another open-source project.
## Enforcement
If you need to report an issue you can contact me or Loris Cro, who are both
paid by the Zig Software Foundation, and so moderation of this space is part of
our job. We will swiftly remove anyone who is antagonizing others or being
generally destructive.
This includes Private Harassment. If person A is directly harassed or
antagonized by person B, person B will be blocked from participating in this
space even if the harassment didn't take place on one of the mediums directly
under rule of this Code of Conduct.
As noted, discussing this Code of Conduct should not take place on GitHub or IRC
because these spaces are for directly working on code, not for meta-discussion.
If you have any issues with it, you can contact me directly, or you can join one
of the community spaces that has different rules.
* Andrew Kelley <andrew@ziglang.org>
* Loris Cro <loris@ziglang.org>
## Conclusion
Thanks for reading the rules. Together, we can make this space welcoming and
inclusive for everyone, regardless of age, body size, disability, ethnicity,
sex characteristics, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.
Sincerely,
Andrew ✌️

3
.github/CONTRIBUTING.md vendored Normal file
View file

@ -0,0 +1,3 @@
Please see the
[Contributing](https://github.com/ziglang/zig/wiki/Contributing)
page on the wiki.

1
.github/FUNDING.yml vendored Normal file
View file

@ -0,0 +1 @@
github: [ziglang]

10
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View file

@ -0,0 +1,10 @@
contact_links:
- name: Language Proposal
about: Propose to improve the Zig language
url: https://github.com/ziglang/zig/wiki/Language-Proposals
- name: Question
about: Please use one of the community spaces for questions or general discussions.
url: https://github.com/ziglang/zig/wiki/Community
- name: Copilot and Other LLMs
about: Please do not use GitHub Copilot or any other LLM to write an issue.
url: https://github.com/ziglang/zig/wiki/Writing-Issues-with-Copilot-and-Other-LLMs

View file

@ -0,0 +1,35 @@
name: ci-pr-riscv64-linux
on:
pull_request:
types:
- labeled
- opened
- reopened
- synchronize
- unlabeled
concurrency:
# Cancels pending runs when a PR gets updated.
group: riscv64-linux-${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: true
permissions:
# Sets permission policy for `GITHUB_TOKEN`
contents: read
jobs:
riscv64-linux-debug:
if: contains(github.event.pull_request.labels.*.name, 'ci-riscv64-linux')
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
riscv64-linux-release:
if: contains(github.event.pull_request.labels.*.name, 'ci-riscv64-linux')
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-release.sh

118
.github/workflows/ci.yaml vendored Normal file
View file

@ -0,0 +1,118 @@
name: ci
on:
pull_request:
push:
branches:
- master
- 0.15.x
concurrency:
# Cancels pending runs when a PR gets updated.
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
cancel-in-progress: true
permissions:
# Sets permission policy for `GITHUB_TOKEN`
contents: read
jobs:
x86_64-linux-debug:
timeout-minutes: 540
runs-on: [self-hosted, Linux, x86_64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/x86_64-linux-debug.sh
x86_64-linux-debug-llvm:
timeout-minutes: 540
runs-on: [self-hosted, Linux, x86_64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/x86_64-linux-debug-llvm.sh
x86_64-linux-release:
timeout-minutes: 540
runs-on: [self-hosted, Linux, x86_64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/x86_64-linux-release.sh
aarch64-linux-debug:
runs-on: [self-hosted, Linux, aarch64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/aarch64-linux-debug.sh
aarch64-linux-release:
runs-on: [self-hosted, Linux, aarch64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/aarch64-linux-release.sh
riscv64-linux-debug:
if: github.event_name == 'push'
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-debug.sh
riscv64-linux-release:
if: github.event_name == 'push'
timeout-minutes: 420
runs-on: [self-hosted, Linux, riscv64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: sh ci/riscv64-linux-release.sh
x86_64-macos-release:
runs-on: "macos-13"
env:
ARCH: "x86_64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/x86_64-macos-release.sh
aarch64-macos-debug:
runs-on: [self-hosted, macOS, aarch64]
env:
ARCH: "aarch64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/aarch64-macos-debug.sh
aarch64-macos-release:
runs-on: [self-hosted, macOS, aarch64]
env:
ARCH: "aarch64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/aarch64-macos-release.sh
x86_64-windows-debug:
timeout-minutes: 420
runs-on: [self-hosted, Windows, x86_64]
env:
ARCH: "x86_64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/x86_64-windows-debug.ps1
x86_64-windows-release:
timeout-minutes: 420
runs-on: [self-hosted, Windows, x86_64]
env:
ARCH: "x86_64"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Test
run: ci/x86_64-windows-release.ps1

4
.gitignore vendored
View file

@ -16,3 +16,7 @@ zig-out/
/build/
/build-*/
/docgen_tmp/
# Although this was renamed to .zig-cache, let's leave it here for a few
# releases to make it less annoying to work with multiple branches.
zig-cache/

View file

@ -2,16 +2,10 @@ Adam Goertz <adambgoertz@gmail.com>
Ali Chraghi <alichraghi@proton.me> <alichraghi@pm.me>
Andrea Orru <andrea@orru.io> <andreaorru1991@gmail.com>
Andrew Kelley <andrew@ziglang.org> <superjoe30@gmail.com>
Andrew Kelley <andrew@ziglang.org> <andrewrk@noreply.codeberg.org>
Bogdan Romanyuk <wrongnull@gmail.com> <65823030+wrongnull@users.noreply.github.com>
Casey Banner <kcbanner@gmail.com>
Dacheng Gao <successgdc@gmail.com>
Daniel Kongsgaard <dakongsgaard@gmail.com>
David Carlier <devnexen@gmail.com>
David Rubin <david@vortan.dev>
David Rubin <david@vortan.dev> <daviru007@icloud.com>
David Rubin <david@vortan.dev> <87927264+Rexicon226@users.noreply.github.com>
David Senoner <seda18@rolmail.net>
David Rubin <daviru007@icloud.com> <87927264+Rexicon226@users.noreply.github.com>
Dominic <4678790+dweiller@users.noreply.github.com>
Dominic <4678790+dweiller@users.noreply.github.com> <4678790+dweiller@users.noreplay.github.com>
Eric Eastwood <madlittlemods@gmail.com> <contact@ericeastwood.com>
@ -23,7 +17,6 @@ Felix "xq" Queißner <xq@random-projects.net> <git@masterq32.de>
Felix "xq" Queißner <xq@random-projects.net> <git@mq32.de>
Felix "xq" Queißner <xq@random-projects.net> <git@random-projects.net>
Frank Denis <124872+jedisct1@users.noreply.github.com> <github@pureftpd.org>
Frank Denis <124872+jedisct1@users.noreply.github.com> <jedisct1@noreply.codeberg.org>
Garrett Beck <garrettlennoxbeck@gmail.com> <138411610+garrettlennoxbeck@users.noreply.github.com>
Gaëtan S <blaxoujunior@gmail.com>
GalaxyShard <dominic.adragna@byteroach.com>
@ -33,7 +26,6 @@ Igor Anić <igor.anic@gmail.com>
IntegratedQuantum <jahe788@gmail.com> <43880493+IntegratedQuantum@users.noreply.github.com>
Isaac Freund <mail@isaacfreund.com> <ifreund@ifreund.xyz>
Isaac Freund <mail@isaacfreund.com> <isaac.freund@coil.com>
Ivan Stepanov <ivanstepanovftw@gmail.com>
Jacob Young <amazingjacob@gmail.com>
Jacob Young <amazingjacob@gmail.com> <jacobly0@users.noreply.github.com>
Jacob Young <amazingjacob@gmail.com> <15544577+jacobly0@users.noreply.github.com>
@ -46,7 +38,6 @@ Jimmi Holst Christensen <jhc@dismail.de> <jimmiholstchristensen@gmail.com>
Jimmi Holst Christensen <jhc@dismail.de> <rainbowhejsil@gmail.com>
Joachim Schmidt <joachim.schmidt557@outlook.com>
Jonathan Marler <johnnymarler@gmail.com> <jonathan.j.marler@hp.com>
Kendall Condon <goon.pri.low@gmail.com> <149842806+gooncreeper@users.noreply.github.com>
Krzysztof Wolicki <der.teufel.mail@gmail.com>
Krzysztof Wolicki <der.teufel.mail@gmail.com> <46651553+der-teufel-programming@users.noreply.github.com>
LemonBoy <thatlemon@gmail.com> <LemonBoy@users.noreply.github.com>
@ -57,7 +48,6 @@ Marc Tiehuis <marc@tiehu.is> <marctiehuis@gmail.com>
Mason Remaley <mason@anthropicstudios.com>
Mason Remaley <mason@anthropicstudios.com> <MasonRemaley@users.noreply.github.com>
Matthew Lugg <mlugg@mlugg.co.uk>
Matthew Lugg <mlugg@mlugg.co.uk> <mlugg@noreply.codeberg.org>
Meghan Denny <hello@nektro.net>
Meghan Denny <hello@nektro.net> <meghan@bun.sh>
Michael Bartnett <michael.bartnett@gmail.com> <michaelbartnett@users.noreply.github.com>
@ -79,7 +69,6 @@ Travis Staloch <twostepted@gmail.com>
Travis Staloch <twostepted@gmail.com> <1562827+travisstaloch@users.noreply.github.com>
Veikka Tuominen <git@vexu.eu>
Veikka Tuominen <git@vexu.eu> <15308111+Vexu@users.noreply.github.com>
Veikka Tuominen <git@vexu.eu> <veikka@ziglang.org>
Will Lillis <will.lillis24@gmail.com>
Will Lillis <will.lillis24@gmail.com> <wlillis@umass.edu>
Wooster <r00ster91@proton.me>

View file

@ -38,8 +38,8 @@ project(zig
)
set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 16)
set(ZIG_VERSION_PATCH 0)
set(ZIG_VERSION_MINOR 15)
set(ZIG_VERSION_PATCH 1)
set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.")
if("${ZIG_VERSION}" STREQUAL "")
@ -133,9 +133,9 @@ else()
set(ZIG_SYSTEM_LIBCXX "stdc++" CACHE STRING "system libcxx name for build.zig")
endif()
find_package(llvm 21)
find_package(clang 21)
find_package(lld 21)
find_package(llvm 20)
find_package(clang 20)
find_package(lld 20)
if(ZIG_STATIC_ZLIB)
if (MSVC)
@ -197,6 +197,7 @@ set(ZIG_CPP_SOURCES
# These are planned to stay even when we are self-hosted.
src/zig_llvm.cpp
src/zig_llvm-ar.cpp
src/zig_clang.cpp
src/zig_clang_driver.cpp
src/zig_clang_cc1_main.cpp
src/zig_clang_cc1as_main.cpp
@ -205,6 +206,183 @@ set(ZIG_CPP_SOURCES
set(ZIG_STAGE2_SOURCES
"${ZIG_CONFIG_ZIG_OUT}"
lib/compiler_rt.zig
lib/compiler_rt/absv.zig
lib/compiler_rt/absvdi2.zig
lib/compiler_rt/absvsi2.zig
lib/compiler_rt/absvti2.zig
lib/compiler_rt/adddf3.zig
lib/compiler_rt/addf3.zig
lib/compiler_rt/addo.zig
lib/compiler_rt/addsf3.zig
lib/compiler_rt/addtf3.zig
lib/compiler_rt/addvsi3.zig
lib/compiler_rt/addxf3.zig
lib/compiler_rt/arm.zig
lib/compiler_rt/atomics.zig
lib/compiler_rt/aulldiv.zig
lib/compiler_rt/aullrem.zig
lib/compiler_rt/bswap.zig
lib/compiler_rt/ceil.zig
lib/compiler_rt/clear_cache.zig
lib/compiler_rt/cmp.zig
lib/compiler_rt/cmpdf2.zig
lib/compiler_rt/cmpsf2.zig
lib/compiler_rt/cmptf2.zig
lib/compiler_rt/cmpxf2.zig
lib/compiler_rt/common.zig
lib/compiler_rt/comparef.zig
lib/compiler_rt/cos.zig
lib/compiler_rt/count0bits.zig
lib/compiler_rt/divdf3.zig
lib/compiler_rt/divsf3.zig
lib/compiler_rt/divtf3.zig
lib/compiler_rt/divti3.zig
lib/compiler_rt/divxf3.zig
lib/compiler_rt/emutls.zig
lib/compiler_rt/exp.zig
lib/compiler_rt/exp2.zig
lib/compiler_rt/extenddftf2.zig
lib/compiler_rt/extenddfxf2.zig
lib/compiler_rt/extendf.zig
lib/compiler_rt/extendhfsf2.zig
lib/compiler_rt/extendhftf2.zig
lib/compiler_rt/extendhfxf2.zig
lib/compiler_rt/extendsfdf2.zig
lib/compiler_rt/extendsftf2.zig
lib/compiler_rt/extendsfxf2.zig
lib/compiler_rt/extendxftf2.zig
lib/compiler_rt/fabs.zig
lib/compiler_rt/fixdfdi.zig
lib/compiler_rt/fixdfsi.zig
lib/compiler_rt/fixdfti.zig
lib/compiler_rt/fixhfdi.zig
lib/compiler_rt/fixhfsi.zig
lib/compiler_rt/fixhfti.zig
lib/compiler_rt/fixsfdi.zig
lib/compiler_rt/fixsfsi.zig
lib/compiler_rt/fixsfti.zig
lib/compiler_rt/fixtfdi.zig
lib/compiler_rt/fixtfsi.zig
lib/compiler_rt/fixtfti.zig
lib/compiler_rt/fixunsdfdi.zig
lib/compiler_rt/fixunsdfsi.zig
lib/compiler_rt/fixunsdfti.zig
lib/compiler_rt/fixunshfdi.zig
lib/compiler_rt/fixunshfsi.zig
lib/compiler_rt/fixunshfti.zig
lib/compiler_rt/fixunssfdi.zig
lib/compiler_rt/fixunssfsi.zig
lib/compiler_rt/fixunssfti.zig
lib/compiler_rt/fixunstfdi.zig
lib/compiler_rt/fixunstfsi.zig
lib/compiler_rt/fixunstfti.zig
lib/compiler_rt/fixunsxfdi.zig
lib/compiler_rt/fixunsxfsi.zig
lib/compiler_rt/fixunsxfti.zig
lib/compiler_rt/fixxfdi.zig
lib/compiler_rt/fixxfsi.zig
lib/compiler_rt/fixxfti.zig
lib/compiler_rt/float_from_int.zig
lib/compiler_rt/floatdidf.zig
lib/compiler_rt/floatdihf.zig
lib/compiler_rt/floatdisf.zig
lib/compiler_rt/floatditf.zig
lib/compiler_rt/floatdixf.zig
lib/compiler_rt/floatsidf.zig
lib/compiler_rt/floatsihf.zig
lib/compiler_rt/floatsisf.zig
lib/compiler_rt/floatsitf.zig
lib/compiler_rt/floatsixf.zig
lib/compiler_rt/floattidf.zig
lib/compiler_rt/floattihf.zig
lib/compiler_rt/floattisf.zig
lib/compiler_rt/floattitf.zig
lib/compiler_rt/floattixf.zig
lib/compiler_rt/floatundidf.zig
lib/compiler_rt/floatundihf.zig
lib/compiler_rt/floatundisf.zig
lib/compiler_rt/floatunditf.zig
lib/compiler_rt/floatundixf.zig
lib/compiler_rt/floatunsidf.zig
lib/compiler_rt/floatunsihf.zig
lib/compiler_rt/floatunsisf.zig
lib/compiler_rt/floatunsitf.zig
lib/compiler_rt/floatunsixf.zig
lib/compiler_rt/floatuntidf.zig
lib/compiler_rt/floatuntihf.zig
lib/compiler_rt/floatuntisf.zig
lib/compiler_rt/floatuntitf.zig
lib/compiler_rt/floatuntixf.zig
lib/compiler_rt/floor.zig
lib/compiler_rt/fma.zig
lib/compiler_rt/fmax.zig
lib/compiler_rt/fmin.zig
lib/compiler_rt/fmod.zig
lib/compiler_rt/gedf2.zig
lib/compiler_rt/gesf2.zig
lib/compiler_rt/getf2.zig
lib/compiler_rt/gexf2.zig
lib/compiler_rt/int.zig
lib/compiler_rt/int_from_float.zig
lib/compiler_rt/log.zig
lib/compiler_rt/log10.zig
lib/compiler_rt/log2.zig
lib/compiler_rt/modti3.zig
lib/compiler_rt/mulXi3.zig
lib/compiler_rt/muldf3.zig
lib/compiler_rt/mulf3.zig
lib/compiler_rt/mulo.zig
lib/compiler_rt/mulsf3.zig
lib/compiler_rt/multf3.zig
lib/compiler_rt/mulvsi3.zig
lib/compiler_rt/mulxf3.zig
lib/compiler_rt/negXi2.zig
lib/compiler_rt/negdf2.zig
lib/compiler_rt/negsf2.zig
lib/compiler_rt/negtf2.zig
lib/compiler_rt/negv.zig
lib/compiler_rt/negxf2.zig
lib/compiler_rt/os_version_check.zig
lib/compiler_rt/parity.zig
lib/compiler_rt/popcount.zig
lib/compiler_rt/rem_pio2.zig
lib/compiler_rt/rem_pio2_large.zig
lib/compiler_rt/rem_pio2f.zig
lib/compiler_rt/round.zig
lib/compiler_rt/shift.zig
lib/compiler_rt/sin.zig
lib/compiler_rt/sincos.zig
lib/compiler_rt/sqrt.zig
lib/compiler_rt/stack_probe.zig
lib/compiler_rt/subdf3.zig
lib/compiler_rt/subo.zig
lib/compiler_rt/subsf3.zig
lib/compiler_rt/subtf3.zig
lib/compiler_rt/subvdi3.zig
lib/compiler_rt/subvsi3.zig
lib/compiler_rt/subxf3.zig
lib/compiler_rt/tan.zig
lib/compiler_rt/trig.zig
lib/compiler_rt/trunc.zig
lib/compiler_rt/truncdfhf2.zig
lib/compiler_rt/truncdfsf2.zig
lib/compiler_rt/truncf.zig
lib/compiler_rt/truncsfhf2.zig
lib/compiler_rt/trunctfdf2.zig
lib/compiler_rt/trunctfhf2.zig
lib/compiler_rt/trunctfsf2.zig
lib/compiler_rt/trunctfxf2.zig
lib/compiler_rt/truncxfdf2.zig
lib/compiler_rt/truncxfhf2.zig
lib/compiler_rt/truncxfsf2.zig
lib/compiler_rt/udivmod.zig
lib/compiler_rt/udivmodei4.zig
lib/compiler_rt/udivmodti4.zig
lib/compiler_rt/udivti3.zig
lib/compiler_rt/umodti3.zig
lib/compiler_rt/unorddf2.zig
lib/compiler_rt/unordsf2.zig
lib/compiler_rt/unordtf2.zig
lib/std/BitStack.zig
lib/std/Build.zig
lib/std/Build/Cache.zig
@ -233,6 +411,11 @@ set(ZIG_STAGE2_SOURCES
lib/std/Target/wasm.zig
lib/std/Target/x86.zig
lib/std/Thread.zig
lib/std/Thread/Futex.zig
lib/std/Thread/Mutex.zig
lib/std/Thread/Pool.zig
lib/std/Thread/ResetEvent.zig
lib/std/Thread/WaitGroup.zig
lib/std/array_hash_map.zig
lib/std/array_list.zig
lib/std/ascii.zig
@ -257,13 +440,17 @@ set(ZIG_STAGE2_SOURCES
lib/std/fmt.zig
lib/std/fmt/parse_float.zig
lib/std/fs.zig
lib/std/fs/AtomicFile.zig
lib/std/fs/Dir.zig
lib/std/fs/File.zig
lib/std/fs/get_app_data_dir.zig
lib/std/fs/path.zig
lib/std/hash.zig
lib/std/hash/auto_hash.zig
lib/std/hash/wyhash.zig
lib/std/hash_map.zig
lib/std/heap.zig
lib/std/heap/ArenaAllocator.zig
lib/std/heap/arena_allocator.zig
lib/std/json.zig
lib/std/leb128.zig
lib/std/log.zig
@ -315,6 +502,7 @@ set(ZIG_STAGE2_SOURCES
lib/std/zig/Server.zig
lib/std/zig/WindowsSdk.zig
lib/std/zig/Zir.zig
lib/std/zig/c_builtins.zig
lib/std/zig/string_literal.zig
lib/std/zig/system.zig
lib/std/zig/system/NativePaths.zig
@ -334,6 +522,7 @@ set(ZIG_STAGE2_SOURCES
src/Builtin.zig
src/Compilation.zig
src/Compilation/Config.zig
src/DarwinPosixSpawn.zig
src/InternPool.zig
src/Package.zig
src/Package/Fetch.zig
@ -348,6 +537,7 @@ set(ZIG_STAGE2_SOURCES
src/Value.zig
src/Zcu.zig
src/Zcu/PerThread.zig
src/clang.zig
src/clang_options.zig
src/clang_options_data.zig
src/codegen.zig
@ -368,7 +558,6 @@ set(ZIG_STAGE2_SOURCES
src/libs/freebsd.zig
src/libs/glibc.zig
src/libs/netbsd.zig
src/libs/openbsd.zig
src/introspect.zig
src/libs/libcxx.zig
src/libs/libtsan.zig
@ -394,7 +583,7 @@ set(ZIG_STAGE2_SOURCES
src/link/Elf/relocatable.zig
src/link/Elf/relocation.zig
src/link/Elf/synthetic_sections.zig
src/link/Elf2.zig
src/link/Goff.zig
src/link/LdScript.zig
src/link/Lld.zig
src/link/MachO.zig
@ -423,13 +612,13 @@ set(ZIG_STAGE2_SOURCES
src/link/MachO/synthetic.zig
src/link/MachO/Thunk.zig
src/link/MachO/uuid.zig
src/link/MappedFile.zig
src/link/Queue.zig
src/link/StringTable.zig
src/link/Wasm.zig
src/link/Wasm/Archive.zig
src/link/Wasm/Flush.zig
src/link/Wasm/Object.zig
src/link/Xcoff.zig
src/link/aarch64.zig
src/link/riscv.zig
src/link/table_section.zig
@ -450,6 +639,7 @@ set(ZIG_STAGE2_SOURCES
src/register_manager.zig
src/target.zig
src/tracy.zig
src/translate_c.zig
src/libs/wasi_libc.zig
)
@ -547,22 +737,20 @@ endforeach()
include(CheckSymbolExists)
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS)
if(ZIG_HOST_TARGET_OS STREQUAL "android")
set(ZIG_HOST_TARGET_OS "linux")
set(ZIG_HOST_TARGET_IS_ANDROID TRUE)
elseif(ZIG_HOST_TARGET_OS STREQUAL "darwin")
if(ZIG_HOST_TARGET_OS STREQUAL "darwin")
set(ZIG_HOST_TARGET_OS "macos")
elseif(ZIG_HOST_TARGET_OS STREQUAL "gnu")
set(ZIG_HOST_TARGET_OS "hurd")
elseif(ZIG_HOST_TARGET_OS STREQUAL "serenityos")
set(ZIG_HOST_TARGET_OS "serenity")
elseif(ZIG_HOST_TARGET_OS STREQUAL "sunos")
set(ZIG_HOST_TARGET_OS "illumos")
check_symbol_exists(__illumos__ "" ZIG_HOST_TARGET_HAS_ILLUMOS_MACRO)
if (ZIG_HOST_TARGET_HAS_ILLUMOS_MACRO)
set(ZIG_HOST_TARGET_OS "illumos")
else()
set(ZIG_HOST_TARGET_OS "solaris")
endif()
endif()
string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" ZIG_HOST_TARGET_ARCH)
if(ZIG_HOST_TARGET_ARCH MATCHES "^i[3-9]86$")
if (ZIG_HOST_TARGET_OS STREQUAL "illumos")
if (ZIG_HOST_TARGET_OS MATCHES "(solaris|illumos)")
set(ZIG_HOST_TARGET_ARCH "x86_64")
else()
set(ZIG_HOST_TARGET_ARCH "x86")
@ -584,17 +772,15 @@ if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(eb)?$")
endif()
string(REGEX REPLACE "^ppc((64)?(le)?)$" "powerpc\\1" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
set(ZIG_HOST_TARGET_ABI "")
if(MSVC)
set(ZIG_HOST_TARGET_ABI "-msvc")
elseif(MINGW)
set(ZIG_HOST_TARGET_ABI "-gnu")
elseif(ZIG_HOST_TARGET_IS_ANDROID)
if(ZIG_HOST_TARGET_ARCH STREQUAL "arm")
set(ZIG_HOST_TARGET_ABI "-androideabi")
else()
set(ZIG_HOST_TARGET_ABI "-android")
endif()
elseif(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)hf?(eb)?$")
string(REGEX REPLACE "^(arm|thumb)hf?((eb)?)$" "\\1\\2" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
set(ZIG_HOST_TARGET_ABI "-eabihf")
else()
set(ZIG_HOST_TARGET_ABI "")
endif()
set(ZIG_HOST_TARGET_TRIPLE "${ZIG_HOST_TARGET_ARCH}-${ZIG_HOST_TARGET_OS}${ZIG_HOST_TARGET_ABI}" CACHE STRING "Host zig target triple.")
@ -608,11 +794,6 @@ else()
set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2")
set(ZIG1_COMPILE_FLAGS "-std=c99 -Os")
set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector")
# Must match the condition in build.zig.
if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$")
set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -ffunction-sections -fdata-sections")
endif()
if(APPLE)
set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000")
elseif(MINGW)

735
README.md
View file

@ -20,8 +20,8 @@ running `zig std`, which will open a browser tab.
## Installation
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://ziglang.org/learn/getting-started/#managers)
* [bootstrap zig for any target](https://codeberg.org/ziglang/zig-bootstrap)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
A Zig installation is composed of two things:
@ -47,10 +47,7 @@ Ensure you have the required dependencies:
* CMake >= 3.15
* System C/C++ Toolchain
* LLVM, Clang, LLD development libraries, version 21.x, compiled with the
same system C/C++ toolchain.
- If the system package manager lacks these libraries, or has them misconfigured,
see below for how to build them from source.
* LLVM, Clang, LLD development libraries == 20.x
Then it is the standard CMake build process:
@ -61,9 +58,9 @@ cmake ..
make install
```
Use `CMAKE_PREFIX_PATH` if needed to help CMake find LLVM.
This produces `stage3/bin/zig` which is the Zig compiler built by itself.
For more options, tips, and troubleshooting, please see the
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
page on the wiki.
## Building from Source without LLVM
@ -79,377 +76,35 @@ This produces a `zig2` executable in the current working directory. This is a
[without LLVM extensions](https://github.com/ziglang/zig/issues/16270), and is
therefore lacking these features:
- Release mode optimizations
- [Some ELF linking features](https://github.com/ziglang/zig/issues/17749)
- [Some COFF/PE linking features](https://github.com/ziglang/zig/issues/17751)
- [Some WebAssembly linking features](https://github.com/ziglang/zig/issues/17750)
- [Ability to create static archives from object files](https://github.com/ziglang/zig/issues/9828)
- [aarch64 machine code backend](https://github.com/ziglang/zig/issues/21172)
- [@cImport](https://github.com/ziglang/zig/issues/20630)
- [zig translate-c](https://github.com/ziglang/zig/issues/20875)
- [Ability to compile assembly files](https://github.com/ziglang/zig/issues/21169)
- [Some ELF linking features](https://github.com/ziglang/zig/issues/17749)
- [Most COFF/PE linking features](https://github.com/ziglang/zig/issues/17751)
- [Some WebAssembly linking features](https://github.com/ziglang/zig/issues/17750)
- [Ability to create import libs from def files](https://github.com/ziglang/zig/issues/17807)
- [Ability to create static archives from object files](https://github.com/ziglang/zig/issues/9828)
- Ability to compile C, C++, Objective-C, and Objective-C++ files
Even when built this way, Zig provides an LLVM backend that produces bitcode
files, which may be optimized and compiled into object files via a system Clang
However, a compiler built this way does provide a C backend, which may be
useful for creating system packages of Zig projects using the system C
toolchain. **In this case, LLVM is not needed!**
Furthermore, a compiler built this way provides an LLVM backend that produces
bitcode files, which may be compiled into object files via a system Clang
package. This can be used to produce system packages of Zig applications
without the Zig package dependency on LLVM.
## Building from Source Using Prebuilt Zig
Dependencies:
* A recent prior build of Zig. The exact version required depends on how
recently breaking changes occurred. If the language or std lib changed too
much since this version, then this method of building from source will fail.
* LLVM, Clang, and LLD libraries built using Zig.
The easiest way to obtain both of these artifacts is to use
[zig-bootstrap](https://codeberg.org/ziglang/zig-bootstrap), which creates the
directory `out/zig-$target-$cpu` and `out/$target-$cpu`, to be used as
`$ZIG_PREFIX` and `$LLVM_PREFIX`, respectively, in the following command:
```
"$ZIG_PREFIX/zig" build \
-p stage3 \
--search-prefix "$LLVM_PREFIX" \
--zig-lib-dir "lib" \
-Dstatic-llvm
```
Where `$LLVM_PREFIX` is the path that contains, for example,
`include/llvm/Pass.h` and `lib/libLLVMCore.a`.
This produces `stage3/bin/zig`. See `zig build -h` to learn about the options
that can be passed such as `-Drelease`.
## Building from Source on Windows
### Option 1: Use the Windows Zig Compiler Dev Kit
This one has the benefit that LLVM, LLD, and Clang are built in Release mode,
while your Zig build has the option to be a Debug build. It also works
completely independently from MSVC so you don't need it to be installed.
Determine the URL by
[looking at the CI script](https://codeberg.org/ziglang/zig/src/branch/master/ci/x86_64-windows-debug.ps1#L1-L4).
It will look something like this (replace `$VERSION` with the one you see by
following the above link):
```
https://ziglang.org/deps/zig+llvm+lld+clang-x86_64-windows-gnu-$VERSION.zip
```
This zip file contains:
* An older Zig installation.
* LLVM, LLD, and Clang libraries (.lib and .h files), version 16.0.1, built in Release mode.
* zlib (.lib and .h files), v1.2.13, built in Release mode
* zstd (.lib and .h files), v1.5.2, built in Release mode
#### Option 1a: CMake + [Ninja](https://ninja-build.org/)
Unzip the dev kit and then in cmd.exe in your Zig source checkout:
```bat
mkdir build
cd build
set DEVKIT=$DEVKIT
```
Replace `$DEVKIT` with the path to the folder that you unzipped after
downloading it from the link above. Make sure to use forward slashes (`/`) for
all path separators (otherwise CMake will try to interpret backslashes as
escapes and fail).
Then run:
```bat
cmake .. -GNinja -DCMAKE_PREFIX_PATH="%DEVKIT%" -DCMAKE_C_COMPILER="%DEVKIT%/bin/zig.exe;cc" -DCMAKE_CXX_COMPILER="%DEVKIT%/bin/zig.exe;c++" -DCMAKE_AR="%DEVKIT%/bin/zig.exe" -DZIG_AR_WORKAROUND=ON -DZIG_STATIC=ON -DZIG_USE_LLVM_CONFIG=OFF
```
* Append `-DCMAKE_BUILD_TYPE=Release` for a Release build.
* Append `-DZIG_NO_LIB=ON` to avoid having multiple copies of the lib/ folder.
Finally, run:
```bat
ninja install
```
You now have the `zig.exe` binary at `stage3\bin\zig.exe`.
#### Option 1b: zig build
Unzip the dev kit and then in cmd.exe in your Zig source checkout:
```bat
$DEVKIT\bin\zig.exe build -p stage3 --search-prefix $DEVKIT --zig-lib-dir lib -Dstatic-llvm -Duse-zig-libcxx -Dtarget=x86_64-windows-gnu
```
Replace `$DEVKIT` with the path to the folder that you unzipped after
downloading it from the link above.
Append `-Doptimize=ReleaseSafe` for a Release build.
**If you get an error building at this step**, it is most likely that the Zig
installation inside the dev kit is too old, and the dev kit needs to be
updated. In this case one more step is required:
1. [Download the latest master branch zip file](https://ziglang.org/download/#release-master).
2. Unzip, and try the above command again, replacing the path to zig.exe with
the path to the zig.exe you just extracted, and also replace the lib\zig
folder with the new contents.
You now have the `zig.exe` binary at `stage3\bin\zig.exe`.
### Option 2: Using CMake and Microsoft Visual Studio
This one has the benefit that changes to the language or build system won't
break your dev kit. This option can be used to upgrade a dev kit.
First, build LLVM, LLD, and Clang from source using CMake and Microsoft Visual
Studio (see below for detailed instructions).
Install [Build Tools for Visual Studio
2019](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
Be sure to select "Desktop development with C++" when prompted.
* You must additionally check the optional component labeled **C++ ATL for
v142 build tools**.
Install [CMake](http://cmake.org).
Use [git](https://git-scm.com/) to clone the zig repository to a path with no spaces, e.g. `C:\Users\Andy\zig`.
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value.
```bat
mkdir C:\Users\Andy\zig\build-release
cd C:\Users\Andy\zig\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-20.0.0-x86_64-windows-msvc-release-mt -DCMAKE_BUILD_TYPE=Release
msbuild -p:Configuration=Release INSTALL.vcxproj
```
You now have the `zig.exe` binary at `bin\zig.exe` and you can run the tests:
```bat
bin\zig.exe build test
```
This can take a long time.
Note: In case you get the error "llvm-config not found" (or similar), make sure
that you have **no** trailing slash (`/` or `\`) at the end of the
`-DCMAKE_PREFIX_PATH` value.
## Building LLVM, LLD, and Clang from Source
### Windows
Install [CMake](https://cmake.org/), version 3.20.0 or newer.
[Download LLVM, Clang, and LLD sources](https://releases.llvm.org/download.html#21.0.0)
The downloads from llvm lead to the github release pages, where the source's
will be listed as : `llvm-21.X.X.src.tar.xz`, `clang-21.X.X.src.tar.xz`,
`lld-21.X.X.src.tar.xz`. Unzip each to their own directory. Ensure no
directories have spaces in them. For example:
* `C:\Users\Andy\llvm-21.0.0.src`
* `C:\Users\Andy\clang-21.0.0.src`
* `C:\Users\Andy\lld-21.0.0.src`
Install [Build Tools for Visual Studio
2019](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019).
Be sure to select "C++ build tools" when prompted.
* You **must** additionally check the optional component labeled **C++ ATL for
v142 build tools**. As this won't be supplied by a default installation of
Visual Studio.
* Full list of supported MSVC versions:
- 2017 (version 15.8) (unverified)
- 2019 (version 16.7)
Install [Python 3.9.4](https://www.python.org). Tick the box to add python to
your PATH environment variable.
#### LLVM
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value. Here is listed a brief explanation of each of the CMake parameters we pass when configuring the build
- `-Thost=x64` : Sets the windows toolset to use 64 bit mode.
- `-A x64` : Make the build target 64 bit .
- `-G "Visual Studio 16 2019"` : Specifies to generate a 2019 Visual Studio project, the best supported version.
- `-DCMAKE_INSTALL_PREFIX=""` : Path that llvm components will being installed into by the install project.
- `-DCMAKE_PREFIX_PATH=""` : Path that CMake will look into first when trying to locate dependencies, should be the same place as the install prefix. This will ensure that clang and lld will use your newly built llvm libraries.
- `-DLLVM_ENABLE_ZLIB=OFF` : Don't build llvm with ZLib support as it's not required and will disrupt the target dependencies for components linking against llvm. This only has to be passed when building llvm, as this option will be saved into the config headers.
- `-DCMAKE_BUILD_TYPE=Release` : Build llvm and components in release mode.
- `-DCMAKE_BUILD_TYPE=Debug` : Build llvm and components in debug mode.
- `-DLLVM_USE_CRT_RELEASE=MT` : Which C runtime should llvm use during release builds.
- `-DLLVM_USE_CRT_DEBUG=MTd` : Make llvm use the debug version of the runtime in debug builds.
##### Release Mode
```bat
mkdir C:\Users\Andy\llvm-21.0.0.src\build-release
cd C:\Users\Andy\llvm-21.0.0.src\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -
DLLVM_ENABLE_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_USE_CRT_RELEASE=MT
msbuild /m -p:Configuration=Release INSTALL.vcxproj
```
##### Debug Mode
```bat
mkdir C:\Users\Andy\llvm-21.0.0.src\build-debug
cd C:\Users\Andy\llvm-21.0.0.src\build-debug
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -
DLLVM_ENABLE_ZLIB=OFF -DCMAKE_PREFIX_PATH=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_BUILD_TYPE=Debug -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="AVR" -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_USE_CRT_DEBUG=MTd
msbuild /m INSTALL.vcxproj
```
#### LLD
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value.
##### Release Mode
```bat
mkdir C:\Users\Andy\lld-21.0.0.src\build-release
cd C:\Users\Andy\lld-21.0.0.src\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\Andy\llvm+clang+lld-14.0.6-x86_64-windows-msvc-release-mt -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT
msbuild /m -p:Configuration=Release INSTALL.vcxproj
```
##### Debug Mode
```bat
mkdir C:\Users\Andy\lld-21.0.0.src\build-debug
cd C:\Users\Andy\lld-21.0.0.src\build-debug
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_PREFIX_PATH=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_CRT_DEBUG=MTd
msbuild /m INSTALL.vcxproj
```
#### Clang
Using the start menu, run **x64 Native Tools Command Prompt for VS 2019** and execute these commands, replacing `C:\Users\Andy` with the correct value.
##### Release Mode
```bat
mkdir C:\Users\Andy\clang-21.0.0.src\build-release
cd C:\Users\Andy\clang-21.0.0.src\build-release
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_PREFIX_PATH=C:\Users\Andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-release-mt -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT
msbuild /m -p:Configuration=Release INSTALL.vcxproj
```
##### Debug Mode
```bat
mkdir C:\Users\Andy\clang-21.0.0.src\build-debug
cd C:\Users\Andy\clang-21.0.0.src\build-debug
"c:\Program Files\CMake\bin\cmake.exe" .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_PREFIX_PATH=C:\Users\andy\llvm+clang+lld-21.0.0-x86_64-windows-msvc-debug -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_CRT_DEBUG=MTd
msbuild /m INSTALL.vcxproj
```
### POSIX Systems
This guide will get you both a Debug build of LLVM, and/or a Release build of LLVM.
It intentionally does not require privileged access, using a prefix inside your home
directory instead of a global installation.
#### Release
This is the generally recommended approach.
```
cd ~/Downloads
git clone --depth 1 --branch release/21.x https://github.com/llvm/llvm-project llvm-project-21
cd llvm-project-21
git checkout release/21.x
mkdir build-release
cd build-release
cmake ../llvm \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-assert \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-G Ninja
ninja install
```
#### Debug
This is occasionally needed when debugging Zig's LLVM backend. Here we build
the three projects separately so that LLVM can be in Debug mode while the
others are in Release mode.
```
cd ~/Downloads
git clone --depth 1 --branch release/21.x https://github.com/llvm/llvm-project llvm-project-21
cd llvm-project-21
git checkout release/21.x
# LLVM
mkdir llvm/build-debug
cd llvm/build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-debug \
-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug \
-DCMAKE_BUILD_TYPE=Debug \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-G Ninja
ninja install
cd ../..
# LLD
mkdir lld/build-debug
cd lld/build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-debug \
-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DCMAKE_CXX_STANDARD=17 \
-G Ninja
ninja install
cd ../..
# Clang
mkdir clang/build-debug
cd clang/build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/local/llvm21-debug \
-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_INCLUDE_TESTS=OFF \
-G Ninja
ninja install
cd ../..
```
Then add to your Zig CMake line that you got from the README.md:
`-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-debug` or
`-DCMAKE_PREFIX_PATH=$HOME/local/llvm21-assert` depending on whether you want
Debug or Release LLVM.
## Contributing
[Donate monthly](https://ziglang.org/zsf/).
[Join a community](https://ziglang.org/community/).
Zig is Free and Open Source Software. We welcome bug reports and patches from
everyone. However, keep in mind that Zig governance is BDFN (Benevolent
Dictator For Now) which means that Andrew Kelley has final say on the design
and implementation of everything.
### Make Software With Zig
One of the best ways you can contribute to Zig is to start using it for an
open-source personal project.
@ -458,343 +113,35 @@ 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.
### Talk About Zig
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.
Programming languages live and die based on the pulse of their ecosystems. The
more people involved, the more we can build great things upon each other's
abstractions.
### 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.
### Find a Contributor Friendly Issue
You will be taken much more seriously on the issue tracker if you have a
personal project that uses Zig.
The issue label
[Contributor Friendly](https://codeberg.org/ziglang/zig/issues?labels=741726&state=open)
exists to help you find issues that are **limited in scope and/or
knowledge of Zig internals.**
[Contributor Friendly](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributor+friendly%22)
exists to help you find issues that are **limited in scope and/or knowledge of
Zig internals.**
Please note that issues labeled
[Proposal: Proposed](https://codeberg.org/ziglang/zig/issues?labels=746937&state=open)
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
[Proposal](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen+label%3Aproposal)
but do not also have the
[Accepted](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen+label%3Aaccepted)
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.
Language proposals are not accepted. Please do not open an issue proposing to
change the Zig language or syntax.
For more tips, please see the
[Contributing](https://github.com/ziglang/zig/wiki/Contributing) page on the
wiki.
### Editing Source Code
## Community
For a smooth workflow, when building from source, it is recommended to use
CMake with the following settings:
* `-DCMAKE_BUILD_TYPE=Release` - to recompile zig faster.
* `-GNinja` - Ninja is faster and simpler to use than Make.
* `-DZIG_NO_LIB=ON` - Prevents the build system from copying the lib/
directory to the installation prefix, causing zig use lib/ directly from the
source tree instead. Effectively, this makes it so that changes to lib/ do
not require re-running the install command to become active.
After configuration, there are two scenarios:
1. Pulling upstream changes and rebuilding.
- In this case use `git pull` and then `ninja install`. Expected wait:
about 10 minutes.
2. Building from source after making local changes.
- In this case use `stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib`.
Expected wait: about 20 seconds.
This leaves you with two builds of Zig:
* `stage3/bin/zig` - an optimized master branch build. Useful for
miscellaneous activities such as `zig fmt`, as well as for building the
compiler itself after changing the source code.
* `stage4/bin/zig` - a debug build that includes your local changes; useful
for testing and eliminating bugs before submitting a patch.
To reduce time spent waiting for the compiler to build, try these techniques:
* Omit `-Denable-llvm` if you don't need the LLVM backend.
* Use `-Ddev=foo` to build with a reduced feature set for development of
specific features. See `zig build -h` for a list of options.
* Use `--watch -fincremental` to enable incremental compilation. This offers
**near instant rebuilds**.
### Testing
```
stage4/bin/zig build test
```
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 with only the native target
configuration and is estimated to complete in 3 minutes:
```
zig build test-std -Dno-matrix
```
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."
```
If you used `-Dno-lib` and you are in a `build/` subdirectory, you can omit the
`--zig-lib-dir` argument:
```
stage3/bin/zig test ../lib/std/std.zig
```
#### 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.
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.
[ziglang/qemu-static](https://codeberg.org/ziglang/qemu-static) offers static
binaries of the latest QEMU version.
##### 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](https://codeberg.org/ziglang/infra/src/branch/master/building-libcs.md#linux-glibc) (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](https://wasmtime.dev/) 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.
### Improving Translate-C
`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](https://ziglang.org/documentation/master/#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 used to work 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.
However, C translation is in a transitional period right now. It used to be
based on Clang, but is now based on Aro:
[Pull Request: update aro and translate-c to latest; delete clang translate-c](https://github.com/ziglang/zig/pull/24497)
Test coverage as well as bug reports have been moved to this repository:
[ziglang/translate-c](https://codeberg.org/ziglang/translate-c/)
In the future, [@cImport will move to the build system](https://github.com/ziglang/zig/issues/20630),
but for now, the translate-c logic is copy-pasted from that project into
[ziglang/zig](https://codeberg.org/ziglang/zig/), powering both `zig translate-c`
and `@cImport`.
Please see the readme of the translate-c project for how to contribute. Once an
issue is resolved (and test coverage added) there, the changes can be
immediately backported to the zig compiler.
Once we fix the problems people are facing from this transition from Clang to
Aro, we can move on to enhancing the translate-c package such that `@cImport`
becomes redundant and can therefore be eliminated from the language.
### Autodoc
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
```
* `main.js` and `index.html` are static files which live in a Zig installation
at `lib/docs/`.
* `main.wasm` is compiled from the Zig files inside `lib/docs/wasm/`.
* `sources.tar` is all the zig source files of the project.
These artifacts are produced by the compiler when `-femit-docs` is passed.
#### Making Changes
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`.
#### Debugging the Zig Code
While Firefox and Safari support are obviously required, I recommend Chromium
for development for one reason in particular:
[C/C++ DevTools Support (DWARF)](https://chromewebstore.google.com/detail/cc++-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb)
This makes debugging Zig WebAssembly code a breeze.
#### The Sources Tarball
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`.
## Testing Zig Code With LLDB
[@jacobly0](https://github.com/jacobly0) maintains a fork of LLDB with Zig support:
https://github.com/jacobly0/llvm-project/tree/lldb-zig
This fork only contains changes for debugging programs compiled by Zig's
self-hosted backends, i.e. `zig build-exe -fno-llvm ...`.
### Building
To build the LLDB fork, make sure you have
[prerequisites](https://lldb.llvm.org/resources/build.html#preliminaries)
installed, and then do something like:
```
$ cmake llvm -G Ninja -B build -DLLVM_ENABLE_PROJECTS="clang;lldb" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=ON -DLLDB_ENABLE_LIBEDIT=ON -DLLDB_ENABLE_PYTHON=ON
$ cmake --build build --target lldb --target lldb-server
```
(You may need to manually [configure
dependencies](https://lldb.llvm.org/resources/build.html#optional-dependencies)
if CMake can't find them.)
Once built, you can run `./build/bin/lldb` and so on.
### Pretty Printers
If you will be debugging the Zig compiler itself, or if you will be debugging
any project compiled with Zig's LLVM backend (not recommended with the LLDB
fork, prefer vanilla LLDB with a version that matches the version of LLVM that
Zig is using), you can get a better debugging experience by using
[`lldb_pretty_printers.py`](https://codeberg.org/ziglang/zig/src/branch/master/tools/lldb_pretty_printers.py).
Put this line in `~/.lldbinit`:
```
command script import /path/to/zig/tools/lldb_pretty_printers.py
```
If you will be using Zig's LLVM backend (again, not recommended with the LLDB
fork), you will also want these lines:
```
type category enable zig.lang
type category enable zig.std
```
If you will be debugging a Zig compiler built using Zig's LLVM backend (again,
not recommended with the LLDB fork), you will also want this line:
```
type category enable zig.stage2
```
The Zig community is decentralized. Anyone is free to start and maintain their
own space for Zig users to gather. There is no concept of "official" or
"unofficial". Each gathering place has its own moderators and rules. Users are
encouraged to be aware of the social structures of the spaces they inhabit, and
work purposefully to facilitate spaces that align with their values.
Please see the [Community](https://github.com/ziglang/zig/wiki/Community) wiki
page for a public listing of social spaces.

View file

@ -64,8 +64,6 @@ static const char *get_host_os(void) {
return "linux";
#elif defined(__FreeBSD__)
return "freebsd";
#elif defined(__DragonFly__)
return "dragonfly";
#elif defined(__HAIKU__)
return "haiku";
#else
@ -143,7 +141,6 @@ int main(int argc, char **argv) {
"pub const skip_non_native = false;\n"
"pub const debug_gpa = false;\n"
"pub const dev = .core;\n"
"pub const io_mode: enum { threaded, evented } = .threaded;\n"
"pub const value_interpret_mode = .direct;\n"
, zig_version);
if (written < 100)

260
build.zig
View file

@ -1,21 +1,18 @@
const std = @import("std");
const builtin = std.builtin;
const tests = @import("test/tests.zig");
const BufMap = std.BufMap;
const mem = std.mem;
const io = std.io;
const fs = std.fs;
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
const assert = std.debug.assert;
const Io = std.Io;
const tests = @import("test/tests.zig");
const DevEnv = @import("src/dev.zig").Env;
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 16, .patch = 0 };
const stack_size = 46 * 1024 * 1024;
const IoMode = enum { threaded, evented };
const ValueInterpretMode = enum { direct, by_name };
const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 15, .patch = 1 };
const stack_size = 46 * 1024 * 1024;
pub fn build(b: *std.Build) !void {
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
const target = b.standardTargetOptions(.{
@ -30,7 +27,7 @@ pub fn build(b: *std.Build) !void {
const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;
const test_step = b.step("test", "Run all the tests");
const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse only_c;
const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse false;
const skip_install_langref = b.option(bool, "no-langref", "skip copying of langref to the installation prefix") orelse skip_install_lib_files;
const std_docs = b.option(bool, "std-docs", "include standard library autodocs") orelse false;
const no_bin = b.option(bool, "no-bin", "skip emitting compiler binary") orelse false;
@ -84,27 +81,23 @@ pub fn build(b: *std.Build) !void {
docs_step.dependOn(langref_step);
docs_step.dependOn(std_docs_step);
const no_matrix = b.option(bool, "no-matrix", "Limit test matrix to exactly one target configuration") orelse false;
const fuzz_only = b.option(bool, "fuzz-only", "Limit test matrix to one target suitable for fuzzing") orelse false;
const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false;
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse no_matrix;
const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;
const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse no_matrix;
const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
const skip_single_threaded = b.option(bool, "skip-single-threaded", "Main test suite skips tests that are single-threaded") orelse false;
const skip_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") orelse false;
const skip_spirv = b.option(bool, "skip-spirv", "Main test suite skips targets with spirv32/spirv64 architecture") orelse false;
const skip_wasm = b.option(bool, "skip-wasm", "Main test suite skips targets with wasm32/wasm64 architecture") orelse false;
const skip_translate_c = b.option(bool, "skip-translate-c", "Main test suite skips translate-c tests") orelse false;
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
const skip_freebsd = b.option(bool, "skip-freebsd", "Main test suite skips targets with freebsd OS") orelse false;
const skip_netbsd = b.option(bool, "skip-netbsd", "Main test suite skips targets with netbsd OS") orelse false;
const skip_openbsd = b.option(bool, "skip-openbsd", "Main test suite skips targets with openbsd OS") orelse false;
const skip_windows = b.option(bool, "skip-windows", "Main test suite skips targets with windows OS") orelse false;
const skip_darwin = b.option(bool, "skip-darwin", "Main test suite skips targets with darwin OSs") orelse false;
const skip_macos = b.option(bool, "skip-macos", "Main test suite skips targets with macos OS") orelse false;
const skip_linux = b.option(bool, "skip-linux", "Main test suite skips targets with linux OS") orelse false;
const skip_llvm = b.option(bool, "skip-llvm", "Main test suite skips targets that use LLVM backend") orelse false;
const skip_test_incremental = b.option(bool, "skip-test-incremental", "Main test step omits dependency on test-incremental step") orelse false;
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
@ -190,7 +183,6 @@ pub fn build(b: *std.Build) !void {
const strip = b.option(bool, "strip", "Omit debug information");
const valgrind = b.option(bool, "valgrind", "Enable valgrind integration");
const pie = b.option(bool, "pie", "Produce a Position Independent Executable");
const io_mode = b.option(IoMode, "io-mode", "How the compiler performs IO") orelse .threaded;
const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct;
const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
@ -210,7 +202,6 @@ pub fn build(b: *std.Build) !void {
});
exe.pie = pie;
exe.entitlements = entitlements;
exe.use_new_linker = b.option(bool, "new-linker", "Use the new linker");
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm;
@ -239,7 +230,6 @@ pub fn build(b: *std.Build) !void {
exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
exe_options.addOption(bool, "debug_gpa", debug_gpa);
exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full);
exe_options.addOption(IoMode, "io_mode", io_mode);
exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode);
if (link_libc) {
@ -266,12 +256,12 @@ pub fn build(b: *std.Build) !void {
"--git-dir", ".git", // affected by the -C argument
"describe", "--match", "*.*.*", //
"--tags", "--abbrev=9",
}, &code, .ignore) catch {
}, &code, .Ignore) catch {
break :v version_string;
};
const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r");
switch (mem.countScalar(u8, git_describe, '-')) {
switch (mem.count(u8, git_describe, "-")) {
0 => {
// Tagged release version (e.g. 0.10.0).
if (!mem.eql(u8, git_describe, version_string)) {
@ -313,10 +303,8 @@ pub fn build(b: *std.Build) !void {
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else blk: {
const io = b.graph.io;
const cwd: Io.Dir = .cwd();
if (findConfigH(b, config_h_path_option)) |config_h_path| {
const file_contents = cwd.readFileAlloc(io, config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable;
const file_contents = fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable;
break :blk parseConfigH(b, file_contents);
} else {
std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{});
@ -371,22 +359,14 @@ pub fn build(b: *std.Build) !void {
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
);
const tracy_c_flags: []const []const u8 = &.{
"-DTRACY_ENABLE=1",
"-fno-sanitize=undefined",
"-DTRACY_FIBERS",
};
const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
exe.root_module.addCSourceFile(.{
.file = .{ .cwd_relative = client_cpp },
.flags = tracy_c_flags[0..switch (io_mode) {
.threaded => 2,
.evented => 3,
}],
});
exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
if (!enable_llvm) {
exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no });
}
exe.root_module.link_libc = true;
exe.root_module.link_libcpp = true;
if (target.result.os.tag == .windows) {
exe.root_module.linkSystemLibrary("dbghelp", .{});
@ -418,13 +398,6 @@ pub fn build(b: *std.Build) !void {
}
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];
const test_only: ?tests.ModuleTestOptions.TestOnly = if (no_matrix)
.default
else if (fuzz_only)
.{ .fuzz = optimize }
else
null;
const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" };
const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" };
const do_fmt = b.addFmt(.{
@ -442,21 +415,21 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(check_fmt);
const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
try tests.addCases(b, test_cases_step, .{
try tests.addCases(b, test_cases_step, target, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.skip_compile_errors = skip_compile_errors,
.skip_non_native = skip_non_native,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
}, .{
.skip_translate_c = skip_translate_c,
.skip_run_translated_c = skip_run_translated_c,
}, .{
.enable_llvm = enable_llvm,
.llvm_has_m68k = llvm_has_m68k,
@ -480,18 +453,35 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
// 3888779264 was observed on an x86_64-linux-gnu host.
.max_rss = 4000000000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_extra_targets = test_extra_targets,
.root_src = "test/c_import.zig",
.name = "c-import",
.desc = "Run the @cImport tests",
.optimize_modes = optimization_modes,
.include_paths = &.{"test/c_import"},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_windows = skip_windows,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
.max_rss = 4_000_000_000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
@ -505,19 +495,14 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = true,
.no_builtin = true,
.max_rss = 4_000_000_000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
@ -526,24 +511,19 @@ pub fn build(b: *std.Build) !void {
.test_extra_targets = test_extra_targets,
.root_src = "lib/c.zig",
.name = "zigc",
.desc = "Run the zig libc implementation unit tests",
.desc = "Run the zigc tests",
.optimize_modes = optimization_modes,
.include_paths = &.{},
.skip_single_threaded = true,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = true,
.no_builtin = true,
.max_rss = 4_000_000_000,
}));
test_modules_step.dependOn(tests.addModuleTests(b, .{
@ -557,18 +537,15 @@ pub fn build(b: *std.Build) !void {
.include_paths = &.{},
.skip_single_threaded = skip_single_threaded,
.skip_non_native = skip_non_native,
.test_only = test_only,
.skip_spirv = skip_spirv,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_libc = skip_libc,
.max_rss = 8_500_000_000,
// I observed a value of 5605064704 on the M2 CI.
.max_rss = 6165571174,
}));
const unit_tests_step = b.step("test-unit", "Run the compiler source unit tests");
@ -584,7 +561,6 @@ pub fn build(b: *std.Build) !void {
.use_llvm = use_llvm,
.use_lld = use_llvm,
.zig_lib_dir = b.path("lib"),
.max_rss = 2_500_000_000,
});
if (link_libc) {
unit_tests.root_module.link_libc = true;
@ -592,6 +568,7 @@ pub fn build(b: *std.Build) !void {
unit_tests.root_module.addOptions("build_options", exe_options);
unit_tests_step.dependOn(&b.addRunArtifact(unit_tests).step);
test_step.dependOn(tests.addCompareOutputTests(b, test_filters, optimization_modes));
test_step.dependOn(tests.addStandaloneTests(
b,
optimization_modes,
@ -602,21 +579,18 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addCAbiTests(b, .{
.test_target_filters = test_target_filters,
.skip_non_native = skip_non_native,
.skip_wasm = skip_wasm,
.skip_freebsd = skip_freebsd,
.skip_netbsd = skip_netbsd,
.skip_openbsd = skip_openbsd,
.skip_windows = skip_windows,
.skip_darwin = skip_darwin,
.skip_macos = skip_macos,
.skip_linux = skip_linux,
.skip_llvm = skip_llvm,
.skip_release = skip_release,
.max_rss = 3_000_000_000,
}));
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows));
test_step.dependOn(tests.addStackTraceTests(b, test_filters, skip_non_native));
test_step.dependOn(tests.addErrorTraceTests(b, test_filters, optimization_modes, skip_non_native));
test_step.dependOn(tests.addStackTraceTests(b, test_filters, optimization_modes));
test_step.dependOn(tests.addCliTests(b));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes));
if (tests.addDebuggerTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
@ -654,16 +628,8 @@ pub fn build(b: *std.Build) !void {
}
const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases");
try tests.addIncrementalTests(b, test_incremental_step, test_filters);
if (!skip_test_incremental) test_step.dependOn(test_incremental_step);
if (tests.addLibcTests(b, .{
.optimize_modes = optimization_modes,
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.skip_wasm = skip_wasm,
.max_rss = 3_500_000_000,
})) |test_libc_step| test_step.dependOn(test_libc_step);
try tests.addIncrementalTests(b, test_incremental_step);
test_step.dependOn(test_incremental_step);
}
fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
@ -696,7 +662,6 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
exe_options.addOption(u32, "tracy_callstack_depth", 0);
exe_options.addOption(bool, "value_tracing", false);
exe_options.addOption(DevEnv, "dev", .bootstrap);
exe_options.addOption(IoMode, "io_mode", .threaded);
// zig1 chooses to interpret values by name. The tradeoff is as follows:
//
@ -725,14 +690,14 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
});
run_opt.addArtifactArg(exe);
run_opt.addArg("-o");
const optimized_wasm = run_opt.addOutputFileArg("zig1.wasm");
run_opt.addFileArg(b.path("stage1/zig1.wasm"));
const update_zig1 = b.addUpdateSourceFiles();
update_zig1.addCopyFileToSource(optimized_wasm, "stage1/zig1.wasm");
update_zig1.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
const copy_zig_h = b.addUpdateSourceFiles();
copy_zig_h.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
update_zig1_step.dependOn(&update_zig1.step);
update_zig1_step.dependOn(&run_opt.step);
update_zig1_step.dependOn(&copy_zig_h.step);
}
const AddCompilerModOptions = struct {
@ -759,7 +724,13 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu
.root_source_file = b.path("lib/compiler/aro/aro.zig"),
});
const aro_translate_c_mod = b.createModule(.{
.root_source_file = b.path("lib/compiler/aro_translate_c.zig"),
});
aro_translate_c_mod.addImport("aro", aro_mod);
compiler_mod.addImport("aro", aro_mod);
compiler_mod.addImport("aro_translate_c", aro_translate_c_mod);
return compiler_mod;
}
@ -767,17 +738,11 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu
fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile {
const exe = b.addExecutable(.{
.name = "zig",
.max_rss = 7_900_000_000,
.max_rss = 7_800_000_000,
.root_module = addCompilerMod(b, options),
});
exe.stack_size = stack_size;
// Must match the condition in CMakeLists.txt.
const function_data_sections = options.target.result.cpu.arch.isArm() or options.target.result.cpu.arch.isPowerPC();
exe.link_function_sections = function_data_sections;
exe.link_data_sections = function_data_sections;
return exe;
}
@ -850,7 +815,7 @@ fn addCmakeCfgOptionsToExe(
};
mod.linkSystemLibrary("unwind", .{});
},
.driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => {
.ios, .macos, .watchos, .tvos, .visionos => {
mod.link_libcpp = true;
},
.windows => {
@ -871,7 +836,7 @@ fn addCmakeCfgOptionsToExe(
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
if (static) try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
},
.illumos => {
.solaris, .illumos => {
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
},
@ -904,48 +869,46 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
.flags = &zig_cpp_cflags,
});
const lsl_options: std.Build.Module.LinkSystemLibraryOptions = .{ .use_pkg_config = .no };
for (clang_libs) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
}
for (lld_libs) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
}
for (llvm_libs) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
}
if (options.llvm_has_m68k) for (llvm_libs_m68k) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_csky) for (llvm_libs_csky) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_arc) for (llvm_libs_arc) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_xtensa) for (llvm_libs_xtensa) |lib_name| {
mod.linkSystemLibrary(lib_name, lsl_options);
mod.linkSystemLibrary(lib_name, .{});
};
mod.linkSystemLibrary("z", lsl_options);
mod.linkSystemLibrary("zstd", lsl_options);
mod.linkSystemLibrary("z", .{});
mod.linkSystemLibrary("zstd", .{});
if (mod.resolved_target.?.result.os.tag != .windows or mod.resolved_target.?.result.abi != .msvc) {
// This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
mod.linkSystemLibrary("c++", lsl_options);
mod.linkSystemLibrary("c++", .{});
}
if (mod.resolved_target.?.result.os.tag == .windows) {
mod.linkSystemLibrary("version", lsl_options);
mod.linkSystemLibrary("uuid", lsl_options);
mod.linkSystemLibrary("ole32", lsl_options);
mod.linkSystemLibrary("version", .{});
mod.linkSystemLibrary("uuid", .{});
mod.linkSystemLibrary("ole32", .{});
}
}
@ -1030,13 +993,10 @@ const CMakeConfig = struct {
const max_config_h_bytes = 1 * 1024 * 1024;
fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
const io = b.graph.io;
const cwd: Io.Dir = .cwd();
if (config_h_path_option) |path| {
var config_h_or_err = cwd.openFile(io, path, .{});
var config_h_or_err = fs.cwd().openFile(path, .{});
if (config_h_or_err) |*file| {
file.close(io);
file.close();
return path;
} else |_| {
std.log.err("Could not open provided config.h: \"{s}\"", .{path});
@ -1046,13 +1006,13 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
var check_dir = fs.path.dirname(b.graph.zig_exe).?;
while (true) {
var dir = cwd.openDir(io, check_dir, .{}) catch unreachable;
defer dir.close(io);
var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
defer dir.close();
// Check if config.h is present in dir
var config_h_or_err = dir.openFile(io, "config.h", .{});
var config_h_or_err = dir.openFile("config.h", .{});
if (config_h_or_err) |*file| {
file.close(io);
file.close();
return fs.path.join(
b.allocator,
&[_][]const u8{ check_dir, "config.h" },
@ -1063,9 +1023,9 @@ fn findConfigH(b: *std.Build, config_h_path_option: ?[]const u8) ?[]const u8 {
}
// Check if we reached the source root by looking for .git, and bail if so
var git_dir_or_err = dir.openDir(io, ".git", .{});
var git_dir_or_err = dir.openDir(".git", .{});
if (git_dir_or_err) |*git_dir| {
git_dir.close(io);
git_dir.close();
return null;
} else |_| {}
@ -1190,6 +1150,7 @@ fn toNativePathSep(b: *std.Build, s: []const u8) []u8 {
const zig_cpp_sources = [_][]const u8{
// These are planned to stay even when we are self-hosted.
"src/zig_llvm.cpp",
"src/zig_clang.cpp",
"src/zig_llvm-ar.cpp",
"src/zig_clang_driver.cpp",
"src/zig_clang_cc1_main.cpp",
@ -1215,6 +1176,7 @@ const clang_libs = [_][]const u8{
"clangBasic",
"clangEdit",
"clangLex",
"clangARCMigrate",
"clangRewriteFrontend",
"clangRewrite",
"clangCrossTU",
@ -1360,31 +1322,30 @@ const llvm_libs = [_][]const u8{
"LLVMOrcTargetProcess",
"LLVMOrcShared",
"LLVMDWP",
"LLVMDWARFCFIChecker",
"LLVMDebugInfoLogicalView",
"LLVMDebugInfoGSYM",
"LLVMOption",
"LLVMObjectYAML",
"LLVMObjCopy",
"LLVMMCA",
"LLVMMCDisassembler",
"LLVMLTO",
"LLVMFrontendOpenACC",
"LLVMFrontendHLSL",
"LLVMFrontendDriver",
"LLVMExtensions",
"LLVMPasses",
"LLVMHipStdPar",
"LLVMCoroutines",
"LLVMCFGuard",
"LLVMCoroutines",
"LLVMipo",
"LLVMInstrumentation",
"LLVMVectorize",
"LLVMSandboxIR",
"LLVMLinker",
"LLVMInstrumentation",
"LLVMFrontendOpenMP",
"LLVMFrontendDirective",
"LLVMFrontendAtomic",
"LLVMFrontendOffloading",
"LLVMObjectYAML",
"LLVMFrontendOpenACC",
"LLVMFrontendHLSL",
"LLVMFrontendDriver",
"LLVMFrontendAtomic",
"LLVMExtensions",
"LLVMDWARFLinkerParallel",
"LLVMDWARFLinkerClassic",
"LLVMDWARFLinker",
@ -1413,9 +1374,7 @@ const llvm_libs = [_][]const u8{
"LLVMDebugInfoPDB",
"LLVMDebugInfoMSF",
"LLVMDebugInfoCodeView",
"LLVMDebugInfoGSYM",
"LLVMDebugInfoDWARF",
"LLVMDebugInfoDWARFLowLevel",
"LLVMObject",
"LLVMTextAPI",
"LLVMMCParser",
@ -1461,8 +1420,6 @@ const llvm_libs_xtensa = [_][]const u8{
};
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const io = b.graph.io;
const doctest_exe = b.addExecutable(.{
.name = "doctest",
.root_module = b.createModule(.{
@ -1472,18 +1429,17 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
}),
});
var dir = b.build_root.handle.openDir(io, "doc/langref", .{ .iterate = true }) catch |err| {
var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| {
std.debug.panic("unable to open '{f}doc/langref' directory: {s}", .{
b.build_root, @errorName(err),
});
};
defer dir.close(io);
defer dir.close();
var wf = b.addWriteFiles();
b.step("test-docs", "Test code snippets from the docs").dependOn(&wf.step);
var it = dir.iterateAssumeFirstIteration();
while (it.next(io) catch @panic("failed to read dir")) |entry| {
while (it.next() catch @panic("failed to read dir")) |entry| {
if (std.mem.startsWith(u8, entry.name, ".") or entry.kind != .file)
continue;

View file

@ -1,63 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,69 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -5,14 +5,20 @@
set -x
set -e
TARGET="aarch64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -44,15 +50,13 @@ ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--maxrss 44918199637 \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 3m
-Denable-superhtml
stage3-debug/bin/zig build \
--prefix stage4-debug \

View file

@ -5,14 +5,20 @@
set -x
set -e
TARGET="aarch64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -44,15 +50,13 @@ ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--maxrss 44918199637 \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 3m
-Denable-superhtml
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \

View file

@ -3,10 +3,13 @@
set -x
set -e
# Script assumes the presence of the following:
# s3cmd
ZIGDIR="$PWD"
TARGET="aarch64-macos-none"
TARGET="$ARCH-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
@ -18,6 +21,11 @@ fi
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -27,7 +35,7 @@ export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
cmake .. \
PATH="$HOME/local/bin:$PATH" cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
@ -39,24 +47,11 @@ cmake .. \
-DZIG_NO_LIB=ON \
-GNinja
ninja install
$HOME/local/bin/ninja install
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--test-timeout 2m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig
--search-prefix "$PREFIX"

View file

@ -3,10 +3,13 @@
set -x
set -e
# Script assumes the presence of the following:
# s3cmd
ZIGDIR="$PWD"
TARGET="aarch64-macos-none"
TARGET="$ARCH-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
@ -18,6 +21,11 @@ fi
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -27,7 +35,7 @@ export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
cmake .. \
PATH="$HOME/local/bin:$PATH" cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
@ -39,20 +47,17 @@ cmake .. \
-DZIG_NO_LIB=ON \
-GNinja
ninja install
$HOME/local/bin/ninja install
stage3-release/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--test-timeout 2m
--search-prefix "$PREFIX"
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--maxrss ${ZSF_MAX_RSS:-0} \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
@ -63,7 +68,6 @@ stage3-release/bin/zig build \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
# https://codeberg.org/ziglang/zig/issues/30687
#echo "If the following command fails, it means nondeterminism has been"
#echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
#diff stage3-release/bin/zig stage4-release/bin/zig
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -1,63 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,69 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="aarch64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -1,11 +1,10 @@
$TARGET = "aarch64-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
$MCPU = "baseline"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$(Get-Location)\..\$ZIG_LLVM_CLANG_LLD_NAME"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
if (!(Test-Path "..\$ZIG_LLVM_CLANG_LLD_NAME.zip")) {
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
@ -23,6 +22,14 @@ function CheckLastExitCode {
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -55,14 +62,11 @@ CheckLastExitCode
Write-Output "Main test suite..."
& "stage3-release\bin\zig.exe" build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
-Dskip-test-incremental `
-Denable-symlinks-windows `
--test-timeout 30m
-Denable-symlinks-windows
CheckLastExitCode
# Ensure that stage3 and stage4 are byte-for-byte identical.

View file

@ -1,65 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="loongarch64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,71 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="loongarch64-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -1,67 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="powerpc64le-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1594+9fa433d71"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
-Dcpu=native+longcall \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Dcpu=$MCPU \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,73 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="powerpc64le-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1594+9fa433d71"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
-Dcpu=native+longcall \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Dcpu=$MCPU \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -5,14 +5,20 @@
set -x
set -e
TARGET="riscv64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="spacemit_x60"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.15.0-dev.929+31e46be74"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -43,12 +49,14 @@ unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test-modules test-c-abi \
--maxrss ${ZSF_MAX_RSS:-0} \
stage3-debug/bin/zig build test-cases test-modules test-unit test-c-abi test-stack-traces test-asm-link test-llvm-ir \
--maxrss 68719476736 \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-compile-errors \
-Dskip-translate-c \
-Dskip-run-translated-c \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
--zig-lib-dir "$PWD/../lib"

View file

@ -5,14 +5,20 @@
set -x
set -e
TARGET="riscv64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="spacemit_x60"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.15.0-dev.929+31e46be74"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -43,12 +49,14 @@ unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test-modules test-c-abi \
--maxrss ${ZSF_MAX_RSS:-0} \
stage3-release/bin/zig build test-cases test-modules test-unit test-c-abi test-stack-traces test-asm-link test-llvm-ir \
--maxrss 68719476736 \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-compile-errors \
-Dskip-translate-c \
-Dskip-run-translated-c \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
--zig-lib-dir "$PWD/../lib"

View file

@ -1,66 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="s390x-linux-musl"
MCPU="z15"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1354+94e98bfe8"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Dcpu=$MCPU \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,72 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="s390x-linux-musl"
MCPU="z15"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.1354+94e98bfe8"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Dcpu=$MCPU \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -1,69 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-spirv \
-Dskip-wasm \
-Dskip-linux \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,75 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-freebsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-spirv \
-Dskip-wasm \
-Dskip-linux \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

38
ci/x86_64-linux-debug-llvm.sh Executable file → Normal file
View file

@ -5,13 +5,19 @@
set -x
set -e
TARGET="x86_64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH"
export PATH="$HOME/deps/wasmtime-v29.0.0-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-10.0.2/bin:$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
@ -34,10 +40,7 @@ cmake .. \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-DZIG_EXTRA_BUILD_ARGS="-Duse-llvm=true" \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
@ -52,31 +55,16 @@ stage3-debug/bin/zig build \
-Dno-lib
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
-Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-freebsd \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-test-incremental \
-Dskip-macos \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 12m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Duse-llvm \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig
-Denable-superhtml

View file

@ -5,13 +5,19 @@
set -x
set -e
TARGET="x86_64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH"
export PATH="$HOME/deps/wasmtime-v29.0.0-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-10.0.2/bin:$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
@ -33,10 +39,7 @@ cmake .. \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
@ -51,30 +54,17 @@ stage3-debug/bin/zig build \
-Dno-lib
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-freebsd \
-Dskip-netbsd \
-Dskip-openbsd \
-Dskip-windows \
-Dskip-darwin \
-Dskip-macos \
-Dskip-llvm \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 10m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig
-Denable-superhtml

View file

@ -5,13 +5,19 @@
set -x
set -e
TARGET="x86_64-linux-musl"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH"
export PATH="$HOME/deps/wasmtime-v29.0.0-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-10.0.2/bin:$HOME/local/bin:$PATH"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
@ -39,10 +45,7 @@ cmake .. \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
@ -57,18 +60,15 @@ stage3-release/bin/zig build \
-Dno-lib
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Release-e0a42bb34/bin/lldb \
-Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dskip-test-incremental \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 12m
-Denable-superhtml
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
@ -102,10 +102,7 @@ cmake .. \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
-GNinja
unset CC
unset CXX

75
ci/x86_64-macos-release.sh Executable file
View file

@ -0,0 +1,75 @@
#!/bin/sh
set -x
set -e
ZIGDIR="$PWD"
TARGET="$ARCH-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j3"
ZIG="$PREFIX/bin/zig"
if [ ! -d "$PREFIX" ]; then
cd $HOME
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
fi
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
# Test building from source without LLVM.
cc -o bootstrap bootstrap.c
./bootstrap
./zig2 build -Dno-lib
./zig-out/bin/zig test test/behavior.zig
mkdir build
cd build
cmake .. \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \
-DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON
make $JOBS install
stage3/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3/bin/zig build \
--prefix stage4 \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3/bin/zig stage4/bin/zig

View file

@ -1,63 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,69 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-netbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -1,63 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-openbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2051+28b83e3b0"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

View file

@ -1,69 +0,0 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
TARGET="x86_64-openbsd-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2051+28b83e3b0"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
-Dskip-test-incremental \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View file

@ -1,9 +1,19 @@
$TARGET = "x86_64-windows-gnu"
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
$MCPU = "baseline"
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
if (!(Test-Path "$PREFIX_PATH.zip")) {
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
Write-Output "Extracting..."
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
}
function CheckLastExitCode {
if (!$?) {
@ -12,6 +22,14 @@ function CheckLastExitCode {
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -24,7 +42,7 @@ Set-Location -Path 'build-debug'
# CMake gives a syntax error when file paths with backward slashes are used.
# Here, we use forward slashes only to work around this.
cmake .. `
& cmake .. `
-GNinja `
-DCMAKE_INSTALL_PREFIX="stage3-debug" `
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
@ -43,50 +61,49 @@ ninja install
CheckLastExitCode
Write-Output "Main test suite..."
stage3-debug\bin\zig build test docs `
--maxrss $ZSF_MAX_RSS `
& "stage3-debug\bin\zig.exe" build test docs `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
-Dskip-test-incremental `
-Denable-symlinks-windows `
--test-timeout 30m
-Dskip-release `
-Denable-symlinks-windows
CheckLastExitCode
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
stage3-debug\bin\zig build-obj `
& "stage3-debug\bin\zig.exe" test `
..\test\behavior.zig `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="test-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc
CheckLastExitCode
& "stage3-debug\bin\zig.exe" build-obj `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-OReleaseSmall `
--name compiler_rt `
-femit-bin="compiler_rt-x86_64-windows-msvc.c" `
--dep build_options `
-target x86_64-windows-msvc `
-lc `
..\lib\compiler_rt.zig
-Mroot="..\lib\compiler_rt.zig" `
-Mbuild_options="config.zig"
CheckLastExitCode
stage3-debug\bin\zig test `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="behavior-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc `
..\test\behavior.zig
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
CheckLastExitCode
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
CheckLastExitCode
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
-DevCmdArguments '-arch=x64 -no_logo' `
-StartInPath $(Get-Location)
CheckLastExitCode
Write-Output "Build and run behavior tests with msvc..."
cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
CheckLastExitCode
.\behavior-x86_64-windows-msvc
& .\test-x86_64-windows-msvc.exe
CheckLastExitCode

View file

@ -1,9 +1,19 @@
$TARGET = "x86_64-windows-gnu"
$TARGET = "$($Env:ARCH)-windows-gnu"
$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
$MCPU = "baseline"
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
if (!(Test-Path "$PREFIX_PATH.zip")) {
Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL"
Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip"
Write-Output "Extracting..."
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..")
}
function CheckLastExitCode {
if (!$?) {
@ -12,6 +22,14 @@ function CheckLastExitCode {
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
@ -24,7 +42,7 @@ Set-Location -Path 'build-release'
# CMake gives a syntax error when file paths with backward slashes are used.
# Here, we use forward slashes only to work around this.
cmake .. `
& cmake .. `
-GNinja `
-DCMAKE_INSTALL_PREFIX="stage3-release" `
-DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" `
@ -43,20 +61,17 @@ ninja install
CheckLastExitCode
Write-Output "Main test suite..."
stage3-release\bin\zig.exe build test docs `
--maxrss $ZSF_MAX_RSS `
& "stage3-release\bin\zig.exe" build test docs `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
-Dskip-test-incremental `
-Denable-symlinks-windows `
--test-timeout 30m
-Denable-symlinks-windows
CheckLastExitCode
# Ensure that stage3 and stage4 are byte-for-byte identical.
Write-Output "Build and compare stage4..."
stage3-release\bin\zig.exe build `
& "stage3-release\bin\zig.exe" build `
--prefix stage4-release `
-Denable-llvm `
-Dno-lib `
@ -74,38 +89,39 @@ Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-rele
CheckLastExitCode
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
stage3-release\bin\zig.exe build-obj `
& "stage3-release\bin\zig.exe" test `
..\test\behavior.zig `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="test-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc
CheckLastExitCode
& "stage3-release\bin\zig.exe" build-obj `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-OReleaseSmall `
--name compiler_rt `
-femit-bin="compiler_rt-x86_64-windows-msvc.c" `
--dep build_options `
-target x86_64-windows-msvc `
-lc `
..\lib\compiler_rt.zig
-Mroot="..\lib\compiler_rt.zig" `
-Mbuild_options="config.zig"
CheckLastExitCode
stage3-release\bin\zig.exe test `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="behavior-x86_64-windows-msvc.c" `
--test-no-exec `
-target x86_64-windows-msvc `
-lc `
..\test\behavior.zig
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
CheckLastExitCode
Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
CheckLastExitCode
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" `
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" `
-DevCmdArguments '-arch=x64 -no_logo' `
-StartInPath $(Get-Location)
CheckLastExitCode
Write-Output "Build and run behavior tests with msvc..."
cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
CheckLastExitCode
.\behavior-x86_64-windows-msvc
& .\test-x86_64-windows-msvc.exe
CheckLastExitCode

View file

@ -17,10 +17,10 @@ find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
if(${LLVM_LINK_MODE} STREQUAL "shared")
find_library(CLANG_LIBRARIES
NAMES
libclang-cpp.so.21
libclang-cpp.so.21.1
clang-cpp-21.0
clang-cpp210
libclang-cpp.so.20
libclang-cpp.so.20.1
clang-cpp-20.0
clang-cpp200
clang-cpp
NAMES_PER_DIR
HINTS "${LLVM_LIBDIRS}"
@ -60,6 +60,7 @@ else()
FIND_AND_ADD_CLANG_LIB(clangBasic)
FIND_AND_ADD_CLANG_LIB(clangEdit)
FIND_AND_ADD_CLANG_LIB(clangLex)
FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangCrossTU)

View file

@ -9,23 +9,23 @@
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
HINTS ${LLVM_INCLUDE_DIRS}
PATHS
/usr/lib/llvm-21/include
/usr/local/llvm210/include
/usr/local/llvm21/include
/usr/local/opt/lld@21/include
/opt/homebrew/opt/lld@21/include
/home/linuxbrew/.linuxbrew/opt/lld@21/include
/usr/lib/llvm-20/include
/usr/local/llvm200/include
/usr/local/llvm20/include
/usr/local/opt/lld@20/include
/opt/homebrew/opt/lld@20/include
/home/linuxbrew/.linuxbrew/opt/lld@20/include
/mingw64/include)
find_library(LLD_LIBRARY NAMES lld-21.0 lld210 lld NAMES_PER_DIR
find_library(LLD_LIBRARY NAMES lld-20.0 lld200 lld NAMES_PER_DIR
HINTS ${LLVM_LIBDIRS}
PATHS
/usr/lib/llvm-21/lib
/usr/local/llvm210/lib
/usr/local/llvm21/lib
/usr/local/opt/lld@21/lib
/opt/homebrew/opt/lld@21/lib
/home/linuxbrew/.linuxbrew/opt/lld@21/lib
/usr/lib/llvm-20/lib
/usr/local/llvm200/lib
/usr/local/llvm20/lib
/usr/local/opt/lld@20/lib
/opt/homebrew/opt/lld@20/lib
/home/linuxbrew/.linuxbrew/opt/lld@20/lib
)
if(EXISTS ${LLD_LIBRARY})
set(LLD_LIBRARIES ${LLD_LIBRARY})
@ -36,12 +36,12 @@ else()
HINTS ${LLVM_LIBDIRS}
PATHS
${LLD_LIBDIRS}
/usr/lib/llvm-21/lib
/usr/local/llvm210/lib
/usr/local/llvm21/lib
/usr/local/opt/lld@21/lib
/opt/homebrew/opt/lld@21/lib
/home/linuxbrew/.linuxbrew/opt/lld@21/lib
/usr/lib/llvm-20/lib
/usr/local/llvm200/lib
/usr/local/llvm20/lib
/usr/local/opt/lld@20/lib
/opt/homebrew/opt/lld@20/lib
/home/linuxbrew/.linuxbrew/opt/lld@20/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:/msys64/mingw64/lib)

View file

@ -17,12 +17,12 @@ if(ZIG_USE_LLVM_CONFIG)
# terminate when the right LLVM version is not found.
unset(LLVM_CONFIG_EXE CACHE)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-21 llvm-config-21.0 llvm-config210 llvm-config21 llvm-config NAMES_PER_DIR
NAMES llvm-config-20 llvm-config-20.0 llvm-config200 llvm-config20 llvm-config NAMES_PER_DIR
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-21.0.0/bin")
"C:/Libraries/llvm-20.0.0/bin")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
@ -40,9 +40,9 @@ if(ZIG_USE_LLVM_CONFIG)
OUTPUT_STRIP_TRAILING_WHITESPACE)
get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 21 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 22 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 22)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 20 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 21 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 21)
# Save the error message, in case this is the last llvm-config we find
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 21.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 20.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
# Ignore this directory and try the search again
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
@ -66,9 +66,9 @@ if(ZIG_USE_LLVM_CONFIG)
if (LLVM_CONFIG_ERROR)
# Save the error message, in case this is the last llvm-config we find
if (ZIG_SHARED_LLVM)
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 21.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 20.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
else()
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 21.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 20.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
endif()
# Ignore this directory and try the search again
@ -83,7 +83,7 @@ if(ZIG_USE_LLVM_CONFIG)
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
set(ZIG_LLVM_REQUIRED_TARGETS "AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;LoongArch;Mips;MSP430;NVPTX;PowerPC;RISCV;SPIRV;Sparc;SystemZ;VE;WebAssembly;X86;XCore")
set(ZIG_LLVM_REQUIRED_TARGETS "AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore")
set(ZIG_LLVM_REQUIRED_TARGETS_ENABLED TRUE)
foreach(TARGET_NAME IN LISTS ZIG_LLVM_REQUIRED_TARGETS)
@ -315,31 +315,30 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
FIND_AND_ADD_LLVM_LIB(LLVMDWP)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFCFIChecker)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoLogicalView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMObjCopy)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendHLSL)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendDriver)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMHipStdPar)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMSandboxIR)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendDirective)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendAtomic)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOffloading)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendHLSL)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendDriver)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendAtomic)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinkerParallel)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinkerClassic)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
@ -368,9 +367,7 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARFLowLevel)
FIND_AND_ADD_LLVM_LIB(LLVMObject)
FIND_AND_ADD_LLVM_LIB(LLVMTextAPI)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)

View file

@ -128,7 +128,6 @@
}
.table-wrapper {
width: 100%;
margin: 1em auto;
overflow-x: auto;
}
@ -318,7 +317,7 @@
<a href="https://ziglang.org/documentation/0.12.0/">0.12.0</a> |
<a href="https://ziglang.org/documentation/0.13.0/">0.13.0</a> |
<a href="https://ziglang.org/documentation/0.14.1/">0.14.1</a> |
<a href="https://ziglang.org/documentation/0.15.2/">0.15.2</a> |
<a href="https://ziglang.org/documentation/0.15.1/">0.15.1</a> |
master
</nav>
<nav aria-labelledby="table-of-contents">
@ -422,7 +421,8 @@
{#code|unattached_doc-comment.zig#}
<p>
Doc comments can be interleaved with normal comments, which are ignored.
Doc comments can be interleaved with normal comments. Currently, when producing
the package documentation, normal comments are merged with doc comments.
</p>
{#header_close#}
{#header_open|Top-Level Doc Comments#}
@ -438,25 +438,6 @@
{#header_close#}
{#header_close#}
{#header_open|Identifiers#}
<p>
Identifiers must start with an alphabetic character or underscore and may be followed
by any number of alphanumeric characters or underscores.
They must not overlap with any keywords. See {#link|Keyword Reference#}.
</p>
{#header_open|String Identifier Syntax#}
<p>
If a name that does not fit these requirements is needed, such as for
linking with external libraries, the {#syntax#}@""{#endsyntax#} syntax
may be used.
</p>
{#code|identifiers.zig#}
{#header_close#}
{#header_close#}
{#header_open|Values#}
{#code|values.zig#}
@ -658,7 +639,7 @@
{#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an
integer type is {#syntax#}65535{#endsyntax#}.
</p>
{#see_also|Integers|Floats|void|Errors|@Int#}
{#see_also|Integers|Floats|void|Errors|@Type#}
{#header_close#}
{#header_open|Primitive Values#}
<div class="table-wrapper">
@ -982,9 +963,6 @@
humans and computers to do when reading code, and creates more optimization opportunities.
</p>
<p>
Variables are never allowed to shadow {#link|Identifiers#} from an outer scope.
</p>
<p>
The {#syntax#}extern{#endsyntax#} keyword or {#link|@extern#} builtin function can be used to link against a variable that is exported
from another object. The {#syntax#}export{#endsyntax#} keyword or {#link|@export#} builtin function
can be used to make a variable available to other objects at link time. In both cases,
@ -992,6 +970,22 @@
</p>
{#see_also|Exporting a C Library#}
{#header_open|Identifiers#}
<p>
Variable identifiers are never allowed to shadow identifiers from an outer scope.
</p>
<p>
Identifiers must start with an alphabetic character or underscore and may be followed
by any number of alphanumeric characters or underscores.
They must not overlap with any keywords. See {#link|Keyword Reference#}.
</p>
<p>
If a name that does not fit these requirements is needed, such as for linking with external libraries, the {#syntax#}@""{#endsyntax#} syntax may be used.
</p>
{#code|identifiers.zig#}
{#header_close#}
{#header_open|Container Level Variables#}
<p>
{#link|Container|Containers#} level variables have static lifetime and are order-independent and lazily analyzed.
@ -1975,14 +1969,6 @@ or
</p>
{#see_also|@splat|@shuffle|@select|@reduce#}
{#header_open|Relationship with Arrays#}
<p>Vectors and {#link|Arrays#} each have a well-defined <strong>bit layout</strong>
and therefore support {#link|@bitCast#} between each other. {#link|Type Coercion#} implicitly peforms
{#syntax#}@bitCast{#endsyntax#}.</p>
<p>Arrays have well-defined byte layout, but vectors do not, making {#link|@ptrCast#} between
them {#link|Illegal Behavior#}.</p>
{#header_close#}
{#header_open|Destructuring Vectors#}
<p>
Vectors can be destructured:
@ -2468,8 +2454,7 @@ or
{#header_open|Tagged union#}
<p>Unions can be declared with an enum tag type.
This turns the union into a <em>tagged</em> union, which makes it eligible
to use with {#link|switch#} expressions. When switching on tagged unions,
the tag value can be obtained using an additional capture.
to use with {#link|switch#} expressions.
Tagged unions coerce to their tag type: {#link|Type Coercion: Unions and Enums#}.
</p>
{#code|test_tagged_union.zig#}
@ -2511,7 +2496,6 @@ or
{#header_open|packed union#}
<p>A {#syntax#}packed union{#endsyntax#} has well-defined in-memory layout and is eligible
to be in a {#link|packed struct#}.</p>
<p>All fields in a packed union must have the same {#link|@bitSizeOf#}.</p>
{#header_close#}
{#header_open|Anonymous Union Literals#}
@ -2602,13 +2586,6 @@ or
{#header_close#}
{#header_open|Switching on Errors#}
<p>
When switching on errors, some special cases are allowed to simplify generic programming patterns:
</p>
{#code|test_switch_on_errors.zig#}
{#header_close#}
{#header_open|Labeled switch#}
<p>
When a switch statement is labeled, it can be referenced from a
@ -2674,13 +2651,12 @@ or
{#code|test_inline_else.zig#}
<p>
When using an inline prong switching on an union an additional capture
can be used to obtain the union's enum tag value at comptime, even though
its payload might only be known at runtime.
When using an inline prong switching on an union an additional
capture can be used to obtain the union's enum tag value.
</p>
{#code|test_inline_switch_union_tag.zig#}
{#see_also|inline while|inline for|Tagged union#}
{#see_also|inline while|inline for#}
{#header_close#}
{#header_close#}
@ -3040,7 +3016,7 @@ or
{#syntax#}catch{#endsyntax#} after performing some logic, you
can combine {#syntax#}catch{#endsyntax#} with named {#link|Blocks#}:
</p>
{#code|handle_error_with_catch_block.zig#}
{#code|handle_error_with_catch_block.zig.zig#}
{#header_close#}
{#header_open|try#}
@ -3465,52 +3441,6 @@ void do_a_thing(struct Foo *foo) {
</p>
{#code|test_integer_widening.zig#}
{#header_close#}
{#header_open|Type Coercion: Int to Float#}
<p>
{#link|Integers#} coerce to {#link|Floats#} if every possible integer value can be stored in the float
without rounding (i.e. the integer's precision does not exceed the float's significand precision).
Larger integer types that cannot be safely coerced must be explicitly casted with {#link|@floatFromInt#}.
</p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th scope="col">Float Type</th>
<th scope="col">Largest Integer Types</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">{#syntax#}f16{#endsyntax#}</th>
<td>{#syntax#}i12{#endsyntax#} and {#syntax#}u11{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f32{#endsyntax#}</th>
<td>{#syntax#}i25{#endsyntax#} and {#syntax#}u24{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f64{#endsyntax#}</th>
<td>{#syntax#}i54{#endsyntax#} and {#syntax#}u53{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f80{#endsyntax#}</th>
<td>{#syntax#}i65{#endsyntax#} and {#syntax#}u64{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}f128{#endsyntax#}</th>
<td>{#syntax#}i114{#endsyntax#} and {#syntax#}u113{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}c_longdouble{#endsyntax#}</th>
<td>Varies by target</td>
</tr>
</tbody>
</table>
</div>
{#code|test_int_to_float_coercion.zig#}
{#code|test_failed_int_to_float_coercion.zig#}
{#header_close#}
{#header_open|Type Coercion: Float to Int#}
<p>
@ -3785,9 +3715,9 @@ void do_a_thing(struct Foo *foo) {
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}@FieldType(T, "a"){#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}@Int(x, y){#endsyntax#}</th>
<th scope="row">{#syntax#}@Type(x){#endsyntax#}</th>
<td>-</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.builtin.Signedness{#endsyntax#}, {#syntax#}y{#endsyntax#} is a {#syntax#}u16{#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.builtin.Type{#endsyntax#}</td>
</tr>
<tr>
<th scope="row">{#syntax#}@typeInfo(x){#endsyntax#}</th>
@ -3901,9 +3831,9 @@ void do_a_thing(struct Foo *foo) {
<td>{#syntax#}x{#endsyntax#} has no result location (typed initializers do not propagate result locations)</td>
</tr>
<tr>
<th scope="row">{#syntax#}@Int(x, y){#endsyntax#}</th>
<td>-</td>
<td>{#syntax#}x{#endsyntax#} and {#syntax#}y{#endsyntax#} do not have result locations</td>
<th scope="row">{#syntax#}@Type(x){#endsyntax#}</th>
<td>{#syntax#}ptr{#endsyntax#}</td>
<td>{#syntax#}x{#endsyntax#} has no result location</td>
</tr>
<tr>
<th scope="row">{#syntax#}@typeInfo(x){#endsyntax#}</th>
@ -4958,8 +4888,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_open|@fieldParentPtr#}
<pre>{#syntax#}@fieldParentPtr(comptime field_name: []const u8, field_ptr: *T) anytype{#endsyntax#}</pre>
<p>
Given a pointer to a struct or union field, returns a pointer to the struct or union containing that field.
The return type (pointer to the parent struct or union in question) is the inferred result type.
Given a pointer to a struct field, returns a pointer to the struct containing that field.
The return type (and struct in question) is the inferred result type.
</p>
<p>
If {#syntax#}field_ptr{#endsyntax#} does not point to the {#syntax#}field_name{#endsyntax#} field of an instance of
@ -5817,75 +5747,41 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</p>
{#header_close#}
{#header_open|@EnumLiteral#}
<pre>{#syntax#}@EnumLiteral() type{#endsyntax#}</pre>
<p>Returns the comptime-only "enum literal" type. This is the type of uncoerced {#link|Enum Literals#}. Values of this type can coerce to any {#link|enum#} with a matching field.</p>
{#header_open|@Type#}
<pre>{#syntax#}@Type(comptime info: std.builtin.Type) type{#endsyntax#}</pre>
<p>
This function is the inverse of {#link|@typeInfo#}. It reifies type information
into a {#syntax#}type{#endsyntax#}.
</p>
<p>
It is available for the following types:
</p>
<ul>
<li>{#syntax#}type{#endsyntax#}</li>
<li>{#syntax#}noreturn{#endsyntax#}</li>
<li>{#syntax#}void{#endsyntax#}</li>
<li>{#syntax#}bool{#endsyntax#}</li>
<li>{#link|Integers#} - The maximum bit count for an integer type is {#syntax#}65535{#endsyntax#}.</li>
<li>{#link|Floats#}</li>
<li>{#link|Pointers#}</li>
<li>{#syntax#}comptime_int{#endsyntax#}</li>
<li>{#syntax#}comptime_float{#endsyntax#}</li>
<li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li>
<li>{#syntax#}@TypeOf(null){#endsyntax#}</li>
<li>{#link|Arrays#}</li>
<li>{#link|Optionals#}</li>
<li>{#link|Error Set Type#}</li>
<li>{#link|Error Union Type#}</li>
<li>{#link|Vectors#}</li>
<li>{#link|opaque#}</li>
<li>{#syntax#}anyframe{#endsyntax#}</li>
<li>{#link|struct#}</li>
<li>{#link|enum#}</li>
<li>{#link|Enum Literals#}</li>
<li>{#link|union#}</li>
<li>{#link|Functions#}</li>
</ul>
{#header_close#}
{#header_open|@Int#}
<pre>{#syntax#}@Int(comptime signedness: std.builtin.Signedness, comptime bits: u16) type{#endsyntax#}</pre>
<p>Returns an integer type with the given signedness and bit width.</p>
<p>For instance, {#syntax#}@Int(.unsigned, 18){#endsyntax#} returns the type {#syntax#}u18{#endsyntax#}.</p>
{#header_close#}
{#header_open|@Tuple#}
<pre>{#syntax#}@Tuple(comptime field_types: []const type) type{#endsyntax#}</pre>
<p>Returns a {#link|tuple|Tuples#} type with the given field types.</p>
{#header_close#}
{#header_open|@Pointer#}
<pre>{#syntax#}@Pointer(
comptime size: std.builtin.Type.Pointer.Size,
comptime attrs: std.builtin.Type.Pointer.Attributes,
comptime Element: type,
comptime sentinel: ?Element,
) type{#endsyntax#}</pre>
<p>Returns a {#link|pointer|Pointers#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Fn#}
<pre>{#syntax#}@Fn(
comptime param_types: []const type,
comptime param_attrs: *const [param_types.len]std.builtin.Type.Fn.Param.Attributes,
comptime ReturnType: type,
comptime attrs: std.builtin.Type.Fn.Attributes,
) type{#endsyntax#}</pre>
<p>Returns a {#link|function|Functions#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Struct#}
<pre>{#syntax#}@Struct(
comptime layout: std.builtin.Type.ContainerLayout,
comptime BackingInt: ?type,
comptime field_names: []const []const u8,
comptime field_types: *const [field_names.len]type,
comptime field_attrs: *const [field_names.len]std.builtin.Type.StructField.Attributes,
) type{#endsyntax#}</pre>
<p>Returns a {#link|struct#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Union#}
<pre>{#syntax#}@Union(
comptime layout: std.builtin.Type.ContainerLayout,
/// Either the integer tag type, or the integer backing type, depending on `layout`.
comptime ArgType: ?type,
comptime field_names: []const []const u8,
comptime field_types: *const [field_names.len]type,
comptime field_attrs: *const [field_names.len]std.builtin.Type.UnionField.Attributes,
) type{#endsyntax#}</pre>
<p>Returns a {#link|union#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@Enum#}
<pre>{#syntax#}@Enum(
comptime TagInt: type,
comptime mode: std.builtin.Type.Enum.Mode,
comptime field_names: []const []const u8,
comptime field_values: *const [field_names.len]TagInt,
) type{#endsyntax#}</pre>
<p>Returns an {#link|enum#} type with the properties specified by the arguments.</p>
{#header_close#}
{#header_open|@typeInfo#}
<pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.Type{#endsyntax#}</pre>
<p>
@ -6381,6 +6277,10 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</li>
<li>Are you linking libc? In this case, {#syntax#}std.heap.c_allocator{#endsyntax#} is likely
the right choice, at least for your main allocator.</li>
<li>
Need to use the same allocator in multiple threads? Use one of your choice
wrapped around {#syntax#}std.heap.ThreadSafeAllocator{#endsyntax#}
</li>
<li>
Is the maximum number of bytes that you will need bounded by a number known at
{#link|comptime#}? In this case, use {#syntax#}std.heap.FixedBufferAllocator{#endsyntax#}.
@ -6390,7 +6290,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
cyclical pattern (such as a video game main loop, or a web server request handler),
such that it would make sense to free everything at once at the end?
In this case, it is recommended to follow this pattern:
{#code|cli_allocation.zig#}
{#code|cli_allocation.zig#}
When using this kind of allocator, there is no need to free anything manually. Everything
gets freed at once with the call to {#syntax#}arena.deinit(){#endsyntax#}.
@ -6413,18 +6313,14 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</li>
<li>
Finally, if none of the above apply, you need a general purpose allocator.
If you are in Debug mode, {#syntax#}std.heap.DebugAllocator{#endsyntax#} is available as a
function that takes a {#link|comptime#} {#link|struct#} of configuration options and returns a type.
Generally, you will set up exactly one in your main function, and
then pass it or sub-allocators around to various parts of your
Zig's general purpose allocator is available as a function that takes a {#link|comptime#}
{#link|struct#} of configuration options and returns a type.
Generally, you will set up one {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#} in
your main function, and then pass it or sub-allocators around to various parts of your
application.
</li>
<li>
If you are compiling in ReleaseFast mode, {#syntax#}std.heap.smp_allocator{#endsyntax#} is
a solid choice for a general purpose allocator.
</li>
<li>
You can also consider implementing an allocator.
You can also consider {#link|Implementing an Allocator#}.
</li>
</ol>
{#header_close#}
@ -6459,6 +6355,17 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<p>TODO: thread local variables</p>
{#header_close#}
{#header_open|Implementing an Allocator#}
<p>Zig programmers can implement their own allocators by fulfilling the Allocator interface.
In order to do this one must read carefully the documentation comments in std/mem.zig and
then supply a {#syntax#}allocFn{#endsyntax#} and a {#syntax#}resizeFn{#endsyntax#}.
</p>
<p>
There are many example allocators to look at for inspiration. Look at std/heap.zig and
{#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#}.
</p>
{#header_close#}
{#header_open|Heap Allocation Failure#}
<p>
Many programming languages choose to handle the possibility of heap allocation failure by
@ -7089,7 +6996,8 @@ WebAssembly.instantiate(typedArray, {
The result is 3{#end_shell_samp#}
{#header_close#}
{#header_open|WASI#}
<p>Zig standard library has first-class support for WebAssembly System Interface.</p>
<p>Zig's support for WebAssembly System Interface (WASI) is under active development.
Example of using the standard library and reading command line arguments:</p>
{#code|wasi_args.zig#}
{#shell_samp#}$ wasmtime wasi_args.wasm 123 hello
@ -7151,7 +7059,6 @@ coding style.
<li>Data</li>
<li>Context</li>
<li>Manager</li>
<li>State</li>
<li>utils, misc, or somebody's initials</li>
</ul>
<p>Everything is a value, all types are data, everything is context, all logic manages state.
@ -7177,31 +7084,6 @@ coding style.
cannot be any more specific without being incorrect.</p>
{#header_close#}
{#header_open|Refrain from Underscore Prefixes#}
<p>In some programming languages, it is common to prefix identifiers with
underscores {#syntax#}_like_this{#endsyntax#} to avoid keyword
collisions, name collisions, or indicate additional metadata associated with usage of the
identifier, such as: privacy, existence of complex data invariants, exclusion from
semantic versioning, or context-specific type reflection meaning.
</p>
<p>In Zig, there are no private fields, and this style guide recommends
against pretending otherwise. Instead, fields should be named carefully
based on their semantics and documentation should indicate how to use
fields without violating data invariants. If a field is not subject to
the same semantic versioning rules as everything else, the exception
should be noted in the {#link|Doc Comments#}.
</p>
<p>As for {#link|type reflection|@typeInfo#}, it is less error prone and
more maintainable to use the type system than to make field names
meaningful.</p>
<p>Regarding name collisions, an underscore is insufficient to explain
the difference between the two otherwise identical names. If there's no
danger in getting them mixed up, then this guide recommends more verbose
names at outer scopes and more abbreviated names at inner scopes.</p>
<p>Finally, keyword collisions are better avoided via
{#link|String Identifier Syntax#}.</p>
{#header_close#}
{#header_open|Whitespace#}
<ul>
<li>
@ -7225,12 +7107,10 @@ coding style.
</p>
<ul>
<li>
If {#syntax#}x{#endsyntax#} is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated
then {#syntax#}x{#endsyntax#} is considered to be a "namespace" and should be {#syntax#}snake_case{#endsyntax#}.
</li>
<li>
If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#} or {#syntax#}type{#endsyntax#} alias
then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#}
then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}, unless it
is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated,
in which case it is considered to be a "namespace" and uses {#syntax#}snake_case{#endsyntax#}.
</li>
<li>
If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is
@ -7269,7 +7149,8 @@ const namespace_name = @import("dir_name/file_name.zig");
const TypeName = @import("dir_name/TypeName.zig");
var global_var: i32 = undefined;
const const_name = 42;
const PrimitiveTypeAlias = f32;
const primitive_type_alias = f32;
const string_alias = []u8;
const StructName = struct {
field: i32,
@ -7923,11 +7804,11 @@ fn readU32Be() u32 {}
{#header_close#}
{#header_open|Grammar#}
{#syntax_block|peg|grammar.peg#}
Root <- skip ContainerMembers eof
{#syntax_block|peg|grammar.y#}
Root <- skip container_doc_comment? ContainerMembers eof
# *** Top level ***
ContainerMembers <- container_doc_comment? ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
ContainerMembers <- ContainerDeclaration* (ContainerField COMMA)* (ContainerField / ContainerDeclaration*)
ContainerDeclaration <- TestDecl / ComptimeDecl / doc_comment? KEYWORD_pub? Decl
@ -7956,6 +7837,7 @@ Statement
/ KEYWORD_errdefer Payload? BlockExprStatement
/ IfStatement
/ LabeledStatement
/ SwitchExpr
/ VarDeclExprStatement
ComptimeStatement
@ -7966,7 +7848,7 @@ IfStatement
<- IfPrefix BlockExpr ( KEYWORD_else Payload? Statement )?
/ IfPrefix AssignExpr ( SEMICOLON / KEYWORD_else Payload? Statement )
LabeledStatement <- BlockLabel? (Block / LoopStatement / SwitchExpr)
LabeledStatement <- BlockLabel? (Block / LoopStatement)
LoopStatement <- KEYWORD_inline? (ForStatement / WhileStatement)
@ -8020,7 +7902,7 @@ PrimaryExpr
/ KEYWORD_break BreakLabel? Expr?
/ KEYWORD_comptime Expr
/ KEYWORD_nosuspend Expr
/ KEYWORD_continue BreakLabel? Expr?
/ KEYWORD_continue BreakLabel?
/ KEYWORD_resume Expr
/ KEYWORD_return Expr?
/ BlockLabel? LoopExpr
@ -8070,6 +7952,7 @@ PrimaryTypeExpr
/ KEYWORD_anyframe
/ KEYWORD_unreachable
/ STRINGLITERAL
/ SwitchExpr
ContainerDecl <- (KEYWORD_extern / KEYWORD_packed)? ContainerDeclAuto
@ -8082,7 +7965,6 @@ IfTypeExpr <- IfPrefix TypeExpr (KEYWORD_else Payload? TypeExpr)?
LabeledTypeExpr
<- BlockLabel Block
/ BlockLabel? LoopTypeExpr
/ BlockLabel? SwitchExpr
LoopTypeExpr <- KEYWORD_inline? (ForTypeExpr / WhileTypeExpr)
@ -8252,7 +8134,7 @@ PtrTypeStart
ArrayTypeStart <- LBRACKET Expr (COLON Expr)? RBRACKET
# ContainerDecl specific
ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE
ContainerDeclAuto <- ContainerDeclType LBRACE container_doc_comment? ContainerMembers RBRACE
ContainerDeclType
<- KEYWORD_struct (LPAREN Expr RPAREN)?
@ -8272,6 +8154,8 @@ AsmOutputList <- (AsmOutputItem COMMA)* AsmOutputItem?
AsmInputList <- (AsmInputItem COMMA)* AsmInputItem?
StringList <- (STRINGLITERAL COMMA)* STRINGLITERAL?
ParamDeclList <- (ParamDecl COMMA)* ParamDecl?
ExprList <- (Expr COMMA)* Expr?
@ -8318,7 +8202,7 @@ oxC2_oxDF <- [\302-\337]
# [0xF1,0xF3] [0x80,0xBF] [0x80,0xBF] [0x80,0xBF]
# 0xF4 [0x80,0x8F] [0x80,0xBF] [0x80,0xBF]
multibyte_utf8 <-
mb_utf8_literal <-
oxF4 ox80_ox8F ox80_oxBF ox80_oxBF
/ oxF1_oxF3 ox80_oxBF ox80_oxBF ox80_oxBF
/ oxF0 ox90_0xBF ox80_oxBF ox80_oxBF
@ -8328,47 +8212,46 @@ multibyte_utf8 <-
/ oxE0 oxA0_oxBF ox80_oxBF
/ oxC2_oxDF ox80_oxBF
non_control_ascii <- [\040-\176]
ascii_char_not_nl_slash_squote <- [\000-\011\013-\046\050-\133\135-\177]
char_escape
<- "\\x" hex hex
/ "\\u{" hex+ "}"
/ "\\" [nr\\t'"]
char_char
<- multibyte_utf8
<- mb_utf8_literal
/ char_escape
/ ![\\'\n] non_control_ascii
/ ascii_char_not_nl_slash_squote
string_char
<- multibyte_utf8
/ char_escape
/ ![\\"\n] non_control_ascii
<- char_escape
/ [^\\"\n]
container_doc_comment <- ('//!' [^\n]* [ \n]* skip)+
doc_comment <- ('///' [^\n]* [ \n]* skip)+
line_comment <- '//' ![!/][^\n]* / '////' [^\n]*
line_string <- ('\\\\' [^\n]* [ \n]*)+
line_string <- ("\\\\" [^\n]* [ \n]*)+
skip <- ([ \n] / line_comment)*
CHAR_LITERAL <- ['] char_char ['] skip
CHAR_LITERAL <- "'" char_char "'" skip
FLOAT
<- '0x' hex_int '.' hex_int ([pP] [-+]? dec_int)? skip
/ dec_int '.' dec_int ([eE] [-+]? dec_int)? skip
/ '0x' hex_int [pP] [-+]? dec_int skip
<- "0x" hex_int "." hex_int ([pP] [-+]? dec_int)? skip
/ dec_int "." dec_int ([eE] [-+]? dec_int)? skip
/ "0x" hex_int [pP] [-+]? dec_int skip
/ dec_int [eE] [-+]? dec_int skip
INTEGER
<- '0b' bin_int skip
/ '0o' oct_int skip
/ '0x' hex_int skip
<- "0b" bin_int skip
/ "0o" oct_int skip
/ "0x" hex_int skip
/ dec_int skip
STRINGLITERALSINGLE <- ["] string_char* ["] skip
STRINGLITERALSINGLE <- "\"" string_char* "\"" skip
STRINGLITERAL
<- STRINGLITERALSINGLE
/ (line_string skip)+
IDENTIFIER
<- !keyword [A-Za-z_] [A-Za-z0-9_]* skip
/ '@' STRINGLITERALSINGLE
BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip
/ "@" STRINGLITERALSINGLE
BUILTINIDENTIFIER <- "@"[A-Za-z_][A-Za-z0-9_]* skip
AMPERSAND <- '&' ![=] skip

View file

@ -17,7 +17,7 @@ pub fn main() !void {
.maximum = 0.20,
};
const category = threshold.categorize(0.90);
std.log.info("category: {t}", .{category});
try std.fs.File.stdout().writeAll(@tagName(category));
}
const std = @import("std");

View file

@ -2,6 +2,9 @@ pub const CallModifier = enum {
/// Equivalent to function call syntax.
auto,
/// Equivalent to async keyword used with function call syntax.
async_kw,
/// Prevents tail call optimization. This guarantees that the return
/// address will point to the callsite, as opposed to the callsite's
/// callsite. If the call is otherwise required to be tail-called
@ -14,7 +17,7 @@ pub const CallModifier = enum {
/// Asserts that the function call will not suspend. This allows a
/// non-async function to call an async function.
no_suspend,
no_async,
/// Guarantees that the call will be generated with tail call optimization.
/// If this is not possible, a compile error is emitted instead.

View file

@ -4,7 +4,6 @@ const c = @cImport({
@cInclude("stdio.h");
});
pub fn main() void {
if (@import("builtin").os.tag == .netbsd) return; // https://github.com/Vexu/arocc/issues/960
_ = c.printf("hello\n");
}

View file

@ -15,8 +15,8 @@ pub fn main() void {
break :blk .{ min, max };
};
print("min = {}\n", .{ min });
print("max = {}\n", .{ max });
print("min = {}", .{ min });
print("max = {}", .{ max });
}
// exe=succeed

View file

@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 {
test "parse u64" {
const result = try parseU64("1234", 10);
try std.testing.expectEqual(1234, result);
try std.testing.expect(result == 1234);
}
// test

View file

@ -1,7 +1,7 @@
const std = @import("std");
pub fn main(init: std.process.Init) !void {
try std.Io.File.stdout().writeStreamingAll(init.io, "Hello, World!\n");
pub fn main() !void {
try std.fs.File.stdout().writeAll("Hello, World!\n");
}
// exe=succeed

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
test "attempt to swap array elements with array initializer" {
var arr: [2]u32 = .{ 1, 2 };
arr = .{ arr[1], arr[0] };
@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" {
// arr[0] = arr[1];
// arr[1] = arr[0];
// So this fails!
try expectEqual(2, arr[0]); // succeeds
try expectEqual(1, arr[1]); // fails
try expect(arr[0] == 2); // succeeds
try expect(arr[1] == 1); // fails
}
// test_error=

View file

@ -7,7 +7,7 @@ pub fn main() void {
const y = @shrExact(x, 2);
std.debug.print("value: {}\n", .{y});
if ((builtin.cpu.arch.isPowerPC() or builtin.cpu.arch.isRISCV() or builtin.cpu.arch.isLoongArch() or builtin.cpu.arch == .s390x) and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
if (builtin.cpu.arch.isRISCV() and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
}
// exe=fail

View file

@ -11,7 +11,7 @@ pub const std_options: std.Options = .{
fn myLogFn(
comptime level: std.log.Level,
comptime scope: @EnumLiteral(),
comptime scope: @Type(.enum_literal),
comptime format: []const u8,
args: anytype,
) void {

View file

@ -1,11 +1,11 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "no runtime side effects" {
var data: i32 = 0;
const T = @TypeOf(foo(i32, &data));
try comptime expectEqual(i32, T);
try expectEqual(0, data);
try comptime expect(T == i32);
try expect(data == 0);
}
fn foo(comptime T: type, ptr: *T) T {

View file

@ -1,13 +1,13 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const expectEqualStrings = std.testing.expectEqualStrings;
const expect = std.testing.expect;
test "using an allocator" {
var buffer: [100]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fba.allocator();
const result = try concat(allocator, "foo", "bar");
try expectEqualStrings("foobar", result);
try expect(std.mem.eql(u8, "foobar", result));
}
fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {

View file

@ -1,11 +1,11 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "allowzero" {
var zero: usize = 0; // var to make to runtime-known
_ = &zero; // suppress 'var is never mutated' error
const ptr: *allowzero i32 = @ptrFromInt(zero);
try expectEqual(0, @intFromPtr(ptr));
try expect(@intFromPtr(ptr) == 0);
}
// test

View file

@ -1,6 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
test "fully anonymous struct" {
try check(.{
@ -12,11 +11,11 @@ test "fully anonymous struct" {
}
fn check(args: anytype) !void {
try expectEqual(1234, args.int);
try expectEqual(12.34, args.float);
try expect(args.int == 1234);
try expect(args.float == 12.34);
try expect(args.b);
try expectEqual('h', args.s[0]);
try expectEqual('i', args.s[1]);
try expect(args.s[0] == 'h');
try expect(args.s[1] == 'i');
}
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
const Number = union {
int: i32,
@ -9,8 +9,8 @@ const Number = union {
test "anonymous union literal syntax" {
const i: Number = .{ .int = 42 };
const f = makeNumber();
try expectEqual(42, i.int);
try expectEqual(12.34, f.float);
try expect(i.int == 42);
try expect(f.float == 12.34);
}
fn makeNumber() Number {

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
const assert = @import("std").debug.assert;
const mem = @import("std").mem;
@ -29,7 +29,7 @@ test "iterate over an array" {
for (message) |byte| {
sum += byte;
}
try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum);
try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
}
// modifiable array
@ -39,8 +39,8 @@ test "modify an array" {
for (&some_integers, 0..) |*item, i| {
item.* = @intCast(i);
}
try expectEqual(10, some_integers[10]);
try expectEqual(99, some_integers[99]);
try expect(some_integers[10] == 10);
try expect(some_integers[99] == 99);
}
// array concatenation works if the values are known
@ -91,8 +91,8 @@ const Point = struct {
};
test "compile-time array initialization" {
try expectEqual(4, fancy_array[4].x);
try expectEqual(8, fancy_array[4].y);
try expect(fancy_array[4].x == 4);
try expect(fancy_array[4].y == 8);
}
// call a function to initialize an array
@ -104,9 +104,9 @@ fn makePoint(x: i32) Point {
};
}
test "array initialization with function calls" {
try expectEqual(3, more_points[4].x);
try expectEqual(6, more_points[4].y);
try expectEqual(10, more_points.len);
try expect(more_points[4].x == 3);
try expect(more_points[4].y == 6);
try expect(more_points.len == 10);
}
// test

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
const expectEqualSlices = @import("std").testing.expectEqualSlices;
test "basic slices" {
@ -12,14 +12,14 @@ test "basic slices" {
try expectEqualSlices(i32, slice, alt_slice);
try expectEqual([]i32, @TypeOf(slice));
try expectEqual(&array[0], &slice[0]);
try expectEqual(array.len, slice.len);
try expect(@TypeOf(slice) == []i32);
try expect(&slice[0] == &array[0]);
try expect(slice.len == array.len);
// If you slice with comptime-known start and end positions, the result is
// a pointer to an array, rather than a slice.
const array_ptr = array[0..array.len];
try expectEqual(*[array.len]i32, @TypeOf(array_ptr));
try expect(@TypeOf(array_ptr) == *[array.len]i32);
// You can perform a slice-by-length by slicing twice. This allows the compiler
// to perform some optimisations like recognising a comptime-known length when
@ -28,13 +28,13 @@ test "basic slices" {
_ = &runtime_start;
const length = 2;
const array_ptr_len = array[runtime_start..][0..length];
try expectEqual(*[length]i32, @TypeOf(array_ptr_len));
try expect(@TypeOf(array_ptr_len) == *[length]i32);
// Using the address-of operator on a slice gives a single-item pointer.
try expectEqual(*i32, @TypeOf(&slice[0]));
try expect(@TypeOf(&slice[0]) == *i32);
// Using the `ptr` field gives a many-item pointer.
try expectEqual([*]i32, @TypeOf(slice.ptr));
try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0]));
try expect(@TypeOf(slice.ptr) == [*]i32);
try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0]));
// Slices have array bounds checking. If you try to access something out
// of bounds, you'll get a safety check failure:
@ -47,8 +47,8 @@ test "basic slices" {
const empty1 = &[0]u8{};
// If the type is known you can use this short hand:
const empty2: []u8 = &.{};
try expectEqual(0, empty1.len);
try expectEqual(0, empty2.len);
try expect(empty1.len == 0);
try expect(empty2.len == 0);
// A zero-length initialization can always be used to create an empty slice, even if the slice is mutable.
// This is because the pointed-to data is zero bits long, so its immutability is irrelevant.

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
const BitField = packed struct {
a: u3,
@ -9,13 +9,13 @@ const BitField = packed struct {
test "offsets of non-byte-aligned fields" {
comptime {
try expectEqual(0, @bitOffsetOf(BitField, "a"));
try expectEqual(3, @bitOffsetOf(BitField, "b"));
try expectEqual(6, @bitOffsetOf(BitField, "c"));
try expect(@bitOffsetOf(BitField, "a") == 0);
try expect(@bitOffsetOf(BitField, "b") == 3);
try expect(@bitOffsetOf(BitField, "c") == 6);
try expectEqual(0, @offsetOf(BitField, "a"));
try expectEqual(0, @offsetOf(BitField, "b"));
try expectEqual(0, @offsetOf(BitField, "c"));
try expect(@offsetOf(BitField, "a") == 0);
try expect(@offsetOf(BitField, "b") == 0);
try expect(@offsetOf(BitField, "c") == 0);
}
}

View file

@ -1,7 +1,7 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
test "noinline function call" {
try expectEqual(12, @call(.auto, add, .{ 3, 9 }));
try expect(@call(.auto, add, .{ 3, 9 }) == 12);
}
fn add(a: i32, b: i32) i32 {

View file

@ -12,7 +12,7 @@ const AllocationError = error{
test "coerce subset to superset" {
const err = foo(AllocationError.OutOfMemory);
try std.testing.expectEqual(FileOpenError.OutOfMemory, err);
try std.testing.expect(err == FileOpenError.OutOfMemory);
}
fn foo(err: AllocationError) FileOpenError {

View file

@ -1,10 +1,10 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "coercing large integer type to smaller one when value is comptime-known to fit" {
const x: u64 = 255;
const y: u8 = x;
try expectEqual(255, y);
try expect(y == 255);
}
// test

View file

@ -1,12 +1,12 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "coerce to optionals wrapped in error union" {
const x: anyerror!?i32 = 1234;
const y: anyerror!?i32 = null;
try expectEqual(1234, (try x).?);
try expectEqual(null, (try y));
try expect((try x).? == 1234);
try expect((try y) == null);
}
// test

View file

@ -1,12 +1,12 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "coerce to optionals" {
const x: ?i32 = 1234;
const y: ?i32 = null;
try expectEqual(1234, x.?);
try expectEqual(null, y);
try expect(x.? == 1234);
try expect(y == null);
}
// test

View file

@ -1,7 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expectEqualStrings = std.testing.expectEqualStrings;
const expectEqualSlices = std.testing.expectEqualSlices;
const expect = std.testing.expect;
// You can assign constant pointers to arrays to a slice with
// const modifier on the element type. Useful in particular for
@ -9,48 +7,48 @@ const expectEqualSlices = std.testing.expectEqualSlices;
test "*const [N]T to []const T" {
const x1: []const u8 = "hello";
const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
try expectEqualStrings(x1, x2);
try expect(std.mem.eql(u8, x1, x2));
const y: []const f32 = &[2]f32{ 1.2, 3.4 };
try expectEqual(1.2, y[0]);
try expect(y[0] == 1.2);
}
// Likewise, it works when the destination type is an error union.
test "*const [N]T to E![]const T" {
const x1: anyerror![]const u8 = "hello";
const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
try expectEqualStrings(try x1, try x2);
try expect(std.mem.eql(u8, try x1, try x2));
const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
try expectEqual(1.2, (try y)[0]);
try expect((try y)[0] == 1.2);
}
// Likewise, it works when the destination type is an optional.
test "*const [N]T to ?[]const T" {
const x1: ?[]const u8 = "hello";
const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
try expectEqualStrings(x1.?, x2.?);
try expect(std.mem.eql(u8, x1.?, x2.?));
const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
try expectEqual(1.2, y.?[0]);
try expect(y.?[0] == 1.2);
}
// In this cast, the array length becomes the slice length.
test "*[N]T to []T" {
var buf: [5]u8 = "hello".*;
const x: []u8 = &buf;
try expectEqualStrings("hello", x);
try expect(std.mem.eql(u8, x, "hello"));
const buf2 = [2]f32{ 1.2, 3.4 };
const x2: []const f32 = &buf2;
try expectEqualSlices(f32, &[2]f32{ 1.2, 3.4 }, x2);
try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
}
// Single-item pointers to arrays can be coerced to many-item pointers.
test "*[N]T to [*]T" {
var buf: [5]u8 = "hello".*;
const x: [*]u8 = &buf;
try expectEqual('o', x[4]);
try expect(x[4] == 'o');
// x[5] would be an uncaught out of bounds pointer dereference!
}
@ -58,7 +56,7 @@ test "*[N]T to [*]T" {
test "*[N]T to ?[*]T" {
var buf: [5]u8 = "hello".*;
const x: ?[*]u8 = &buf;
try expectEqual('o', x.?[4]);
try expect(x.?[4] == 'o');
}
// Single-item pointers can be cast to len-1 single-item arrays.
@ -66,14 +64,14 @@ test "*T to *[1]T" {
var x: i32 = 1234;
const y: *[1]i32 = &x;
const z: [*]i32 = y;
try expectEqual(1234, z[0]);
try expect(z[0] == 1234);
}
// Sentinel-terminated slices can be coerced into sentinel-terminated pointers
test "[:x]T to [*:x]T" {
const buf: [:0]const u8 = "hello";
const buf2: [*:0]const u8 = buf;
try expectEqual('o', buf2[4]);
try expect(buf2[4] == 'o');
}
// test

View file

@ -1,11 +1,11 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "coercion to error unions" {
const x: anyerror!i32 = 1234;
const y: anyerror!i32 = error.Failure;
try expectEqual(1234, (try x));
try expect((try x) == 1234);
try std.testing.expectError(error.Failure, y);
}

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
const Tuple = struct { u8, u8 };
test "coercion from homogeneous tuple to array" {

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
const E = enum {
one,
@ -28,22 +28,22 @@ const U2 = union(enum) {
test "coercion between unions and enums" {
const u = U{ .two = 12.34 };
const e: E = u; // coerce union to enum
try expectEqual(E.two, e);
try expect(e == E.two);
const three = E.three;
const u_2: U = three; // coerce enum to union
try expectEqual(E.three, u_2);
try expect(u_2 == E.three);
const u_3: U = .three; // coerce enum literal to union
try expectEqual(E.three, u_3);
try expect(u_3 == E.three);
const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
try expectEqual(1, u_4.tag());
try expect(u_4.tag() == 1);
// The following example is invalid.
// error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
// error: coercion from enum '@TypeOf(.enum_literal)' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
//var u_5: U2 = .b;
//try expectEqual(2, u_5.tag());
//try expect(u_5.tag() == 2);
}
// test

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
const CmdFn = struct {
name: []const u8,
@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
}
test "perform fn" {
try expectEqual(6, performFn('t', 1));
try expectEqual(1, performFn('o', 0));
try expectEqual(99, performFn('w', 99));
try expect(performFn('t', 1) == 6);
try expect(performFn('o', 0) == 1);
try expect(performFn('w', 99) == 99);
}
// test

View file

@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T {
}
}
test "try to compare bools" {
try @import("std").testing.expectEqual(true, max(bool, false, true));
try @import("std").testing.expect(max(bool, false, true) == true);
}
// test

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
test "comptime @ptrFromInt" {
comptime {
@ -6,8 +6,8 @@ test "comptime @ptrFromInt" {
// ptr is never dereferenced.
const ptr: *i32 = @ptrFromInt(0xdeadbee0);
const addr = @intFromPtr(ptr);
try expectEqual(usize, @TypeOf(addr));
try expectEqual(0xdeadbee0, addr);
try expect(@TypeOf(addr) == usize);
try expect(addr == 0xdeadbee0);
}
}

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
test "comptime pointers" {
comptime {
@ -6,7 +6,7 @@ test "comptime pointers" {
const ptr = &x;
ptr.* += 1;
x += 1;
try expectEqual(3, ptr.*);
try expect(ptr.* == 3);
}
}

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "comptime vars" {
var x: i32 = 1;
@ -8,8 +8,8 @@ test "comptime vars" {
x += 1;
y += 1;
try expectEqual(2, x);
try expectEqual(2, y);
try expect(x == 2);
try expect(y == 2);
if (y != 2) {
// This compile error never triggers because y is a comptime variable,

View file

@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 {
}
test "variable values" {
try @import("std").testing.expectEqual(1060, sum_of_first_25_primes);
try @import("std").testing.expect(sum_of_first_25_primes == 1060);
}
// test

View file

@ -2,8 +2,8 @@ var y: i32 = add(10, x);
const x: i32 = add(12, 34);
test "container level variables" {
try expectEqual(46, x);
try expectEqual(56, y);
try expect(x == 46);
try expect(y == 56);
}
fn add(a: i32, b: i32) i32 {
@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 {
}
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
const print = std.debug.print;
fn deferExample() !usize {
@ -9,14 +9,14 @@ fn deferExample() !usize {
defer a = 2;
a = 1;
}
try expectEqual(2, a);
try expect(a == 2);
a = 5;
return a;
}
test "defer basics" {
try expectEqual(5, (try deferExample()));
try expect((try deferExample()) == 5);
}
// test

View file

@ -22,10 +22,6 @@ test "defining a variadic function" {
// https://github.com/ziglang/zig/issues/16961
return error.SkipZigTest;
}
if (builtin.cpu.arch == .s390x) {
// https://github.com/ziglang/zig/issues/21350#issuecomment-3543006475
return error.SkipZigTest;
}
try std.testing.expectEqual(@as(c_int, 0), add(0));
try std.testing.expectEqual(@as(c_int, 1), add(1, @as(c_int, 1)));

View file

@ -1,12 +1,12 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test {
const a = {};
const b = void{};
try expectEqual(void, @TypeOf(a));
try expectEqual(void, @TypeOf(b));
try expectEqual(a, b);
try expect(@TypeOf(a) == void);
try expect(@TypeOf(b) == void);
try expect(a == b);
}
// test

View file

@ -1,6 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const Color = enum {
auto,
@ -11,7 +10,7 @@ const Color = enum {
test "enum literals" {
const color1: Color = .auto;
const color2 = Color.auto;
try expectEqual(color1, color2);
try expect(color1 == color2);
}
test "switch using enum literals" {

View file

@ -1,6 +1,4 @@
const expect = @import("std").testing.expect;
const expectEqual = @import("std").testing.expectEqual;
const expectEqualStrings = @import("std").testing.expectEqualStrings;
const mem = @import("std").mem;
// Declare an enum.
@ -22,9 +20,9 @@ const Value = enum(u2) {
// Now you can cast between u2 and Value.
// The ordinal value starts from 0, counting up by 1 from the previous member.
test "enum ordinal value" {
try expectEqual(0, @intFromEnum(Value.zero));
try expectEqual(1, @intFromEnum(Value.one));
try expectEqual(2, @intFromEnum(Value.two));
try expect(@intFromEnum(Value.zero) == 0);
try expect(@intFromEnum(Value.one) == 1);
try expect(@intFromEnum(Value.two) == 2);
}
// You can override the ordinal value for an enum.
@ -34,9 +32,9 @@ const Value2 = enum(u32) {
million = 1000000,
};
test "set enum ordinal value" {
try expectEqual(100, @intFromEnum(Value2.hundred));
try expectEqual(1000, @intFromEnum(Value2.thousand));
try expectEqual(1000000, @intFromEnum(Value2.million));
try expect(@intFromEnum(Value2.hundred) == 100);
try expect(@intFromEnum(Value2.thousand) == 1000);
try expect(@intFromEnum(Value2.million) == 1000000);
}
// You can also override only some values.
@ -48,11 +46,11 @@ const Value3 = enum(u4) {
e,
};
test "enum implicit ordinal values and overridden values" {
try expectEqual(0, @intFromEnum(Value3.a));
try expectEqual(8, @intFromEnum(Value3.b));
try expectEqual(9, @intFromEnum(Value3.c));
try expectEqual(4, @intFromEnum(Value3.d));
try expectEqual(5, @intFromEnum(Value3.e));
try expect(@intFromEnum(Value3.a) == 0);
try expect(@intFromEnum(Value3.b) == 8);
try expect(@intFromEnum(Value3.c) == 9);
try expect(@intFromEnum(Value3.d) == 4);
try expect(@intFromEnum(Value3.e) == 5);
}
// Enums can have methods, the same as structs and unions.
@ -86,7 +84,7 @@ test "enum switch" {
Foo.number => "this is a number",
Foo.none => "this is a none",
};
try expectEqualStrings(what_is_it, "this is a number");
try expect(mem.eql(u8, what_is_it, "this is a number"));
}
// @typeInfo can be used to access the integer tag type of an enum.
@ -97,18 +95,18 @@ const Small = enum {
four,
};
test "std.meta.Tag" {
try expectEqual(u2, @typeInfo(Small).@"enum".tag_type);
try expect(@typeInfo(Small).@"enum".tag_type == u2);
}
// @typeInfo tells us the field count and the fields names:
test "@typeInfo" {
try expectEqual(4, @typeInfo(Small).@"enum".fields.len);
try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");
try expect(@typeInfo(Small).@"enum".fields.len == 4);
try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));
}
// @tagName gives a [:0]const u8 representation of an enum value:
test "@tagName" {
try expectEqualStrings(@tagName(Small.three), "three");
try expect(mem.eql(u8, @tagName(Small.three), "three"));
}
// test

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
test "error union" {
var foo: anyerror!i32 = undefined;
@ -10,10 +10,10 @@ test "error union" {
foo = error.SomeError;
// Use compile-time reflection to access the payload type of an error union:
try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload);
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
// Use compile-time reflection to access the error set type of an error union:
try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set);
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
}
// test

View file

@ -1,8 +0,0 @@
test "integer type is too large for implicit cast to float" {
var int: u25 = 123;
_ = &int;
const float: f32 = int;
_ = float;
}
// test_error=

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
fn fibonacci(index: u32) u32 {
//if (index < 2) return index;
@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 {
}
test "fibonacci" {
try comptime expectEqual(13, fibonacci(7));
try comptime expect(fibonacci(7) == 13);
}
// test_error=overflow of integer type

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
fn fibonacci(index: u32) u32 {
if (index < 2) return index;
@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 {
test "fibonacci" {
// test fibonacci at run-time
try expectEqual(13, fibonacci(7));
try expect(fibonacci(7) == 13);
// test fibonacci at compile-time
try comptime expectEqual(13, fibonacci(7));
try comptime expect(fibonacci(7) == 13);
}
// test

View file

@ -1,5 +1,4 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const Point = struct {
x: u32,
@ -9,20 +8,23 @@ const Point = struct {
};
test "field access by string" {
const expect = std.testing.expect;
var p = Point{ .x = 0, .y = 0 };
@field(p, "x") = 4;
@field(p, "y") = @field(p, "x") + 1;
try expectEqual(4, @field(p, "x"));
try expectEqual(5, @field(p, "y"));
try expect(@field(p, "x") == 4);
try expect(@field(p, "y") == 5);
}
test "decl access by string" {
try expectEqual(1, @field(Point, "z"));
const expect = std.testing.expect;
try expect(@field(Point, "z") == 1);
@field(Point, "z") = 2;
try expectEqual(2, @field(Point, "z"));
try expect(@field(Point, "z") == 2);
}
// test

View file

@ -3,8 +3,8 @@ const math = std.math;
const testing = std.testing;
test "fn reflection" {
try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?);
try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
}

View file

@ -1,15 +1,15 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
fn addFortyTwo(x: anytype) @TypeOf(x) {
return x + 42;
}
test "fn type inference" {
try expectEqual(43, addFortyTwo(1));
try expectEqual(comptime_int, @TypeOf(addFortyTwo(1)));
try expect(addFortyTwo(1) == 43);
try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
const y: i64 = 2;
try expectEqual(44, addFortyTwo(y));
try expectEqual(i64, @TypeOf(addFortyTwo(y)));
try expect(addFortyTwo(y) == 44);
try expect(@TypeOf(addFortyTwo(y)) == i64);
}
// test

View file

@ -1,4 +1,4 @@
const expectEqual = @import("std").testing.expectEqual;
const expect = @import("std").testing.expect;
test "for basics" {
const items = [_]i32{ 4, 5, 3, 4, 0 };
@ -12,22 +12,22 @@ test "for basics" {
}
sum += value;
}
try expectEqual(16, sum);
try expect(sum == 16);
// To iterate over a portion of a slice, reslice.
for (items[0..1]) |value| {
sum += value;
}
try expectEqual(20, sum);
try expect(sum == 20);
// To access the index of iteration, specify a second condition as well
// as a second capture value.
var sum2: i32 = 0;
for (items, 0..) |_, i| {
try expectEqual(usize, @TypeOf(i));
try expect(@TypeOf(i) == usize);
sum2 += @as(i32, @intCast(i));
}
try expectEqual(10, sum2);
try expect(sum2 == 10);
// To iterate over consecutive integers, use the range syntax.
// Unbounded range is always a compile error.
@ -35,7 +35,7 @@ test "for basics" {
for (0..5) |i| {
sum3 += i;
}
try expectEqual(10, sum3);
try expect(sum3 == 10);
}
test "multi object for" {
@ -50,7 +50,7 @@ test "multi object for" {
count += i + j;
}
try expectEqual(21, count);
try expect(count == 21);
}
test "for reference" {
@ -62,9 +62,9 @@ test "for reference" {
value.* += 1;
}
try expectEqual(4, items[0]);
try expectEqual(5, items[1]);
try expectEqual(3, items[2]);
try expect(items[0] == 4);
try expect(items[1] == 5);
try expect(items[2] == 3);
}
test "for else" {
@ -79,10 +79,10 @@ test "for else" {
sum += value.?;
}
} else blk: {
try expectEqual(12, sum);
try expect(sum == 12);
break :blk sum;
};
try expectEqual(12, result);
try expect(result == 12);
}
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
test "nested break" {
var count: usize = 0;
@ -9,7 +9,7 @@ test "nested break" {
break :outer;
}
}
try expectEqual(1, count);
try expect(count == 1);
}
test "nested continue" {
@ -21,7 +21,7 @@ test "nested continue" {
}
}
try expectEqual(8, count);
try expect(count == 8);
}
// test

View file

@ -1,7 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");
const native_arch = builtin.cpu.arch;
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
// Functions are declared like this
fn add(a: i8, b: i8) i8 {
@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 {
}
test "function" {
try expectEqual(11, doOp(add, 5, 6));
try expectEqual(-1, doOp(sub2, 5, 6));
try expect(doOp(add, 5, 6) == 11);
try expect(doOp(sub2, 5, 6) == -1);
}
// test

View file

@ -1,5 +1,5 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
comptime {
asm (
@ -14,7 +14,7 @@ comptime {
extern fn my_func(a: i32, b: i32) i32;
test "global assembly" {
try expectEqual(46, my_func(12, 34));
try expect(my_func(12, 34) == 46);
}
// test

Some files were not shown because too many files have changed in this diff Show more