Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the default installation directory from ./zig-cache to ./ #7296

Closed
andrewrk opened this issue Dec 4, 2020 · 20 comments · Fixed by #7612 or #8638
Closed

change the default installation directory from ./zig-cache to ./ #7296

andrewrk opened this issue Dec 4, 2020 · 20 comments · Fixed by #7612 or #8638
Labels
accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Dec 4, 2020

Accepted Proposal


If you run zig init-exe and then zig build --help you see this:

Steps:
  install (default)           Copy build artifacts to prefix path
  uninstall                   Remove build artifacts from prefix path
  run                         Run the app

General Options:
  -h, --help                  Print this help and exit
  --verbose                   Print commands before executing them
  --prefix [path]             Override default install prefix
  --search-prefix [path]      Add a path to look for binaries, libraries, headers
  --color [auto|off|on]       Enable or disable colored error messages

Project-Specific Options:
  -Dtarget=[string]           The CPU architecture, OS, and ABI to build for
  -Drelease-safe=[bool]       Optimizations on and safety on
  -Drelease-fast=[bool]       Optimizations on and safety off
  -Drelease-small=[bool]      Size optimizations on and safety off

Advanced Options:
...

As you can see, the default step is install. If you pass explicit steps on the command line, those steps are executed instead of the default. Currently, the install step has a default prefix path of zig-cache:

zig/lib/std/build.zig

Lines 194 to 210 in fd18252

/// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
pub fn resolveInstallPrefix(self: *Builder) void {
if (self.dest_dir) |dest_dir| {
const install_prefix = self.install_prefix orelse "/usr";
self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable;
} else {
const install_prefix = self.install_prefix orelse blk: {
const p = self.cache_root;
self.install_prefix = p;
break :blk p;
};
self.install_path = install_prefix;
}
self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
self.h_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "include" }) catch unreachable;
}

This proposal is to make the default installation directory named after the output mode:

zig/lib/std/builtin.zig

Lines 144 to 149 in fd18252

pub const Mode = enum {
Debug,
ReleaseSafe,
ReleaseFast,
ReleaseSmall,
};

So, if you were to run zig build with the defaults for init-exe, you would get:

Debug/bin/foo.exe

With zig build -Drelease-safe you would get:

ReleaseSafe/bin/foo.exe

However, I further propose that this changes when one takes advantage of setPreferredReleaseMode, in which case

Project-Specific Options:
  -Dtarget=[string]           The CPU architecture, OS, and ABI to build for
  -Drelease-safe=[bool]       Optimizations on and safety on
  -Drelease-fast=[bool]       Optimizations on and safety off
  -Drelease-small=[bool]      Size optimizations on and safety off

turns into

Project-Specific Options:
  -Dtarget=[string]           The CPU architecture, OS, and ABI to build for
  -Drelease=[bool]            Create a release build (ReleaseSafe)

where "ReleaseSafe" is whatever the preferred release mode is. In this case, zig build -Drelease would give you a default installation directory of "Release":

Release/bin/foo.exe

As a reminder, it is always possible to override the install prefix with the --prefix CLI parameter.


Comments / suggestions / counter proposals welcome! Nobody will be accused of doing the B-word in this thread!

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig build system std.Build, the build runner, `zig build` subcommand, package management labels Dec 4, 2020
@andrewrk andrewrk added this to the 0.9.0 milestone Dec 4, 2020
@g-w1
Copy link
Contributor

g-w1 commented Dec 4, 2020

Is there any reason why this is not zig-cache/Release/bin/foo.exe or zig-cache/bin/Release/foo.exe, depending on if you can share things between multiple build modes (such as cached comptime values)? I would like this better because all the artifacts are in one place. (Keep in mind, i'm coming from Rust which does this so i'm probably biased). I like this proposal though, because it doesn't overwrite the zig-cache/bin/foo.exe when you change release mode.

@frmdstryr
Copy link
Contributor

Maybe there should just be a .zigrc file that people can set their own defaults since getting people to agree on one way will likely never happen.

I prefer how it currently is as its easier to switch modes without having to update other commands.

@g-w1
Copy link
Contributor

g-w1 commented Dec 30, 2020

I also think that the default install directory should be in the same directory as build.zig and not in cwd() as I proposed in #7603, which I realized is a duplicate of this.

@andrewrk
Copy link
Member Author

Here is what is accepted:

@andrewrk andrewrk added accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. labels Dec 30, 2020
@andrewrk andrewrk changed the title change the default installation directory from zig-cache to Debug/Release change the default installation directory from ./zig-cache to $build_root/{debug,release} Dec 30, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.8.0 Dec 30, 2020
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Dec 30, 2020
g-w1 added a commit to g-w1/zig that referenced this issue Dec 31, 2020
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
g-w1 added a commit to g-w1/zig that referenced this issue Dec 31, 2020
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
@g-w1 g-w1 mentioned this issue Dec 31, 2020
g-w1 added a commit to g-w1/zig that referenced this issue Jan 1, 2021
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
andrewrk added a commit that referenced this issue Jan 3, 2021
aarvay pushed a commit to aarvay/zig that referenced this issue Jan 4, 2021
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
andrewrk added a commit that referenced this issue Jan 4, 2021
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.
@andrewrk
Copy link
Member Author

andrewrk commented Jan 4, 2021

Reverted in fc38b42 due to a regression and pushback from the community. This issue is now open for discussion again.

@andrewrk andrewrk reopened this Jan 4, 2021
@andrewrk andrewrk removed accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Jan 4, 2021
@andrewrk
Copy link
Member Author

andrewrk commented Jan 4, 2021

One issue that this proposal does not take into account is that we currently do not have a concept of release/debug until the build.zig script creates one. However the build.zig script wants to access the installation directory. So we have a dependency cycle to resolve here if we wanted to put build mode into the install path.

g-w1 added a commit to g-w1/zig that referenced this issue Jan 5, 2021
commit 3e8aaee
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Mon Jan 4 12:20:43 2021 +0100

    Fixes missing error prong in std.os.send.

commit fc3508b
Author: J.C. Moyer <[email protected]>
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 <[email protected]>
Date:   Mon Jan 4 17:41:24 2021 +0100

    std.c: add some noalias

commit 2fe8a48
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
Date:   Mon Jan 4 14:33:32 2021 -0700

    stage2: add more perf tracing points

commit fc38b42
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
Date:   Mon Jan 4 13:40:51 2021 -0700

    Merge branch 'g-w1-stage2-evalbranch'

    closes ziglang#7682

commit 7e64dc4
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Sun Jan 3 09:10:59 2021 +0100

    std/crypto: add BLAKE2-160 types and tests

commit e4c4a0a
Author: daurnimator <[email protected]>
Date:   Mon Jan 4 01:27:35 2021 +1100

    Improve uring definitions

commit 53a0b79
Merge: c8e44d8 807dc56
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Sun Jan 3 20:25:04 2021 -0700

    stage2: fix Cache debug deadlock code memory leak

commit 5c92e24
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Sun Jan 3 16:44:53 2021 +0100

    stage2: add some missing deallocations in Compilation.zig

commit 3c05c60
Author: Timon Kruiper <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Sat Jan 2 23:11:34 2021 -0500

    fix 7665:

    only add self exe path when testing

commit 50a5301
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Sat Jan 2 19:03:37 2021 -0700

    Merge branch 'LemonBoy-revive-6680'

    closes ziglang#6870

commit 974c008
Author: Andrew Kelley <[email protected]>
Date:   Sat Jan 2 19:03:14 2021 -0700

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

commit 5b981b1
Author: LemonBoy <[email protected]>
Date:   Sat Jan 2 12:29:37 2021 +0100

    Remove some unwanted changes

    Leftovers after a long rebase.

commit 608a73e
Author: LemonBoy <[email protected]>
Date:   Wed Dec 2 20:02:51 2020 +0100

    Decrement max_depth when printing slice elements

commit 04f37dc
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 22:20:44 2020 +0100

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

commit 1fbe89d
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 19:14:22 2020 +0100

    langref: Update langref to use {s}

commit d2f6fa1
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 17:06:52 2020 +0100

    Fix more stray uses of {} for formatting strings

commit 1ca2dec
Author: LemonBoy <[email protected]>
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 <[email protected]>
Date:   Thu Nov 26 13:28:38 2020 +0100

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

commit 1c13ca5
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 13:19:30 2020 +0100

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

commit dd973fb
Author: LemonBoy <[email protected]>
Date:   Thu Nov 26 09:48:12 2020 +0100

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

commit 5a06fdf
Author: LemonBoy <[email protected]>
Date:   Thu Nov 19 19:02:30 2020 +0100

    Use same brace pairs for arrays/slices/vectors

commit d4a8fc8
Author: LemonBoy <[email protected]>
Date:   Sat Oct 31 15:16:59 2020 +0100

    Small cleanup

commit 2b5e93f
Author: data-man <[email protected]>
Date:   Sat Oct 31 15:12:05 2020 +0100

    Add formatting for arrays

commit 6f53653
Author: LemonBoy <[email protected]>
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 <[email protected]>
Date:   Wed Oct 14 18:45:46 2020 +0200

    Formatting fix

commit 1d97747
Author: ryuukk <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Sat Jan 2 22:50:49 2021 +0800

    Fix usage message

commit 44c9bf5
Author: Andrew Kelley <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Thu Dec 31 10:21:58 2020 -0500

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

commit a1a1929
Author: g-w1 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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
@andrewrk
Copy link
Member Author

andrewrk commented Jan 7, 2021

Discussed during the stage2 meeting:

  • build scripts should have access to the already computed install prefix (status quo)
  • add a -p=foo and -p foo alias for --prefix to make it easier to type, for the use case of cwd being the build root but you want to have a build directory
  • default prefix will be current working directory (instead of zig-cache)
  • Follow-up proposal (separate): omit bin/ and lib/ directories when installing Windows applications, just throw everything in the top level. Let's check what other build systems such as Meson do.

@andrewrk andrewrk changed the title change the default installation directory from ./zig-cache to $build_root/{debug,release} change the default installation directory from ./zig-cache to ./ Jan 7, 2021
@andrewrk andrewrk added accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Jan 7, 2021
@marler8997
Copy link
Contributor

Why have a different convention for windows?

@marler8997
Copy link
Contributor

Today we use $build_root/zig-cache as the default install prefix, what's the rationale behind changing it to $CWD? For example, why would we choose $CWD instead of $build_root?

@andrewrk
Copy link
Member Author

andrewrk commented Jan 8, 2021

For example, why would we choose $CWD instead of $build_root?

The main deciding factor is that it enables the use case of having a bunch of different build flags that you could mix and match so the user could name their own directories and do their own flag combos.

Why have a different convention for windows?

I'll make a follow-up proposal for that, so that won't be part of this one. The question is whether to have a convention that is consistent across different platforms, or to have a convention that is consistent across users' expectations for their own platforms (and my understanding is that Windows users expect .zip files with flat hierarchy).

@ikskuh
Copy link
Contributor

ikskuh commented Jan 8, 2021

Why have a different convention for windows?

Because if you build a project consisting of a shared library and an executable, you need to copy them to the same directory on windows anyway, but with FHS, the case is different

@marler8997
Copy link
Contributor

Because if you build a project consisting of a shared library and an executable, you need to copy them to the same directory on windows anyway, but with FHS, the case is different

Ah that's true. On Linux ELF supports absolute path references or DT_RUNPATH and the like. I don't know of an equivalent on Windows that would allow an exe to find a dll that's not in the same directory. I quickly skimmed the docs and didn't find anything we could use either (https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order).

@ityonemo
Copy link
Contributor

ityonemo commented Jan 14, 2021

Just as a note, in the long run you might want release environments, that are tagged by the user, possibly as an argument to zig build. For example, a reasonable sane default set release environments would be "test", "dev", "prod" as basic environments, but someone else might want "test", "dev", "staging", "prod", or geographically segregated for compliance reasons: "prod-US"/"prod-EU". This could for example change what dependencies are loaded by the package manager, and there could be a many-to-many mapping between the release mode and the release environments, and if I had to pick I would want release environments to set the destination directory, and not the release mode. Such a thing would not preclude using the release mode as dirname in the short term.

@marler8997
Copy link
Contributor

@ityonemo I think your examples further demonstrate the need for taking a "hands off" approach here. There are an endless number of strings one could put into the install directory name. build mode, datetime, language, backend, libc name, target arch/os/cpu, optimization level, the list goes on. So the proposed default of using CWD means that Zig is punting this decision to the user. Now Zig doesn't have to make the decision of a reasonable default set of strings to include in the install directory name.

@ityonemo
Copy link
Contributor

I would say the only thing is that if you do have it be cwd the problem is it's easy to accidentally leave a binary artifact behind in the version control, which is not great. If you have some sort of build subdirectory, then it's an easy .gitignore.

@marler8997
Copy link
Contributor

@ityonemo Yeah. If we made the default something like $CWD/install then that could have some benefits.

dgbuckley pushed a commit to dgbuckley/zig that referenced this issue Mar 9, 2021
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
dgbuckley pushed a commit to dgbuckley/zig that referenced this issue Mar 9, 2021
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.
ifreund added a commit to ifreund/zig that referenced this issue Apr 29, 2021
@KempWatson
Copy link

I've been amazed at the awkwardness of this and similar discussions. Should not one be simply able to run "zig build", and have the build system do anything relatively easily? Without needing arguments to zig build? Why is setting my own preferred target folder so hard?

@Paul-Dempsey
Copy link

@KempWatson please refrain from complaining on the issue tracker. Your comment contributes no facts or makes any specific proposal to move the issue forward. It is just a complaint. If you want to have a discussion on process or priorities, or a place to vent, one of the Zig social forums are more appropriate places for that.

@KempWatson
Copy link

@Paul-Dempsey my apologies; I'll rephrase:

I'm trying to use build.zig to script creation of a library, for a number of operating system targets, all with exactly the same name. Currently, zig build allows selection of input file paths, but not output file paths, which seems imbalanced as both are equally integral parts of building a target. The suggestion above to make the default installation directory named after the output mode will not accomplish this use case, which I think would be fairly common. I'd propose to make this simple, as in:

const libWinX64 = b.addSharedLibrary(.{
.name = "WinX64",
.root_source_file = b.path("src/main.zig"),
.dest_target_file = b.path("mycustomrelativepath/winOnX64/mylib.dll"), // PROPOSAL
.target = b.resolveTargetQuery(.{ .os_tag = .windows, .cpu_arch = .x86_64 }),
.optimize = .ReleaseSmall,
});

const libWinARM = b.addSharedLibrary(.{
.name = "WinARM",
.root_source_file = b.path("src/main.zig"),
.dest_target_file = b.path("mycustomrelativepath/winOnARM/mylib.dll"), // PROPOSAL
.target = b.resolveTargetQuery(.{ .os_tag = .windows, .cpu_arch = .aarch64 }),
.optimize = .ReleaseSmall,
});

Also, per @marler8997 above, the different output naming convention for Windows seems not to match Zig's stated goal of explicitness - it's making assumptions about output naming, also a related concern.

@marler8997
Copy link
Contributor

Hey @KempWatson, Zigup had the same issue you're describing and I solved it by making a "ci" target that will build zigup for various architectures and installs them to a subdirectory based on the target (see https://github.com/marler8997/zigup/blob/master/build.zig).

So by default, running zig build will give you your 1 zigup executable in zig-out/bin/zigup, but running zig build ci will build many targets and installs them to various subdirectories like zig-out/arch64-linux/zigup. Here's a snippet for how this works in build.zig:

    for (ci_targets) |ci_target_str| {
        const target = b.resolveTargetQuery(try std.Target.Query.parse(
            .{ .arch_os_abi = ci_target_str },
        ));
        // ...
        const zigup_exe = addZigupExe(b, target, optimize);
        const zigup_exe_install = b.addInstallArtifact(zigup_exe, .{
            .dest_dir = .{ .override = .{ .custom = ci_target_str } },
        });
        ci_step.dependOn(&zigup_exe_install.step);

Further down it evens tars up all the results into a single archive that I can download after a CI run and upload to a release. build.zig is pretty powerful but it does take some time/practice to wrap your head around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants