Skip to content

Commit

Permalink
Merge branch 'master' into type-check-more-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
g-w1 authored Dec 23, 2020
2 parents 8a9b15a + 55b998c commit 50572ef
Show file tree
Hide file tree
Showing 797 changed files with 88,150 additions and 5,519 deletions.
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 7)
set(ZIG_VERSION_PATCH 0)
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 "")
Expand Down Expand Up @@ -63,9 +63,6 @@ endif()

if(ZIG_STATIC)
set(ZIG_STATIC_LLVM "on")
set(ZIG_LINK_MODE "Static")
else()
set(ZIG_LINK_MODE "Dynamic")
endif()

string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
Expand All @@ -78,6 +75,7 @@ set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for"
set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries for")
set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
set(ZIG_PREFER_LLVM_CONFIG off CACHE BOOL "(when cross compiling) use llvm-config to find target llvm dependencies if needed")
set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread")

find_package(llvm)
find_package(clang)
Expand Down Expand Up @@ -364,6 +362,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/io/buffered_writer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/change_detection_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/counting_writer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/counting_reader.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/find_byte_out_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/fixed_buffer_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/reader.zig"
Expand Down Expand Up @@ -413,7 +412,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/win32error.zig"
"${CMAKE_SOURCE_DIR}/lib/std/pdb.zig"
"${CMAKE_SOURCE_DIR}/lib/std/process.zig"
"${CMAKE_SOURCE_DIR}/lib/std/progress.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Progress.zig"
"${CMAKE_SOURCE_DIR}/lib/std/rand.zig"
"${CMAKE_SOURCE_DIR}/lib/std/reset_event.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sort.zig"
Expand Down Expand Up @@ -513,10 +512,13 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/Cache.zig"
"${CMAKE_SOURCE_DIR}/src/Compilation.zig"
"${CMAKE_SOURCE_DIR}/src/DepTokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Event.zig"
"${CMAKE_SOURCE_DIR}/src/Module.zig"
"${CMAKE_SOURCE_DIR}/src/Package.zig"
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/astgen.zig"
"${CMAKE_SOURCE_DIR}/src/clang.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options.zig"
Expand Down Expand Up @@ -594,6 +596,12 @@ else(MSVC)
set(EXE_CFLAGS "-std=c++14")
endif(MSVC)

if(ZIG_STATIC)
set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Static")
else()
set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Dynamic")
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(MSVC)
set(EXE_CFLAGS "${EXE_CFLAGS} /w")
Expand Down Expand Up @@ -710,6 +718,11 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
else()
set(ZIG1_RELEASE_ARG -OReleaseFast --strip)
endif()
if(ZIG_SINGLE_THREADED)
set(ZIG1_SINGLE_THREADED_ARG "--single-threaded")
else()
set(ZIG1_SINGLE_THREADED_ARG "")
endif()

set(BUILD_ZIG1_ARGS
"src/stage1.zig"
Expand All @@ -719,6 +732,7 @@ set(BUILD_ZIG1_ARGS
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-femit-bin=${ZIG1_OBJECT}"
"${ZIG1_RELEASE_ARG}"
"${ZIG1_SINGLE_THREADED_ARG}"
-lc
--pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
--pkg-end
Expand Down
26 changes: 19 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ personal project. Here are some great examples:

* [Oxid](https://github.com/dbandstra/oxid) - arcade style game
* [TM35-Metronome](https://github.com/TM35-Metronome) - tools for modifying and randomizing Pokémon games
* [trOS](https://github.com/sjdh02/trOS) - tiny aarch64 baremetal OS thingy
* [River](https://github.com/ifreund/river/) - a dynamic tiling wayland compositor

More examples can be found on the
[Community Projects Wiki](https://github.com/ziglang/zig/wiki/Community-Projects).

Without fail, these projects lead to discovering bugs and helping flesh out use
cases, which lead to further design iterations of Zig. Importantly, each issue
Expand Down Expand Up @@ -51,7 +54,8 @@ knowledge of Zig internals.**

### Editing Source Code

First, build the Stage 1 compiler as described in [Building from Source](README.md#Building-from-Source).
First, build the Stage 1 compiler as described in
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source).

Zig locates lib files relative to executable path by searching up the
filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`.
Expand Down Expand Up @@ -129,6 +133,14 @@ 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
`-Denable-wasmtime` 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

Please read the [Editing Source Code](#editing-source-code) section as a
Expand All @@ -152,7 +164,7 @@ The relevant tests for this feature are:
same, and that the program exits cleanly. This kind of test coverage is preferred, when
possible, because it makes sure that the resulting Zig code is actually viable.

* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
have the correct values. Macros have to be tested separately since they are expanded by
Clang in `run_translated_c` tests.
Expand All @@ -173,21 +185,21 @@ repo, we maintain a C API on top of Clang's C++ API:
Clang's C++ API changes. This one file necessarily does include Clang's C++ headers, which
makes it the slowest-to-compile source file in all of Zig's codebase.

* `src-self-hosted/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
* `src/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
maintained list of types and functions that are ABI-compatible with the Clang C API we
maintain. In theory this could be generated by running translate-c on `src/zig_clang.h`,
but that would introduce a dependency cycle, since we are using this file to implement
translate-c.

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

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

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

2. Edit `src-self-hosted/translate_c.zig` to improve the behavior.
2. Edit `src/translate_c.zig` to improve the behavior.

3. Run the relevant tests: `./zig build test-run-translated-c test-translate-c`
96 changes: 5 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,98 +14,12 @@ A general-purpose programming language and toolchain for maintaining
* [Frequently Asked Questions](https://github.com/ziglang/zig/wiki/FAQ)
* [Community Projects](https://github.com/ziglang/zig/wiki/Community-Projects)

## Building from Source
## Installation

[![Build Status](https://dev.azure.com/ziglang/zig/_apis/build/status/ziglang.zig?branchName=master)](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)

Note that you can
[download a binary of the master branch](https://ziglang.org/download/#release-master) or
[install Zig from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager).

### Stage 1: Build Zig from C++ Source Code

This step must be repeated when you make changes to any of the C++ source code.

#### Dependencies

##### POSIX

* cmake >= 2.8.5
* gcc >= 5.0.0 or clang >= 3.6.0
* LLVM, Clang, LLD development libraries == 11.x, compiled with the same gcc or clang version above
- Use the system package manager, or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix).

##### Windows

* cmake >= 3.15.3
* Microsoft Visual Studio. Supported versions:
- 2017 (version 15.8)
- 2019 (version 16)
* LLVM, Clang, LLD development libraries == 11.x
- Use the [pre-built binaries](https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows) or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#windows).

#### Instructions

##### POSIX

```
mkdir build
cd build
cmake ..
make install
```

Need help? [Troubleshooting Build Issues](https://github.com/ziglang/zig/wiki/Troubleshooting-Build-Issues)

##### MacOS

```
brew install cmake llvm
brew outdated llvm || brew upgrade llvm
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
make install
```

##### Windows

See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows

### Stage 2: Build Self-Hosted Zig from Zig Source Code

Now we use the stage1 binary:

```
zig build --prefix $(pwd)/stage2 -Denable-llvm
```

This produces `stage2/bin/zig` which can be used for testing and development.
Once it is feature complete, it will be used to build stage 3 - the final compiler
binary.

### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler

*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
not yet supported.*

Once the self-hosted compiler can build itself, this will be the actual
compiler binary that we will install to the system. Until then, users should
use stage 1.

#### Debug / Development Build

```
stage2/bin/zig build
```

This produces `zig-cache/bin/zig`.

#### Release / Install Build

```
stage2/bin/zig build install -Drelease
```
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [build from source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)

## License

Expand Down
Loading

0 comments on commit 50572ef

Please sign in to comment.