Commit graph

550 commits

Author SHA1 Message Date
Andrew Kelley
3fc7413574
Merge pull request #17069 from squeek502/resinator
Add a `.rc` -> `.res` compiler to the Zig compiler
2023-09-22 12:18:50 -07:00
Ryan Liptak
0168ed7bf1 rc compilation: Use MSVC includes if present, fallback to mingw
The include directories used when preprocessing .rc files are now separate from the target, and by default will use the system MSVC include paths if the MSVC + Windows SDK are present, otherwise it will fall back to the MinGW includes distributed with Zig. This default behavior can be overridden by the `-rcincludes` option (possible values: any (the default), msvc, gnu, or none).

This behavior is useful because Windows resource files may `#include` files that only exist with in the MSVC include dirs (e.g. in `<MSVC install directory>/atlmfc/include` which can contain other .rc files, images, icons, cursors, etc). So, by defaulting to the `any` behavior (MSVC if present, MinGW fallback), users will by default get behavior that is most-likely-to-work.

It also should be okay that the include directories used when compiling .rc files differ from the include directories used when compiling the main binary, since the .res format is not dependent on anything ABI-related. The only relevant differences would be things like `#define` constants being different values in the MinGW headers vs the MSVC headers, but any such differences would likely be a MinGW bug.
2023-09-17 03:09:58 -07:00
Ryan Liptak
a94d830a48 addWin32ResourceFile: Ignore the resource file if the target object format is not coff 2023-09-17 03:09:45 -07:00
Ryan Liptak
2a56fe1175 Add a .rc -> .res compiler to the Zig compiler 2023-09-17 03:09:45 -07:00
mlugg
94529ffb62 package manager: write deps in a flat format, eliminating the FQN concept
The new `@depedencies` module contains generated code like the
following (where strings like "abc123" represent hashes):

```zig
pub const root_deps = [_]struct { []const u8, []const u8 }{
    .{ "foo", "abc123" },
};

pub const packages = struct {
    pub const abc123 = struct {
        pub const build_root = "/home/mlugg/.cache/zig/blah/abc123";
        pub const build_zig = @import("abc123");
        pub const deps = [_]struct { []const u8, []const u8 }{
            .{ "bar", "abc123" },
            .{ "name", "ghi789" },
        };
    };
};
```

Each package contains a build root string, the build.zig import, and a
mapping from dependency names to package hashes. There is also such a
mapping for the root package dependencies.

In theory, we could now remove the `dep_prefix` field from `std.Build`,
since its main purpose is now handled differently. I believe this is a
desirable goal, as it doesn't really make sense to assign a single FQN
to any package (because it may appear in many different places in the
package hierarchy). This commit does not remove that field, as it's used
non-trivially in a few places in the build runner and compiler tests:
this will be a future enhancement.

Resolves: #16354
Resolves: #17135
2023-09-15 14:04:23 -07:00
Jacob Young
750998eef6 Build: fail tests that log errors, like zig test does 2023-08-25 15:36:25 -07:00
mlugg
321961d860 AstGen: add result location analysis pass
The main motivation for this change is eliminating the `block_ptr`
result location and corresponding `store_to_block_ptr` ZIR instruction.
This is achieved through a simple pass over the AST before AstGen which
determines, for AST nodes which have a choice on whether to provide a
result location, which choice to make, based on whether the result
pointer is consumed non-trivially.

This eliminates so much logic from AstGen that we almost break even on
line count! AstGen no longer has to worry about instruction rewriting
based on whether or not a result location was consumed: it always knows
what to do ahead of time, which simplifies a *lot* of logic. This also
incidentally fixes a few random AstGen bugs related to result location
handling, leading to the changes in `test/` and `lib/std/`.

This opens the door to future RLS improvements by making them much
easier to implement correctly, and fixes many bugs. Most ZIR is made
more compact after this commit, mainly due to not having redundant
`store_to_block_ptr` instructions lying around, but also due to a few
bugs in the old system which are implicitly fixed here.
2023-08-20 11:58:14 -07:00
Ryan Liptak
020105d0dd Cache: Fix findPrefix when paths are slightly out of the ordinary
This makes Cache.findPrefix/findPrefixResolved use `std.fs.path.relative` instead of `std.mem.startsWith` when checking if a file is within a prefix. This fixes multiple edge cases around prefix detection:

- If a prefix path ended with a path separator, then the first character of the 'sub_path' would get cut off because the previous implementation assumed it was a path separator. Example: prefix: `/foo/`, file_path: `/foo/abc.txt` would see that they both start with `/foo/` and then slice starting from one byte past the common prefix, ending up with `bc.txt` instead of the expected `abc.txt`
- If a prefix contained double path separators after any component, then the `startsWith` check would erroneously fail. Example: prefix: `/foo//bar`, file_path: `/foo/bar/abc.txt` would not see that abc.txt is a sub path of the prefix `/foo//bar`
- On Windows, case insensitivity was not respected at all, instead the UTF-8 bytes were compared directly

This fixes all of the things in the above list (and possibly more).
2023-08-19 22:32:24 -07:00
Jakub Konka
1e899b8769 check-object: dump contents of LC_BUILD_VERSION and LC_VERSION_MIN_* cmds 2023-08-18 11:56:14 +02:00
Jakub Konka
71cc2e6759 build: merge FrameworkDir into IncludeDir 2023-08-18 08:08:24 +02:00
Jakub Konka
23b4a2b8e1 build: disambiguate system framework path (-iframework) from framework path (-F) 2023-08-18 08:00:40 +02:00
Jakub Konka
6a4b29a58f build: remove spurious -iframework flag; use getPath2 for framework path resolution 2023-08-18 08:00:40 +02:00
Jakub Konka
5e945f813c build: do not emit -iwithsysroot/-iframeworkwithsysroot implicitly
Prior to this change, we would unconditionally emit any system include path/framework
path as `-iwithsysroot`/`-iframeworkwithsysroot` if the sysroot was
set which can lead to unexpected build failures. Now, calls to
`b.addSystemIncludePath` and `b.addFrameworkPath` will always emit
search paths as `-isystem`/`-iframework`. As a result, it is now up to
the user to correctly concat the search paths with the sysroot when
and where desired.

If there is a need for emitting `-iwithsysroot`/`-iframeworkwithsysroot`
I would advise adding explicit hooks such as `addSystemIncludePathWithSysroot`
and `addFrameworkPathWithSysroot`.
2023-08-18 08:00:40 +02:00
Andrew Kelley
a1049d4561
Merge pull request #16773 from Sahnvour/build-stack-frames
std.Build: make number of collected stack frames configurable
2023-08-13 13:54:51 -07:00
Sahnvour
2ceeade99a std.Build: add support for deps .d file in Step.Run 2023-08-13 12:15:47 -07:00
Sahnvour
f43402f883 std.Build: factorize Step stack trace dumping code 2023-08-13 11:25:48 +02:00
Sahnvour
078e330555 std.Build: make number of collected stack frames configurable 2023-08-13 10:56:28 +02:00
Xavier Bouchoux
2da28d93de build/ObjCopy: strip debug info to a separate elf file.
example usage:
    if (!strip) {
        b.installArtifact(exe);
    } else {
        const stripped_exe = b.addObjCopy(exe.getEmittedBin(), .{
            .basename = exe.out_filename, // set the name for the debuglink
            .compress_debug = true,
            .strip = .debug_and_symbols,
            .extract_to_separate_file = true,
        });
        b.getInstallStep().dependOn(&b.addInstallBinFile(stripped_exe.getOutput(), exe.out_filename).step);
        b.getInstallStep().dependOn(&b.addInstallBinFile(stripped_exe.getOutputSeparatedDebug().?, b.fmt("{s}.debug", .{exe.out_filename})).step);
    }
2023-08-12 09:54:35 +02:00
Ali Chraghi
7ab306d1f7 Build.ConfigHeader: render identifiers 2023-08-10 16:17:32 -07:00
Zachary Raineri
0461a64a93
change uses of std.builtin.Mode to OptimizeMode (#16745)
std.builtin.Mode is deprecated.
2023-08-09 14:39:34 -04:00
Andrew Kelley
aef8bcf776 std.Build.Step.Compile: fine-grained system lib search control
For each library you can specify the preferred mode and search strategy.

The old way of setting global state is eliminated.
2023-08-03 09:52:15 -07:00
Fabio Arnold
31979b1006 Fix compile error in addVcpkgPaths 2023-08-03 09:37:26 -07:00
Mitchell Hashimoto
76f7b40e15 build: dupe library, rpath, and framework LazyPaths
Without duping, users could get some unexpected behavior if they used a
string with a lifetime that didn't persist throughout the full build,
i.e. if it wasn't heap allocated, or if it was explicitly freed.
2023-08-02 20:20:48 -07:00
Andrew Kelley
4d7dd1689f CLI: stop special-casing LLVM, LLD, and Clang
Before:

-fLLVM, -fLLD, -fClang, -flibLLVM
-fno-LLVM, -fno-LLD, -fno-Clang, -fno-libLLVM

After:

-fllvm, -flld, -fclang, -flibllvm
-fno-llvm, -fno-lld, -fno-clang, -fno-libllvm
2023-08-01 20:32:54 -07:00
GethDW
33e4cbb20f std.Build.Step.WriteFile: fix call to nonexistent function 2023-07-31 14:23:57 +02:00
Andrew Kelley
25a9487caa std.Build.LazyPath: fix resolution of cwd_relative
The callsites of getPath rely on the result being absolute so that they
can pass the path to a child process with the cwd set to the build root.
2023-07-30 18:42:08 -07:00
Andrew Kelley
bdbd617237 std.Build.Step.InstallArtifact: disable emit-h
This branch was not intended to introduce new test coverage on the
emit-h feature.

See #9698
2023-07-30 17:22:54 -07:00
Andrew Kelley
38840e2e58 build system: follow-up enhancements regarding LazyPath
* introduce LazyPath.cwd_relative variant and use it for --zig-lib-dir. closes #12685
* move overrideZigLibDir and setMainPkgPath to options fields set once
  and then never mutated.
* avoid introducing Build/util.zig
* use doc comments for deprecation notices so that they show up in
  generated documentation.
* introduce InstallArtifact.Options, accept it as a parameter to
  addInstallArtifact, and move override_dest_dir into it. Instead of
  configuring the installation via Compile step, configure the
  installation via the InstallArtifact step. In retrospect this is
  obvious.
* remove calls to pushInstalledFile in InstallArtifact. See #14943
* rewrite InstallArtifact to not incorrectly observe whether a Compile
  step has any generated outputs. InstallArtifact is meant to trigger
  output generation.
* fix child process evaluation code handling of `-fno-emit-bin`.
* don't store out_h_filename, out_ll_filename, etc., pointlessly. these
  are all just simple extensions appended to the root name.
* make emit_directory optional. It's possible to have nothing outputted,
  for example, if you're just type-checking.
* avoid passing -femit-foo/-fno-emit-foo when it is the default
* rename ConfigHeader.getTemplate to getOutput
* deprecate addOptionArtifact
* update the random number seed of Options step caching.
* avoid using `inline for` pointlessly
* avoid using `override_Dest_dir` pointlessly
* avoid emitting an executable pointlessly in test cases

Removes forceBuild and forceEmit. Let's consider these additions separately.
Nearly all of the usage sites were suspicious.
2023-07-30 11:19:32 -07:00
Felix "xq" Queißner
f8386de7ae Tries to fix Windows DLL linking. 2023-07-30 11:18:50 -07:00
Felix "xq" Queißner
35d0a49db9 Introduces Compile.forceBuild() and Compile.forceEmit(…) 2023-07-30 11:18:50 -07:00
Felix (xq) Queißner
5c01818410 Introduces Compile.getEmittedX() functions, drops Compile.emit_X. Resolves #14971 2023-07-30 11:18:50 -07:00
Felix (xq) Queißner
ce95a3b153 Build.zig rename orgy (aka: #16353). Renames FileSource to LazyPath and removes functions that take literal paths instead of LazyPath. 2023-07-30 11:18:50 -07:00
Jacob Young
e8e9a4ac66 Build: use optionals again
Closes #14952
2023-07-28 21:43:07 -07:00
kcbanner
8b9627f01d test: add a test that verifies no debug handlers get pulled into compiler_rt
build: fix CheckObject checkNotPresent only checking a single line of the haystack
2023-07-27 10:31:52 -04:00
Andrew Kelley
e8fa199602 std.Build.Step.Compile: getEmittedDocs API enhancements
* Allow calling it multiple times.
 * Rename it. Sorry, this is to coincide with #16353.
2023-07-24 02:37:25 -07:00
Andrew Kelley
575a7cccc0 CLI: delete dead option -femit-analysis
This used to do something with the old autodocs system. Now it does
nothing.
2023-07-24 02:37:25 -07:00
Jacob Young
c610cde1eb test: test for issues starting codegen on many targets
Specifically this is to make sure llvm data layout generation doesn't
regress.  The no emit bin is to allow testing targets that can't
currently be linked.  The commented out targets are ones that fail in
the linker anyway when no emit bin is passed.
2023-07-23 23:48:19 -04:00
Andrew Kelley
6e4fff6ba6 move installation logic to the build script where it belongs
* build.zig: introduce `-Dflat` option which makes the installation
  match what we want to ship for our download tarballs. This allows
  deleting a bunch of shell script logic from the CI.
  - for example it puts the executable directly in prefix/zig rather
    than prefix/bin/zig and it additionally includes prefix/LICENSE.
* build.zig: by default also install std lib documentation to doc/std/
  - this can be disabled by `-Dno-autodocs` similar to how there is
    already `-Dno-langref`.
* build.zig: add `std-docs` and `langref` steps which build and install
  the std lib autodocs and langref to prefix/doc/std and
  prefix/doc/langref.html, respectively.

* std.Build: implement proper handling of `-femit-docs` using the
  LazyPath system. This is a breaking change.
  - this is a partial implementation of #16351
* frontend: fixed the handling of Autodocs with regards to caching and
  putting the artifacts in the proper location to integrate with the
  build system.
  - closes #15864

* CI: delete the logic for autodocs since it is now handled by build.zig
  and is enabled by default.
  - in the future we should strive to have nearly all the CI shell
    script logic deleted in favor of `zig build` commands.
* CI: pass `-DZIG_NO_LIB=ON`/`-Dno-lib` except for the one command where
  we want to actually generate the langref and autodocs. Generating the
  langref takes 14 minutes right now (why?!) so we don't want to do that
  more times than necessary.

* Autodoc: fixed use of a global variable. It works fine as a local
  variable instead.
  - note that in the future we will want to make Autodoc run
    simultaneously using the job system, but for now the principle of
    YAGNI dictates that we don't have an init()/deinit() API and instead
    simply call the function that does the things.
* Autodoc: only do it when there are no compile errors
2023-07-22 00:16:27 -07:00
Jakub Konka
c0260d39d5 check-object: allow for multiple extractions within one check 2023-07-20 22:12:06 +02:00
Jakub Konka
245f6553e6 check-object: format known OS-specific types before doing generic format 2023-07-20 20:01:06 +02:00
Jakub Konka
3b6200db41 check-object: dump PT flags when dumping program headers 2023-07-20 20:01:06 +02:00
Jakub Konka
e8b613783f check-object: remove wildcard matchers as they are too clunky
Instead, we now have a looser helper called `checkContains(...)`
that will match on any occurrence similarly to `std.mem.indexOf()`.

While at it, I have cleaned up other combinators to make the entire
API more consistent, and so:
* `checkStart(phrase)` is now `checkStart()` followed by
`checkExact(phrase)`
* `checkNext(phrase)` if matching exactly is now `checkExact(phrase)`
* `checkNext(phrase)` if matching loosely is now `checkContains(phrase)`
* `checkNext(phrase)` if matching exactly with var extractors is now
`checkExtract(phrase)`

Finally, `ElfDumper` is now dumping contents of `.symtab` and `.dynsym`
symbol tables. I have also removed dumping of symtabs as optional - they
are now always dumped which cleaned up the implementation even more.
2023-07-20 20:01:06 +02:00
Jakub Konka
5839054e85 check-object: dump contents of .dynamic section 2023-07-20 20:01:06 +02:00
Luuk de Gram
1a3304ed23
test/link: add shared-memory test for WebAssembly 2023-07-19 17:22:46 +02:00
Jakub Konka
546212ff7b
Merge pull request #16398 from ziglang/check-object-elf
std: add ELF parse'n'dump functionality to std.Build.Step.CheckObject
2023-07-14 06:38:33 +02:00
Jakub Konka
77026c67a4 check-object: dump info on PHDRs 2023-07-13 21:27:18 +02:00
Jakub Konka
33154b511c check-object: dump more info on SHDRs 2023-07-13 20:31:19 +02:00
Jakub Konka
76dc0d5160 check-object: dump some info on SHDRs 2023-07-13 17:01:26 +02:00
Jakub Konka
4c3625d745 check-object: dump ELF header 2023-07-13 14:33:33 +02:00
Xavier Bouchoux
cea8645423 build: avoid repeating objects when linking a static library
Don't pass the object files from a static library to the linker invocation.
The lib.a file already contains them.

Avoids "duplicate symbol" errors (and useless work by the linker)
2023-07-11 11:46:59 +02:00