Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3e8aaee
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 22:25:04 2021 -0700

    std: skip more tests on Windows to save CI memory

    I've enabled only the tests that check things specific to Windows that
    are not tested by other systems.

commit 16896a9
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 15:57:54 2021 -0700

    ci: skip crypto tests on windows

    Trying to buy us more time on the Windows CI.

commit 66e5e92
Merge: d957244 2561168
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 14:23:01 2021 -0800

    Merge pull request ziglang#7592 from LemonBoy/fix-7188

    Allow variable captures on multi-prong switch arms

commit d957244
Author: Evan Haas <evan@lagerdata.com>
Date:   Fri Jan 1 23:13:15 2021 -0800

    Allow dollar sign $ in identifiers in translate-c

    In strictly conforming C, identifiers cannot container dollar signs.
    However GCC and Clang allow them by default, so translate-c should
    handle them. See http://gcc.gnu.org/onlinedocs/cpp/Tokenization.html
    I encountered this in the wild in windows.h

    Fixes ziglang#7585

commit 819f2a0
Author: Felix (xq) Queißner <git@mq32.de>
Date:   Mon Jan 4 12:20:43 2021 +0100

    Fixes missing error prong in std.os.send.

commit fc3508b
Author: J.C. Moyer <jcmoyer32@gmail.com>
Date:   Mon Jan 4 09:15:39 2021 -0500

    Fix off-by-one error in SinglyLinkedList.len() and add associated tests

commit a93c123
Author: xackus <14938807+xackus@users.noreply.github.com>
Date:   Mon Jan 4 17:41:24 2021 +0100

    std.c: add some noalias

commit 2fe8a48
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 14:59:18 2021 -0700

    ci: omit stage2 backend from stage1 on Windows

    to avoid out-of-memory on the CI runs.

commit 462c1d8
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 14:33:32 2021 -0700

    stage2: add more perf tracing points

commit fc38b42
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 13:49:17 2021 -0700

    Revert "Fix ziglang#7296:"

    This broke build scripts that wanted to refer to `exe_dir` or
    `install_path`.

    There has also been some pushback and discussion on this breaking
    change. I think it should be re-evaluated.

    This reverts commit a1a1929.

commit ef2fa67
Merge: aa0906e 7e64dc4
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 13:40:51 2021 -0700

    Merge branch 'g-w1-stage2-evalbranch'

    closes ziglang#7682

commit 7e64dc4
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon Jan 4 13:40:01 2021 -0700

    stage2: improvements to `@setEvalBranchQuota`

     * extract magic number into a constant
     * properly use result location casting for the operand
     * naming convention for ZIR instructions

commit 638f93e
Author: g-w1 <jacoblevgw@gmail.com>
Date:   Sun Jan 3 15:45:22 2021 -0500

    stage2: implementation of `@setEvalBranchQuota`:

    `@setEvalBranchQuota` can be called before the comptime/inline call
    stack is created.

    For example:

    ```zig
    @setEvalBranchQuota(100);
    comptime {
        while (true) {}
    }
    ```

    Here we need to set the branch_quota before the comptime block creates a
    scope for the branch_count.

commit aa0906e
Author: joachimschmidt557 <joachim.schmidt557@outlook.com>
Date:   Sat Jan 2 18:53:11 2021 +0100

    stage2 x86_64: fix bug in Function.gen

    Previously, the x86_64 backend would remove code for exitlude relocs
    if the jump amount were 0. This causes issues as earlier jumps rely on
    the jump being present at the same address.

commit 4400d2d
Author: Frank Denis <github@pureftpd.org>
Date:   Sun Jan 3 09:10:59 2021 +0100

    std/crypto: add BLAKE2-160 types and tests

commit e4c4a0a
Author: daurnimator <quae@daurnimator.com>
Date:   Mon Jan 4 01:27:35 2021 +1100

    Improve uring definitions

commit 53a0b79
Merge: c8e44d8 807dc56
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun Jan 3 19:51:38 2021 -0800

    Merge pull request ziglang#7681 from kubkon/stage2-aarch64-fn-args

    stage2: basic fn args for aarch64

commit c8e44d8
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun Jan 3 20:34:17 2021 -0700

    stage2: remove the Cache deadlock detection code

    It's more trouble than it's worth; it didn't even catch the most recent
    incident because it was across process boundaries anyway.

commit 404dc96
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun Jan 3 20:25:04 2021 -0700

    stage2: fix Cache debug deadlock code memory leak

commit 5c92e24
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun Jan 3 20:10:07 2021 -0700

    drone ci: skip compile error tests to save time

    These are covered by other CI scripts and we're up against Drone CI time
    limits.

commit f664425
Merge: 5cc1310 0151f3b
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun Jan 3 16:09:14 2021 -0800

    Merge pull request ziglang#7598 from FireFox317/more-llvm-stage2

    stage2: More improvements to self-hosted LLVM backend

commit 5cc1310
Author: Evan Haas <evan@lagerdata.com>
Date:   Tue Dec 29 11:07:04 2020 -0800

    Static function declarations with no prototype should not be variadic

    If a static function is defined with no argument list and no prototype
    is given, it should be treated as a function that takes no arguments
    rather than as a variadic function.

    Fixes ziglang#7594

commit 807dc56
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Sun Jan 3 23:20:09 2021 +0100

    stage2: add aarch64 stage2 tests

    Fix missing string format specifier in Mach-O used to generate
    path to debug symbols bundle.

commit 2a410ba
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Sun Jan 3 23:01:22 2021 +0100

    stage2: implement basic function params aarch64

    Implement missing `.register` prong for `aarch64` `genSetReg`.

commit 0151f3b
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Sun Jan 3 17:10:28 2021 +0100

    stage2: Add support for testing LLVM enabled builds in test-stage2

    To make sure that we don't have to rebuild libc for every case, we now
    have a seperate cache directory for the global cache, which remains
    the same between test runs.

    Also make sure to destory the Compilation before executing a child process,
    otherwise the compiler deadlocks. (ziglang#7596)

commit a926c91
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Sun Jan 3 16:48:52 2021 +0100

    stage2: enable building test-stage2 with LLVM backend enabled

    We can now run `zig build test-stage2 -Denable-llvm`.

commit 7e5aaca
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Sun Jan 3 16:44:53 2021 +0100

    stage2: add some missing deallocations in Compilation.zig

commit 3c05c60
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Sun Jan 3 16:09:32 2021 +0100

    stage2: Output the LLVM object files in the cache directory

    Also make sure to properly free everything.

commit 0008bef
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Sun Jan 3 16:00:12 2021 +0100

    stage2: add support for integers in LLVM backend

    Also adds support for simple operators, like add and subtract.
    The intcast and bitcast instruction also have been implemented.

    Linking with libc also works, so we can now generate working executables!

    `zig build-exe example.zig -fLLVM -lc`:
    ```
    fn add(a: i32, b: i32) i32 {
        return a + b;
    }

    export fn main() c_int {
        var a: i32 = -5;
        const x = add(a, 7);
        var y = add(2, 0);
        y -= x;
        return y;
    }
    ```

commit e095ebf
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue Dec 29 22:47:52 2020 +0100

    stage2: make use of proper LLVM intrinsic APIs in LLVM backend

commit da545d6
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue Dec 29 20:39:58 2020 +0100

    stage2: implement argument passing and returning in LLVM backend

    Furthermore add the Not instruction.

    The following now works:
    ```
    export fn _start() noreturn {
        var x: bool = true;
        var other: bool = foo(x);
        exit();
    }

    fn foo(cond: bool) bool {
        return !cond;
    }

    fn exit() noreturn {
        unreachable;
    }
    ```

commit 47a4d43
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue Dec 29 20:18:17 2020 +0100

    stage2: Add code generation for Load instruction in LLVM backend

    The following now works:
    ```
    export fn _start() noreturn {
        var x: bool = true;
        var y: bool = x;
        exit();
    }

    fn exit() noreturn {
        unreachable;
    }
    ```

commit 19cfd31
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue Dec 29 20:09:08 2020 +0100

    stage2: implement register allocation in LLVM self-hosted backend

    A HashMap has been added which store the LLVM values used in a function.
    Together with the alloc and store instructions the following now works:
    ```
    export fn _start() noreturn {
        var x: bool = true;
        exit();
    }

    fn exit() noreturn {
        unreachable;
    }
    ```

commit a5dab15
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue Dec 29 19:03:04 2020 +0100

    stage2: clear `err_msg` after it has been added to `module.failed_decls`

commit 0ed04aa
Author: Timon Kruiper <timonkruiper@gmail.com>
Date:   Tue Dec 29 18:52:53 2020 +0100

    stage2: fix building self-hosted compiler with -Dstatic-llvm

    This supersedes c81ae52

commit 5aac2fc
Author: Frank Denis <github@pureftpd.org>
Date:   Sat Jan 2 20:08:27 2021 +0100

    std/crypto: properly support arbitrary output sizes

    Fixes ziglang#7657

commit 6838141
Merge: d8f3f14 33e53d7
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 22:05:31 2021 -0800

    Merge pull request ziglang#7612 from g-w1/do-7296

    Implement ziglang#7296

commit d8f3f14
Merge: 3d151fb 6548322
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 22:01:51 2021 -0800

    Merge pull request ziglang#7647 from ziglang/stage2-comptime-fn-call

    stage2: comptime function calls and inline function calls

commit 6548322
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 22:42:07 2021 -0700

    stage2: support recursive inline/comptime functions

    zir.Inst no longer has an `analyzed_inst` field. This is previously how
    we mapped ZIR to their TZIR counterparts, however with the way inline
    and comptime function calls work, we can potentially have the same ZIR
    structure being analyzed by multiple different analyses, such as during
    a recursive inline function call. This would cause the `analyzed_inst`
    field to become clobbered. So instead, we use a table to map the
    instructions to their semantically analyzed counterparts. This will help
    with multi-threaded compilation as well.

    Scope.Block.Inlining is split into 2 different layers of "sharedness".
    The first layer is shared by the whole inline/comptime function call
    stack. It contains the callsite where something is being inlined and the
    branch count/quota. The second layer is different per function call but
    shared by all the blocks within the function being inlined.

    Add support for debug dumping br and brvoid TZIR instructions.

    Remove the "unreachable code" error. It was happening even for this case:

    ```zig
    if (comptime_condition) return;
    bar(); // error: unreachable code
    ```

    We will need smarter logic for when it is legal to emit this compile
    error.

    Remove the ZIR test cases. These are redundant with other higher level
    Zig source tests we have, and maintaining support for ZIRModule as a
    first-class top level abstraction is getting in the way of clean
    compiler design for the main use case. We will have ZIR/TZIR based test
    cases someday to help with testing optimization passes and ZIR to TZIR
    analysis, but as is, these test cases are not accomplishing that, and
    they are getting in the way.

commit 3d151fb
Author: g-w1 <jacoblevgw@gmail.com>
Date:   Sat Jan 2 23:11:34 2021 -0500

    fix 7665:

    only add self exe path when testing

commit 50a5301
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 14:28:03 2021 -0700

    stage2: fix handling compile error in inline fn call

     * scopes properly inherit inlining information
     * compile errors of inline function calls are properly attached to the
       caller rather than the callee.
       - added a test case for this
     * --watch still opens a repl if compile errors happen.

commit 006e7f6
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 13:40:23 2021 -0700

    stage2: re-use ZIR for comptime and inline calls

    Instead of freeing ZIR after semantic analysis, we keep it around so
    that it can be used for comptime calls, inline calls, and generic
    function calls. ZIR memory is now managed by the Decl arena.

    Debug dump() functions are conditionally compiled; only available in
    Debug builds of the compiler.

    Add a test for an inline function call.

commit 9362f38
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 12:32:30 2021 -0700

    stage2: implement function call inlining in the frontend

     * remove the -Ddump-zir thing. that's handled through --verbose-ir
     * rework Fn to have an is_inline flag without requiring any more memory
       on the heap per function.
     * implement a rough first version of dumping typed zir (tzir) which is
       a lot more helpful for debugging than what we had before. We don't
       have a way to parse it though.
     * keep track of whether the inline-ness of a function changes because
       if it does we have to go update callsites.
     * add compile error for inline and export used together.

    inline function calls and comptime function calls are implemented the
    same way. A block instruction is set up to capture the result, and then
    a scope is set up that has a flag for is_comptime and some state if the
    scope is being inlined.

    when analyzing `ret` instructions, zig looks for inlining state in the
    scope, and if found, treats `ret` as a `break` instruction instead, with
    the target block being the one set up at the inline callsite.

    Follow-up items:
     * Complete out the debug TZIR dumping code.
     * Don't redundantly generate ZIR for each inline/comptime function
       call. Instead we should add a new state enum tag to Fn.
     * comptime and inlining branch quotas.
     * Add more test cases.

commit fea8659
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Fri Jan 1 19:24:02 2021 -0700

    stage2: comptime function calls

     * Function calls that happen in a comptime scope get called at
       compile-time. We do this by putting the parameters in place as
       constant values and then running regular function analysis on the
       body.
     * Added `Scope.Block.dump()` for debugging purposes.
     * Fixed some code to call `identifierTokenString` rather than
       `tokenSlice`, making it work for `@""` syntax.
     * Implemented `Value.copy` for big integers.

    Follow-up issues to tackle:
     * Adding compile errors to the callsite instead of the callee Decl.
     * Proper error notes for "called from here".
       - Related: ziglang#7555
     * Branch quotas.
     * ZIR support?

commit fb37c1b
Merge: db1e97d 974c008
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 19:03:37 2021 -0700

    Merge branch 'LemonBoy-revive-6680'

    closes ziglang#6870

commit 974c008
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 19:03:14 2021 -0700

    convert more {} to {d} and {s}

commit 5b981b1
Author: LemonBoy <thatlemon@gmail.com>
Date:   Sat Jan 2 12:29:37 2021 +0100

    Remove some unwanted changes

    Leftovers after a long rebase.

commit 608a73e
Author: LemonBoy <thatlemon@gmail.com>
Date:   Wed Dec 2 20:02:51 2020 +0100

    Decrement max_depth when printing slice elements

commit 04f37dc
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 22:20:44 2020 +0100

    stage2: Use {z} instead of {s} in generated Zig code

commit 1fbe89d
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 19:14:22 2020 +0100

    langref: Update langref to use {s}

commit d2f6fa1
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 17:06:52 2020 +0100

    Fix more stray uses of {} for formatting strings

commit 1ca2dec
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 15:43:28 2020 +0100

    std: Disable the special casing of {} for u8 slices/arrays

    Unless {s} is specified the contents won't be treated as a string.

commit 4420afe
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 13:28:38 2020 +0100

    tests: Use {s} instead of {} when formatting strings

commit 1c13ca5
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 13:19:30 2020 +0100

    stage2: Use {s} instead of {} when formatting strings

commit dd973fb
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 26 09:48:12 2020 +0100

    std: Use {s} instead of {} when printing strings

commit 5a06fdf
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Nov 19 19:02:30 2020 +0100

    Use same brace pairs for arrays/slices/vectors

commit d4a8fc8
Author: LemonBoy <thatlemon@gmail.com>
Date:   Sat Oct 31 15:16:59 2020 +0100

    Small cleanup

commit 2b5e93f
Author: data-man <datamanrb@gmail.com>
Date:   Sat Oct 31 15:12:05 2020 +0100

    Add formatting for arrays

commit 6f53653
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu Oct 29 22:22:25 2020 +0100

    std: Refactor the slice formatting code

    Also fix the `*` specifier for more types, print an error message if we
    can't show the value address.

commit 5275280
Author: ryuukk <44361234+ryuukk@users.noreply.github.com>
Date:   Wed Oct 14 18:45:46 2020 +0200

    Formatting fix

commit 1d97747
Author: ryuukk <44361234+ryuukk@users.noreply.github.com>
Date:   Wed Oct 14 18:38:59 2020 +0200

    Pretty print Slices

    This code is adapted from pixelherodev paste from IRC

    I have added a new fmt option to handle printing slice values ``{v}`` or ``{V}``

    While i think it can be made the default, i want your opinion about it

    ```zig
        var slicea = [0]u32{};
        var sliceb = [3]u32{ 1, 2, 3 };

        std.log.info("Content: {v}", .{slicea});
        std.log.info("Content: {v}", .{sliceb});
    ```

    will print:

    ```
    info: Content: []
    info: Content: [1, 2, 3]
    ```

    Question:

    Should we drop ``{v}`` and make it the default behavior?

commit db1e97d
Author: Cameron Conn <camconn@users.noreply.github.com>
Date:   Sat Jan 2 18:06:51 2021 -0600

    Improve documentation for ArrayList, ArrayListUnmanaged, etc. (ziglang#7624)

    * Improve ArrayList & co documentation

    - Added doc comments about the validity of references to elements in
    an ArrayList and how they may become invalid after resizing operations.
    - This should help users avoid footguns in future.

    * Improve ArrayListUnmanaged & co's documentation

    - Port improved documentation from ArrayList and ArrayList aligned to
      their unmanaged counterparts.
    - Made documentation for ArrayListUnmanaged & co more inclusive and
      up-to-date.
    - Made documentation more consistent with `ArrayList`.

    * Corrections on ArrayList documentation.

    - Remove incorrect/unpreferred wording on ArrayList vs
      ArrayListUnmanaged.
    - Fix notes about the alignment of ArrayListAligned
    - Be more verbose with warnings on when pointers are invalidated.
    - Copy+paste a few warnings

    * add warning to replaceRange

    * revert changes to append documentation

commit 1856dfe
Author: LemonBoy <LemonBoy@users.noreply.github.com>
Date:   Fri Jan 1 19:33:53 2021 +0100

    stage1: Use correct format specifier for size_t parameters

    Use `Iu` on Windows, the integer width depends on the target being
    a 32bit or a 64bit one.

commit af8eab5
Author: Sizhe Zhao <prc.zhao@outlook.com>
Date:   Sat Jan 2 22:50:49 2021 +0800

    Fix usage message

commit 44c9bf5
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat Jan 2 12:21:19 2021 -0700

    std: disable a couple tests on windows

    They are passing but we're hitting OOM on the Windows CI server. This is
    to buy us more time until stage2 rescues us from the CI memory crisis.

commit 5a65796
Merge: a9c75a2 763d807
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Sat Jan 2 20:08:37 2021 +0100

    Merge pull request ziglang#7506 from kubkon/fix-6923

    zig cc: detect framework include paths when native

commit 763d807
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Sun Dec 20 11:52:25 2020 +0100

    Duplicate OSAtomic.h between aarch64 and x86_64

    The reason this is required is for two reasons: 1) the libc
    targeting `aarch64` macOS is slightly newer than that targeting
    `x86_64`, and 2) `OSAtomic.h` uses relative imports rather than
    system-wide imports for accompanying headers which clearly is an
    oversight on Apple's part. Until such time when `libkern` headers
    between `x86_64` and `aarch64` are identical, this will require a
    manual intervention to duplicate the relevant headers between the
    respective architectures.

commit 91a35e1
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Sun Dec 20 11:45:48 2020 +0100

    Detect native iframework dirs on macOS

    This commit adds default search paths for system frameworks
    on macOS while also adding `-isysroot` for OS versions at least BigSur.
    Since BigSur (11.0.1), neither headers nor libs exist in standard
    root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they
    are now exclusively part of the installed developer toolchain (either
    via XCode.app or CLT), and specifying `-isysroot` allows us to keep
    using universal search paths such as `/System/Library/Frameworks` while
    only changing the include flag from `-iframework` to
    `-iframeworkwithsysroot`.

commit 33e53d7
Author: g-w1 <jacoblevgw@gmail.com>
Date:   Thu Dec 31 10:21:58 2020 -0500

    update .gitignore to include /release/ and /debug/

commit a1a1929
Author: g-w1 <jacoblevgw@gmail.com>
Date:   Wed Dec 30 21:04:27 2020 -0500

    Fix ziglang#7296:

    * makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.

commit 2561168
Author: LemonBoy <thatlemon@gmail.com>
Date:   Tue Dec 29 13:00:01 2020 +0100

    std: Clean up some tests

    No functional changes, remove some dead code.

commit 88634f0
Author: LemonBoy <thatlemon@gmail.com>
Date:   Tue Dec 29 12:58:47 2020 +0100

    stage1: Allow variable capture for multi-prong switch arms

    Handle the multi-prong case as we do with range cases.

    Closes ziglang#7188
  • Loading branch information
g-w1 committed Jan 5, 2021
1 parent e5fcdfa commit 101f6d8
Show file tree
Hide file tree
Showing 111 changed files with 3,504 additions and 1,772 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# -andrewrk

zig-cache/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries
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")
set(ZIG_OMIT_STAGE2 off CACHE BOOL "omit the stage2 backend from stage1")

find_package(llvm)
find_package(clang)
Expand Down Expand Up @@ -587,6 +588,12 @@ if(MSVC)
endif()
endif()

if(ZIG_OMIT_STAGE2)
set(ZIG_OMIT_STAGE2_BOOL "true")
else()
set(ZIG_OMIT_STAGE2_BOOL "false")
endif()

configure_file (
"${CMAKE_SOURCE_DIR}/src/stage1/config.h.in"
"${ZIG_CONFIG_H_OUT}"
Expand Down
221 changes: 121 additions & 100 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn build(b: *Builder) !void {
exe.addBuildOption(bool, "have_llvm", enable_llvm);
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);

if (is_stage1) {
exe.addIncludeDir("src");
exe.addIncludeDir("deps/SoftFloat-3e/source/include");
Expand All @@ -109,28 +110,8 @@ pub fn build(b: *Builder) !void {
softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
exe.linkLibrary(softfloat);

const exe_cflags = [_][]const u8{
"-std=c++14",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-D_GNU_SOURCE",
"-fvisibility-inlines-hidden",
"-fno-exceptions",
"-fno-rtti",
"-Werror=type-limits",
"-Wno-missing-braces",
"-Wno-comment",
};
exe.addCSourceFiles(&stage1_sources, &exe_cflags);
exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
if (cmake_cfg == null) {
// We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
// in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is
// unavailable when LLVM is compiled in Release mode.
const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);
}
}
if (cmake_cfg) |cfg| {
// Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
Expand All @@ -139,79 +120,13 @@ pub fn build(b: *Builder) !void {
if (cfg.cmake_prefix_path.len > 0) {
b.addSearchPrefix(cfg.cmake_prefix_path);
}
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cfg.cmake_binary_dir,
"zigcpp",
b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
}) catch unreachable);
assert(cfg.lld_include_dir.len != 0);
exe.addIncludeDir(cfg.lld_include_dir);
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);

const need_cpp_includes = tracy != null;

// System -lc++ must be used because in this code path we are attempting to link
// against system-provided LLVM, Clang, LLD.
if (exe.target.getOsTag() == .linux) {
// First we try to static link against gcc libstdc++. If that doesn't work,
// we fall back to -lc++ and cross our fingers.
addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
error.RequiredLibraryNotFound => {
exe.linkSystemLibrary("c++");
},
else => |e| return e,
};

exe.linkSystemLibrary("pthread");
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
} else if (exe.target.getOsTag() == .openbsd) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
} else if (exe.target.isDarwin()) {
if (addCxxKnownPath(b, cfg, exe, "libgcc_eh.a", "", need_cpp_includes)) {
// Compiler is GCC.
try addCxxKnownPath(b, cfg, exe, "libstdc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
// TODO LLD cannot perform this link.
// Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead.
// See https://github.com/ziglang/zig/issues/1535
} else |err| switch (err) {
error.RequiredLibraryNotFound => {
// System compiler, not gcc.
exe.linkSystemLibrary("c++");
},
else => |e| return e,
}
}

if (cfg.dia_guids_lib.len != 0) {
exe.addObjectFile(cfg.dia_guids_lib);
}
try addCmakeCfgOptionsToExe(b, cfg, tracy, exe);
try addCmakeCfgOptionsToExe(b, cfg, tracy, test_stage2);
} else {
// Here we are -Denable-llvm but no cmake integration.
for (clang_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}

for (lld_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}

for (llvm_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}

// This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
exe.linkSystemLibrary("c++");

if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("version");
exe.linkSystemLibrary("uuid");
}
try addStaticLlvmOptionsToExe(exe);
try addStaticLlvmOptionsToExe(test_stage2);
}
}
if (link_libc) {
Expand All @@ -220,11 +135,10 @@ pub fn build(b: *Builder) !void {
}

const log_scopes = b.option([]const []const u8, "log", "Which log scopes to enable") orelse &[0][]const u8{};
const zir_dumps = b.option([]const []const u8, "dump-zir", "Which functions to dump ZIR for before codegen") orelse &[0][]const u8{};

const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");
const version = if (opt_version_string) |version| version else v: {
const version_string = b.fmt("{}.{}.{}", .{ zig_version.major, zig_version.minor, zig_version.patch });
const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch });

var code: u8 = undefined;
const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{
Expand All @@ -238,7 +152,7 @@ pub fn build(b: *Builder) !void {
0 => {
// Tagged release version (e.g. 0.7.0).
if (!mem.eql(u8, git_describe, version_string)) {
std.debug.print("Zig version '{}' does not match Git tag '{}'\n", .{ version_string, git_describe });
std.debug.print("Zig version '{s}' does not match Git tag '{s}'\n", .{ version_string, git_describe });
std.process.exit(1);
}
break :v version_string;
Expand All @@ -258,15 +172,15 @@ pub fn build(b: *Builder) !void {

// Check that the commit hash is prefixed with a 'g' (a Git convention).
if (commit_id.len < 1 or commit_id[0] != 'g') {
std.debug.print("Unexpected `git describe` output: {}\n", .{git_describe});
std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
break :v version_string;
}

// The version is reformatted in accordance with the https://semver.org specification.
break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id[1..] });
break :v b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] });
},
else => {
std.debug.print("Unexpected `git describe` output: {}\n", .{git_describe});
std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
break :v version_string;
},
}
Expand All @@ -277,9 +191,9 @@ pub fn build(b: *Builder) !void {
exe.addBuildOption(std.SemanticVersion, "semver", semver);

exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps);
exe.addBuildOption(bool, "enable_tracy", tracy != null);
exe.addBuildOption(bool, "is_stage1", is_stage1);
exe.addBuildOption(bool, "omit_stage2", false);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
Expand All @@ -302,6 +216,7 @@ pub fn build(b: *Builder) !void {

test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
test_stage2.addBuildOption(bool, "is_stage1", is_stage1);
test_stage2.addBuildOption(bool, "omit_stage2", false);
test_stage2.addBuildOption(bool, "have_llvm", enable_llvm);
test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
Expand Down Expand Up @@ -359,6 +274,112 @@ pub fn build(b: *Builder) !void {
test_step.dependOn(docs_step);
}

const exe_cflags = [_][]const u8{
"-std=c++14",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-D_GNU_SOURCE",
"-fvisibility-inlines-hidden",
"-fno-exceptions",
"-fno-rtti",
"-Werror=type-limits",
"-Wno-missing-braces",
"-Wno-comment",
};

fn addCmakeCfgOptionsToExe(
b: *Builder,
cfg: CMakeConfig,
tracy: ?[]const u8,
exe: *std.build.LibExeObjStep,
) !void {
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cfg.cmake_binary_dir,
"zigcpp",
b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
}) catch unreachable);
assert(cfg.lld_include_dir.len != 0);
exe.addIncludeDir(cfg.lld_include_dir);
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);

const need_cpp_includes = tracy != null;

// System -lc++ must be used because in this code path we are attempting to link
// against system-provided LLVM, Clang, LLD.
if (exe.target.getOsTag() == .linux) {
// First we try to static link against gcc libstdc++. If that doesn't work,
// we fall back to -lc++ and cross our fingers.
addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
error.RequiredLibraryNotFound => {
exe.linkSystemLibrary("c++");
},
else => |e| return e,
};

exe.linkSystemLibrary("pthread");
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
} else if (exe.target.getOsTag() == .openbsd) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
} else if (exe.target.isDarwin()) {
if (addCxxKnownPath(b, cfg, exe, "libgcc_eh.a", "", need_cpp_includes)) {
// Compiler is GCC.
try addCxxKnownPath(b, cfg, exe, "libstdc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
// TODO LLD cannot perform this link.
// Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead.
// See https://github.com/ziglang/zig/issues/1535
} else |err| switch (err) {
error.RequiredLibraryNotFound => {
// System compiler, not gcc.
exe.linkSystemLibrary("c++");
},
else => |e| return e,
}
}

if (cfg.dia_guids_lib.len != 0) {
exe.addObjectFile(cfg.dia_guids_lib);
}
}

fn addStaticLlvmOptionsToExe(
exe: *std.build.LibExeObjStep,
) !void {
// Adds the Zig C++ sources which both stage1 and stage2 need.
//
// We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
// in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is
// unavailable when LLVM is compiled in Release mode.
const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);

for (clang_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}

for (lld_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}

for (llvm_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}

// This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
exe.linkSystemLibrary("c++");

if (exe.target.getOs().tag == .windows) {
exe.linkSystemLibrary("version");
exe.linkSystemLibrary("uuid");
}
}

fn addCxxKnownPath(
b: *Builder,
ctx: CMakeConfig,
Expand All @@ -369,14 +390,14 @@ fn addCxxKnownPath(
) !void {
const path_padded = try b.exec(&[_][]const u8{
ctx.cxx_compiler,
b.fmt("-print-file-name={}", .{objname}),
b.fmt("-print-file-name={s}", .{objname}),
});
const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;
if (mem.eql(u8, path_unpadded, objname)) {
if (errtxt) |msg| {
warn("{}", .{msg});
warn("{s}", .{msg});
} else {
warn("Unable to determine path to {}\n", .{objname});
warn("Unable to determine path to {s}\n", .{objname});
}
return error.RequiredLibraryNotFound;
}
Expand Down
5 changes: 3 additions & 2 deletions ci/azure/windows_msvc_script.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ git.exe fetch --tags

mkdir %ZIGBUILDDIR%
cd %ZIGBUILDDIR%
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release -DZIG_OMIT_STAGE2=ON || exit /b
msbuild /maxcpucount /p:Configuration=Release INSTALL.vcxproj || exit /b

"%ZIGINSTALLDIR%\bin\zig.exe" build test-behavior -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stage2 -Dskip-non-native || exit /b
REM Disabled to prevent OOM
REM "%ZIGINSTALLDIR%\bin\zig.exe" build test-stage2 -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-fmt -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-std -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compiler-rt -Dskip-non-native || exit /b
Expand Down
2 changes: 1 addition & 1 deletion ci/drone/linux_script
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cd build
cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja

samu install
./zig build test -Dskip-release -Dskip-non-native
./zig build test -Dskip-release -Dskip-non-native -Dskip-compile-errors

if [ -z "$DRONE_PULL_REQUEST" ]; then
mv ../LICENSE "$DISTDIR/"
Expand Down
Loading

0 comments on commit 101f6d8

Please sign in to comment.