@bitCast of packed struct containing pointer temporarily.
TODO: Figure out what to do about this. Context: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179 After changing our emit strategy for packed structs to just write to memory: test-behavior └─ run test behavior-x86_64-linux.6.5...6.5-gnu.2.38-x86_64-ReleaseSmall-libc └─ zig test ReleaseSmall native failure error: thread 44346 panic: attempt to unwrap error: ReinterpretDeclRef /home/alexrp/Source/zig/src/Value.zig:571:42: 0x1f33514 in writeToPackedMemory (zig) if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef; ^ /home/alexrp/Source/zig/src/Value.zig:548:17: 0x1f32f45 in writeToPackedMemory (zig) try field_val.writeToPackedMemory(field_ty, pt, buffer, bit_offset + bits); ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:3706:89: 0x1ca2366 in lowerValueToInt (zig) val.writeToPackedMemory(ty, pt, std.mem.sliceAsBytes(limbs)[0..bytes], 0) catch unreachable; ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:4083:49: 0x1a33800 in lowerValue (zig) return o.lowerValueToInt(llvm_int_ty, arg_val); ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:4798:42: 0x2ec4e6a in resolveValue (zig) const llvm_val = try o.lowerValue(val.toIntern()); ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:4789:47: 0x2ec4bd3 in resolveInst (zig) const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.object.pt)).?); ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:8996:49: 0x2f022e9 in airStore (zig) const src_operand = try self.resolveInst(bin_op.rhs); ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:4967:53: 0x29f7260 in genBody (zig) .store => try self.airStore(inst, false), ^ /home/alexrp/Source/zig/src/codegen/llvm.zig:1682:19: 0x29f147c in updateFunc (zig) fg.genBody(air.getMainBody()) catch |err| switch (err) { ^ /home/alexrp/Source/zig/src/link/Elf.zig:2916:70: 0x2eb0f15 in updateFunc (zig) if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(pt, func_index, air, liveness); ^ /home/alexrp/Source/zig/src/link.zig:426:82: 0x29fbef5 in updateFunc (zig) return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(pt, func_index, air, liveness); ^ /home/alexrp/Source/zig/src/Zcu/PerThread.zig:876:22: 0x25f3d9e in linkerUpdateFunc (zig) lf.updateFunc(pt, func_index, air, liveness) catch |err| switch (err) { ^ /home/alexrp/Source/zig/src/Compilation.zig:3975:36: 0x21768fe in processOneCodegenJob (zig) try pt.linkerUpdateFunc(func.func, func.air); ^ /home/alexrp/Source/zig/src/Compilation.zig:3928:36: 0x2176541 in queueCodegenJob (zig) return processOneCodegenJob(tid, comp, codegen_job); ^ /home/alexrp/Source/zig/src/Compilation.zig:3682:37: 0x1e9d37f in processOneJob (zig) try comp.queueCodegenJob(tid, .{ .func = .{ ^ /home/alexrp/Source/zig/src/Compilation.zig:3638:30: 0x1c1f6c1 in performAllTheWorkInner (zig) try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node); ^ /home/alexrp/Source/zig/src/Compilation.zig:3508:36: 0x1ab6e10 in performAllTheWork (zig) try comp.performAllTheWorkInner(main_progress_node); ^ /home/alexrp/Source/zig/src/Compilation.zig:2269:31: 0x1ab25b9 in update (zig) try comp.performAllTheWork(main_progress_node); ^ /home/alexrp/Source/zig/src/main.zig:4156:32: 0x1b01351 in serve (zig) try comp.update(main_progress_node); ^ /home/alexrp/Source/zig/src/main.zig:3453:22: 0x1b20d7c in buildOutputType (zig) try serve( ^ /home/alexrp/Source/zig/src/main.zig:267:31: 0x1969c54 in mainArgs (zig) return buildOutputType(gpa, arena, args, .zig_test); ^ /home/alexrp/Source/zig/src/main.zig:199:20: 0x19669c5 in main (zig) return mainArgs(gpa, arena, args); ^ /home/alexrp/Source/zig/lib/std/start.zig:614:37: 0x19664ee in main (zig) const result = root.main() catch |err| { ^ ../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7a453da2814f in __libc_start_call_main (../sysdeps/x86/libc-start.c) ../csu/libc-start.c:360:3: 0x7a453da28208 in __libc_start_main_impl (../sysdeps/x86/libc-start.c) ???:?:?: 0x1966134 in ??? (???) ???:?:?: 0x0 in ??? (???)
A general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Documentation
If you are looking at this README file in a source tree, please refer to the Release Notes, Language Reference, or Standard Library Documentation corresponding to the version of Zig that you are using by following the appropriate link on the download page.
Otherwise, you're looking at a release of Zig, so you can find the language
reference at doc/langref.html, and the standard library documentation by
running zig std, which will open a browser tab.
Installation
A Zig installation is composed of two things:
- The Zig executable
- The lib/ directory
At runtime, the executable searches up the file system for the lib/ directory, relative to itself:
- lib/
- lib/zig/
- ../lib/
- ../lib/zig/
- (and so on)
In other words, you can unpack a release of Zig anywhere, and then begin
using it immediately. There is no need to install it globally, although this
mechanism supports that use case too (i.e. /usr/bin/zig and /usr/lib/zig/).
Building from Source
Ensure you have the required dependencies:
- CMake >= 3.15
- System C/C++ Toolchain
- LLVM, Clang, LLD development libraries == 18.x
Then it is the standard CMake build process:
mkdir build
cd build
cmake ..
make install
For more options, tips, and troubleshooting, please see the Building Zig From Source page on the wiki.
Building from Source without LLVM
In this case, the only system dependency is a C compiler.
cc -o bootstrap bootstrap.c
./bootstrap
This produces a zig2 executable in the current working directory. This is a
"stage2" build of the compiler,
without LLVM extensions, and is
therefore lacking these features:
- Release mode optimizations
- aarch64 machine code backend
- @cImport
- zig translate-c
- Ability to compile assembly files
- Some ELF linking features
- Most COFF/PE linking features
- Some WebAssembly linking features
- Ability to create import libs from def files
- Ability to create static archives from object files
- Ability to compile C, C++, Objective-C, and Objective-C++ files
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.
Contributing
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.
One of the best ways you can contribute to Zig is to start using it for an open-source personal project.
This leads to discovering bugs and helps flesh out use cases, which lead to further design iterations of Zig. Importantly, each issue found this way comes with real world motivations, making it straightforward to explain the reasoning behind proposals and feature requests.
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 exists to help you find issues that are limited in scope and/or knowledge of Zig internals.
Please note that issues labeled Proposal but do not also have the Accepted label are still under consideration, and efforts to implement such a proposal have a high risk of being wasted. If you are interested in a proposal which is still under consideration, please express your interest in the issue tracker, providing extra insights and considerations that others have not yet expressed. The most highly regarded argument in such a discussion is a real world use case.
For more tips, please see the Contributing page on the wiki.
Community
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 wiki page for a public listing of social spaces.