Skip to content

Commit b553b7a

Browse files
committed
Merge branch 'master' into self-hosted-parser
2 parents 0ba85ea + ee3e279 commit b553b7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3104
-1106
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
sudo: required
2+
services:
3+
- docker
14
os:
25
- linux
36
- osx
47
dist: trusty
58
osx_image: xcode8.3
6-
sudo: required
79
language: cpp
810
before_install:
911
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ci/travis_linux_before_install; fi

CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ if(NOT CMAKE_BUILD_TYPE)
55
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
66
endif()
77

8+
if(NOT CMAKE_INSTALL_PREFIX)
9+
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE STRING
10+
"Directory to install zig to" FORCE)
11+
endif()
12+
813
project(zig C CXX)
914
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
1015

@@ -30,11 +35,6 @@ if(GIT_EXE)
3035
endif()
3136
message("Configuring zig version ${ZIG_VERSION}")
3237

33-
set(ZIG_LIBC_LIB_DIR "" CACHE STRING "Default native target libc directory where crt1.o can be found")
34-
set(ZIG_LIBC_STATIC_LIB_DIR "" CACHE STRING "Default native target libc directory where crtbeginT.o can be found")
35-
set(ZIG_LIBC_INCLUDE_DIR "/usr/include" CACHE STRING "Default native target libc include directory")
36-
set(ZIG_DYNAMIC_LINKER "" CACHE STRING "Override dynamic linker for native target")
37-
set(ZIG_EACH_LIB_RPATH off CACHE BOOL "Add each dynamic library to rpath for native target")
3838
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
3939

4040
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
@@ -430,18 +430,24 @@ set(ZIG_STD_FILES
430430
"crypto/sha2.zig"
431431
"crypto/sha3.zig"
432432
"crypto/blake2.zig"
433+
"crypto/hmac.zig"
433434
"cstr.zig"
434435
"debug/failing_allocator.zig"
435436
"debug/index.zig"
436437
"dwarf.zig"
437438
"elf.zig"
438439
"empty.zig"
439-
"endian.zig"
440+
"event.zig"
440441
"fmt/errol/enum3.zig"
441442
"fmt/errol/index.zig"
442443
"fmt/errol/lookup.zig"
443444
"fmt/index.zig"
444445
"hash_map.zig"
446+
"hash/index.zig"
447+
"hash/adler.zig"
448+
"hash/crc.zig"
449+
"hash/fnv.zig"
450+
"hash/siphash.zig"
445451
"heap.zig"
446452
"index.zig"
447453
"io.zig"
@@ -502,7 +508,6 @@ set(ZIG_STD_FILES
502508
"os/get_user_id.zig"
503509
"os/index.zig"
504510
"os/linux/errno.zig"
505-
"os/linux/i386.zig"
506511
"os/linux/index.zig"
507512
"os/linux/x86_64.zig"
508513
"os/path.zig"

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,25 @@ libc. Create demo games using Zig.
138138

139139
##### POSIX
140140

141-
If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR`,
142-
`ZIG_LIBC_STATIC_LIB_DIR`, and `ZIG_LIBC_INCLUDE_DIR` should be set to
143-
(example below).
144-
145141
```
146142
mkdir build
147143
cd build
148-
cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | cc -E -x c - -v 2>&1 | grep -B1 "End of search list." | head -n1 | cut -c 2- | sed "s/ .*//") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $(cc -print-file-name=crtbegin.o))
144+
cmake ..
149145
make
150146
make install
151-
./zig build --build-file ../build.zig test
147+
bin/zig build --build-file ../build.zig test
152148
```
153149

154150
##### MacOS
155151

156-
`ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused.
157-
158152
```
159153
brew install cmake llvm@6
160154
brew outdated llvm@6 || brew upgrade llvm@6
161155
mkdir build
162156
cd build
163-
cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@6/ -DCMAKE_INSTALL_PREFIX=$(pwd)
157+
cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@6/
164158
make install
165-
./zig build --build-file ../build.zig test
159+
bin/zig build --build-file ../build.zig test
166160
```
167161

168162
##### Windows

build.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ pub fn build(b: &Builder) !void {
4545

4646
var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
4747
exe.setBuildMode(mode);
48+
49+
// This is for finding /lib/libz.a on alpine linux.
50+
// TODO turn this into -Dextra-lib-path=/lib option
51+
exe.addLibPath("/lib");
52+
4853
exe.addIncludeDir("src");
4954
exe.addIncludeDir(cmake_binary_dir);
5055
addCppLib(b, exe, cmake_binary_dir, "zig_cpp");

ci/appveyor/build_script.bat

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_
2020

2121
mkdir %ZIGBUILDDIR%
2222
cd %ZIGBUILDDIR%
23-
cmake.exe .. -Thost=x64 -G"Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGBUILDDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release "-DZIG_LIBC_INCLUDE_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" "-DZIG_LIBC_LIB_DIR=C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt" "-DZIG_LIBC_STATIC_LIB_DIR=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64" || exit /b
23+
cmake.exe .. -Thost=x64 -G"Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGBUILDDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
2424
msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b
2525

2626
bin\zig.exe build --build-file ..\build.zig test || exit /b
27-
28-
@echo "MSVC build succeeded"

ci/travis_linux_install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -x
44

55
sudo apt-get remove -y llvm-*
66
sudo rm -rf /usr/local/*
7-
sudo apt-get install -y clang-6.0 libclang-6.0 libclang-6.0-dev llvm-6.0 llvm-6.0-dev liblld-6.0 liblld-6.0-dev cmake wine1.6-amd64
7+
sudo apt-get install -y clang-6.0 libclang-6.0 libclang-6.0-dev llvm-6.0 llvm-6.0-dev liblld-6.0 liblld-6.0-dev cmake wine1.6-amd64 s3cmd

ci/travis_linux_script

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,16 @@ export CXX=clang++-6.0
88
echo $PATH
99
mkdir build
1010
cd build
11-
cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $($CC -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | $CC -E -x c - -v 2>&1 | grep -B1 "End of search list." | head -n1 | cut -c 2- | sed "s/ .*//") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $($CC -print-file-name=crtbegin.o))
12-
make VERBOSE=1
13-
make install
11+
cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd)
12+
make -j2 install
1413
./zig build --build-file ../build.zig test
1514

16-
./zig test ../test/behavior.zig --target-os windows --target-arch i386 --target-environ msvc
17-
wine zig-cache/test.exe
18-
19-
./zig test ../test/behavior.zig --target-os windows --target-arch i386 --target-environ msvc --release-fast
20-
wine zig-cache/test.exe
21-
22-
./zig test ../test/behavior.zig --target-os windows --target-arch i386 --target-environ msvc --release-safe
23-
wine zig-cache/test.exe
24-
25-
./zig test ../test/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc
26-
wine64 zig-cache/test.exe
27-
28-
#./zig test ../test/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc --release-fast
29-
#wine64 test.exe
30-
#
31-
#./zig test ../test/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc --release-safe
32-
#wine64 test.exe
15+
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
16+
mkdir $TRAVIS_BUILD_DIR/artifacts
17+
docker run -it --mount type=bind,source="$TRAVIS_BUILD_DIR/artifacts",target=/z ziglang/static-base:llvm6-1 -j2 $TRAVIS_COMMIT
18+
echo "access_key = $AWS_ACCESS_KEY_ID" >> ~/.s3cfg
19+
echo "secret_key = $AWS_SECRET_ACCESS_KEY" >> ~/.s3cfg
20+
s3cmd put -P $TRAVIS_BUILD_DIR/artifacts/* s3://ziglang.org/builds/
21+
touch empty
22+
s3cmd put -P empty s3://ziglang.org/builds/zig-linux-x86_64-$TRAVIS_BRANCH.tar.xz --add-header=x-amz-website-redirect-location:/builds/$(ls $TRAVIS_BUILD_DIR/artifacts)
23+
fi

doc/docgen.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn main() !void {
5555
// TODO issue #709
5656
// disabled to pass CI tests, but obviously we want to implement this
5757
// and then remove this workaround
58-
if (builtin.os == builtin.Os.linux) {
58+
if (builtin.os != builtin.Os.windows) {
5959
os.deleteTree(allocator, tmp_dir_name) catch {};
6060
}
6161
}

doc/langref.html.in

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,8 +1947,24 @@ const Foo = extern enum { A, B, C };
19471947
export fn entry(foo: Foo) void { }
19481948
{#code_end#}
19491949
{#header_close#}
1950-
<p>TODO packed enum</p>
1951-
{#see_also|@memberName|@memberCount|@tagName#}
1950+
{#header_open|packed enum#}
1951+
<p>By default, the size of enums is not guaranteed.</p>
1952+
<p><code>packed enum</code> causes the size of the enum to be the same as the size of the integer tag type
1953+
of the enum:</p>
1954+
{#code_begin|test#}
1955+
const std = @import("std");
1956+
1957+
test "packed enum" {
1958+
const Number = packed enum(u8) {
1959+
One,
1960+
Two,
1961+
Three,
1962+
};
1963+
std.debug.assert(@sizeOf(Number) == @sizeOf(u8));
1964+
}
1965+
{#code_end#}
1966+
{#header_close#}
1967+
{#see_also|@memberName|@memberCount|@tagName|@sizeOf#}
19521968
{#header_close#}
19531969
{#header_open|union#}
19541970
{#code_begin|test|union#}
@@ -2017,7 +2033,27 @@ test "union variant switch" {
20172033
assert(mem.eql(u8, what_is_it, "this is a number"));
20182034
}
20192035

2020-
// TODO union methods
2036+
// Unions can have methods just like structs and enums:
2037+
2038+
const Variant = union(enum) {
2039+
Int: i32,
2040+
Bool: bool,
2041+
2042+
fn truthy(self: &const Variant) bool {
2043+
return switch (*self) {
2044+
Variant.Int => |x_int| x_int != 0,
2045+
Variant.Bool => |x_bool| x_bool,
2046+
};
2047+
}
2048+
};
2049+
2050+
test "union method" {
2051+
var v1 = Variant { .Int = 1 };
2052+
var v2 = Variant { .Bool = false };
2053+
2054+
assert(v1.truthy());
2055+
assert(!v2.truthy());
2056+
}
20212057

20222058

20232059
const Small = union {
@@ -2873,7 +2909,7 @@ const err = (error {FileNotFound}).FileNotFound;
28732909
{#header_close#}
28742910
{#header_open|Error Union Type#}
28752911
<p>
2876-
An error set type and normal type can be combined with the <code>!<code>
2912+
An error set type and normal type can be combined with the <code>!</code>
28772913
binary operator to form an error union type. You are likely to use an
28782914
error union type more often than an error set type by itself.
28792915
</p>

example/guess_number/main.zig

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ pub fn main() !void {
99
var stdout_file_stream = io.FileOutStream.init(&stdout_file);
1010
const stdout = &stdout_file_stream.stream;
1111

12-
var stdin_file = try io.getStdIn();
13-
1412
try stdout.print("Welcome to the Guess Number Game in Zig.\n");
1513

1614
var seed_bytes: [@sizeOf(u64)]u8 = undefined;
@@ -27,12 +25,15 @@ pub fn main() !void {
2725
try stdout.print("\nGuess a number between 1 and 100: ");
2826
var line_buf : [20]u8 = undefined;
2927

30-
const line_len = stdin_file.read(line_buf[0..]) catch |err| {
31-
try stdout.print("Unable to read from stdin: {}\n", @errorName(err));
32-
return err;
28+
const line_len = io.readLine(line_buf[0..]) catch |err| switch (err) {
29+
error.InputTooLong => {
30+
try stdout.print("Input too long.\n");
31+
continue;
32+
},
33+
error.EndOfFile, error.StdInUnavailable => return err,
3334
};
3435

35-
const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) catch {
36+
const guess = fmt.parseUnsigned(u8, line_buf[0..line_len], 10) catch {
3637
try stdout.print("Invalid number.\n");
3738
continue;
3839
};

src-self-hosted/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ fn fmtMain(allocator: &mem.Allocator, file_paths: []const []const u8) !void {
741741
defer baf.destroy();
742742

743743
try parser.renderSource(baf.stream(), tree.root_node);
744+
try baf.finish();
744745
}
745746
}
746747

0 commit comments

Comments
 (0)