238 Commits

Author SHA1 Message Date
Luuk de Gram
1cb7a01b25
wasm-linker: implement -fno-entry flag
This adds support for the `-fno-entry` and `-fentry` flags respectively, for
zig build-{exe/lib} and the build system. For `zig cc` we use the `--no-entry`
flag to be compatible with clang and existing tooling.

In `start.zig` we now make the main function optional when the target is
WebAssembly, as to allow for the build-exe command in combination with
`-fno-entry`.

When the execution model is set, and is set to 'reactor', we now verify
when an entry name is given it matches what is expected. When no entry
point is given, we set it to `_initialize` by default. This means the user
will also be met with an error when they use the reactor model, but did
not provide the correct function.
2023-11-03 12:48:52 +01:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Jacob Young
d890e81761 mem: fix ub in writeInt
Use inline to vastly simplify the exposed API.  This allows a
comptime-known endian parameter to be propogated, making extra functions
for a specific endianness completely unnecessary.
2023-10-31 21:37:35 -04:00
Jacob Young
98cd378208 x86_64: fix behavior of getValue
Old behavior renamed to `getValueIfFree`.
2023-10-26 21:45:58 -04:00
Krzysztof Wolicki
a9e66ed730 Step.Options: @typeName gives a fully qualified name so the test needs to reflect that 2023-10-26 13:56:43 +03:00
Jakub Konka
bc081901dc Step.Compile: differentiate between fuzzy and exact matches for compile errors 2023-10-25 11:40:16 +02:00
Jakub Konka
89563f07e3 build: match and ignore /?/ in expected compile errors 2023-10-24 22:08:36 +02:00
Jacob Young
8f69e977f1 x86_64: implement 128-bit builtins
* `@clz`
 * `@ctz`
 * `@popCount`
 * `@byteSwap`
 * `@bitReverse`
 * various encodings used by std
2023-10-23 22:42:18 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing
changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jan Philipp Hafer
fd2239bde9 child_process + Build: rename exec to run + all related code
Justification: exec, execv etc are unix concepts and portable version
should be called differently.

Do no touch non-Zig code. Adjust error names as well, if associated.
Closes #5853.
2023-10-22 14:47:20 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
snoire
b403ca0aab std.Build: use create() instead of init() for Step.RemoveDir 2023-10-21 17:48:25 +03:00
Andrew Kelley
a361f37b1c
Merge pull request #17608 from squeek502/resinator-fixes
resinator: Fix `INCLUDE` var handling and sync with upstream
2023-10-20 03:49:14 -04:00
dweiller
db18b562ac std.Build: do not assume custom test runners support client-server mode 2023-10-20 02:39:17 -04:00
Ryan Liptak
8ec04b567e Error if an .rc file uses the 'preprocess only' or 'no preprocess' flags 2023-10-18 18:30:32 -07:00
Andrew Kelley
149f2f8adb
Merge pull request #17524 from Vexu/aro-translate-c
Add ability to test Aro based `translate-c`
2023-10-18 00:32:59 -04:00
Veikka Tuominen
e765495b11 tests: translate-c and run-translated-c to the test harness 2023-10-17 11:55:17 +03:00
Jacob Young
fbd90e487b Build: fix some issues with ConfigHeader step
* include path was using bad default for dependency lazy paths
 * unhashed config options caused changes to not trigger a rebuild
2023-10-16 03:50:47 -04:00
Ryan Liptak
5f15acc463 Add preliminary support for Windows .manifest files
An embedded manifest file is really just XML data embedded as a RT_MANIFEST resource (ID = 24). Typically, the Windows-only 'Manifest Tool' (`mt.exe`) is used to embed manifest files, and `mt.exe` also seems to perform some transformation of the manifest data before embedding, but in testing it doesn't seem like the transformations are necessary to get the intended result.

So, to handle embedding manifest files, Zig now takes the following approach:

- Generate a .rc file with the contents `1 24 "path-to-manifest.manifest"`
- Compile that generated .rc file into a .res file
- Link the .res file into the final binary

This effectively achieves the same thing as `mt.exe` minus the validation/transformations of the XML data that it performs.

How this is used:

On the command line:
```
zig build-exe main.zig main.manifest
```
(on the command line, specifying a .manifest file when the target object format is not COFF is an error)

or in build.zig:

```
const exe = b.addExecutable(.{
    .name = "manifest-test",
    .root_source_file = .{ .path = "main.zig" },
    .target = target,
    .optimize = optimize,
    .win32_manifest = .{ .path = "main.manifest" },
});
```
(in build.zig, the manifest file is ignored if the target object format is not COFF)

Note: Currently, only one manifest file can be specified per compilation. This is because the ID of the manifest resource is currently always 1. Specifying multiple manifests could be supported if a way for the user to specify an ID for each manifest is added (manifest IDs must be a u16).

Closes #17406

options
2023-10-15 13:33:16 -07:00
radar roark
244233da2a remove redundant use of pathFromRoot 2023-10-13 07:20:45 -07:00
Krzysztof Wolicki
7edba14d7c
Step.Run: change cwd to ?Build.LazyPath (#17418)
closes #17409
2023-10-10 18:39:44 -04:00
Krzysztof Wolicki
7abf9b3a83
Step.Compile: add options struct for addCSourceFiles (#17420)
Closes #17410
2023-10-10 14:29:26 -04:00
Andrew Kelley
47a413361d Package.Fetch: fix handling of relative paths 2023-10-08 16:54:31 -07:00
Andrew Kelley
e5c2a7dbca finish hooking up new dependency tree logic
* add Module instances for each package's build.zig and attach it to the
  dependencies.zig module with the hash digest hex string as the name.
* fix incorrectly skipping the wrong packages for creating
  dependencies.zig
* a couple more renaming of "package" to "module"
2023-10-08 16:54:31 -07:00
Andrew Kelley
d0bcc390e8 get zig fetch working with the new system
* start renaming "package" to "module" (see #14307)
  - build system gains `main_mod_path` and `main_pkg_path` is still
    there but it is deprecated.
* eliminate the object-oriented memory management style of what was
  previously `*Package`. Now it is `*Package.Module` and all pointers
  point to externally managed memory.
* fixes to get the new Fetch.zig code working. The previous commit was
  work-in-progress. There are still two commented out code paths, the
  one that leads to `Compilation.create` and the one for `zig build`
  that fetches the entire dependency tree and creates the required
  modules for the build runner.
2023-10-08 16:54:31 -07:00
Jakub Konka
df9462690f std: fix memory bug in getExternalExecutor
Until now, we would pass `candidate: NativeTargetInfo` which creates
a copy of the `NativeTargetInfo.DynamicLinker` buffer. We would then
return this buffer in `bad_dl: []const u8` which would goes out-of-scope
the moment we leave this function frame yielding garbage. To fix this,
we just need to remember to pass by const-pointer
`candidate: *const NativeTargetInfo`.
2023-10-06 12:43:00 +02:00
Jakub Konka
8b4e3b6aee comp: add support for -fdata-sections 2023-10-04 11:21:56 -07:00
Andrew Kelley
8ebebbd134 std.macho: remove alignment from LoadCommandIterator 2023-10-03 14:55:17 -07:00
Carl Åstholm
412d863ba5 std.Build: expose -idirafter to the build system 2023-10-02 16:22:07 -07:00
Krzysztof Wolicki
19a82ffdba
Add include_extensions to InstallDir Options (#17300)
closes #16687
2023-09-29 18:50:37 -04:00
Krzysztof Wolicki
e919fbea9f
Step.Run: fix assert of the wrong value (#17303)
closes #16866
2023-09-29 14:14:42 -04:00
Luis Cáceres
acac685621
std.Build.ConfigHeader: override include guard option for blank style (#17310)
This commit adds an option to allow for overriding the default header guard that is generated from the output
file path.
2023-09-28 19:30:42 -04:00
antlilja
bcf4a13913 Remove @fabs, fabs and absCast/Int from std lib
Replaces occurences of @fabs absCast and absInt with new @abs builtin.
Also removes the std.math.fabs alias from math.zig.
2023-09-27 11:24:28 -07:00
LinuxUserGD
ceaae42e90 Add '--compress-debug-sections=zstd' 2023-09-26 14:18:01 -07:00
antlilja
8eff0a0a66 Support non zig dependencies
Dependencies no longer require a build.zig file.

Adds path function to Dependency struct which
returns a LazyPath into a dependency.
2023-09-24 02:47:21 +01:00
Garrett Beck
8b78df403f Allow Step.TranslateC to not link libc 2023-09-23 17:41:11 -07:00
kcbanner
53d1282f0c build: add --skip-oom-steps
Specifying this argument causes steps that specify a max_rss that exceeds the
total max_rss value of the runner to be skipped, instead of failing.
2023-09-22 15:08:51 -07:00
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