Commit graph

491 commits

Author SHA1 Message Date
Andrew Kelley
105db13536 std.Build: implement --host-target, --host-cpu, --host-dynamic-linker
This also makes a long-overdue change of extracting common state from
Build into a shared Graph object.

Getting the semantics right for these flags turned out to be quite
tricky. In the end it works like this:
* The override only happens when the target is fully native, with no
  additional query parameters, such as versions or CPU features added.
* The override affects the resolved Target but leaves the original Query
  unmodified.
* The "is native?" detection logic operates on the original, unmodified
  query. This makes it possible to provide invalid host target
  information, causing confusing errors to occur. Don't do that.

There are some minor breaking changes to std.Build API such as the fact
that `b.zig_exe` is now moved to `b.graph.zig_exe`, as well as a handful
of other similar flags.
2024-02-02 20:43:01 -07:00
Jakub Konka
d93a0763d4 test/link/link: pass build options to elf and macho tests 2024-01-24 12:34:39 +01:00
Andrew Kelley
b92e30ff0b std.Build.ResolvedTarget: rename target field to result
This change is seemingly insignificant but I actually agonized over this
for three days. Some other things I considered:

* (status quo in master branch) make Compile step creation functions
  accept a Target.Query and delete the ResolvedTarget struct.
  - downside: redundantly resolve target queries many times
* same as before but additionally add a hash map to cache target query
  resolutions.
  - downside: now there is a hash map that doesn't actually need to
    exist, just to make the API more ergonomic.
* add is_native_os and is_native_abi fields to std.Target and use it
  directly as the result of resolving a target query.
  - downside: they really don't belong there. They would be available
    as comptime booleans via `@import("builtin")` but they should not
    be exposed that way.

With this change the downsides are:
* the option name of addExecutable and friends is `target` instead of
  `resolved_target` matching the type name.
  - upside: this does not break compatibility with existing build
    scripts
* you likely end up seeing `target.result.cpu.arch` rather than
  `target.cpu.arch`.
  - upside: this is an improvement over `target.target.cpu.arch` which
    it was before this commit.
  - downside: `b.host.target` is now `b.host.result`.
2024-01-01 17:51:18 -07:00
Andrew Kelley
8c44954bc6 std.Target.Query: remove deprecated API
These functions have been doomed for a long time. Finally I figured out
what the proper relationship between this API and std.Target is.
2024-01-01 17:51:18 -07:00
Andrew Kelley
3179f58c41 rename std.zig.CrossTarget to std.Target.Query 2024-01-01 17:51:18 -07:00
Andrew Kelley
142471fcc4 zig build system: change target, compilation, and module APIs
Introduce the concept of "target query" and "resolved target". A target
query is what the user specifies, with some things left to default. A
resolved target has the default things discovered and populated.
In the future, std.zig.CrossTarget will be rename to std.Target.Query.
Introduces `std.Build.resolveTargetQuery` to get from one to the other.

The concept of `main_mod_path` is gone, no longer supported. You have to
put the root source file at the module root now.

* remove deprecated API
* update build.zig for the breaking API changes in this branch
* move std.Build.Step.Compile.BuildId to std.zig.BuildId
* add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions,
  std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and
  std.Build.TestOptions.
* remove `std.Build.constructCMacro`. There is no use for this API.
* deprecate `std.Build.Step.Compile.defineCMacro`. Instead,
  `std.Build.Module.addCMacro` is provided.
  - remove `std.Build.Step.Compile.defineCMacroRaw`.
* deprecate `std.Build.Step.Compile.linkFrameworkNeeded`
  - use `std.Build.Module.linkFramework`
* deprecate `std.Build.Step.Compile.linkFrameworkWeak`
  - use `std.Build.Module.linkFramework`
* move more logic into `std.Build.Module`
* allow `target` and `optimize` to be `null` when creating a Module.
  Along with other fields, those unspecified options will be inherited
  from parent `Module` when inserted into an import table.
* the `target` field of `addExecutable` is now required. pass `b.host`
  to get the host target.
2024-01-01 17:51:18 -07:00
Jacob Young
bf5ab54510 test: test with -fstrip and fix failures
Closes #17513
2023-12-01 04:34:50 +00:00
Andrew Kelley
e357550610 update for the std.fs.Dir changes 2023-11-22 15:24:57 -07:00
Andrew Kelley
9f363cd679 zig init: also create a build.zig.zon 2023-11-20 23:30:51 -07:00
Andrew Kelley
f645022d16 merge zig init-exe and zig init-lib into zig init
Instead of `zig init-lib` and `zig init-exe`, now there is only
`zig init`, which initializes any of the template files that do not
already exist, and makes a package that contains both an executable and
a static library. The idea is that the user can delete whatever they
don't want. In fact, I think even more things should be added to the
build.zig template.
2023-11-20 23:01:45 -07:00
Andrew Kelley
234693bcbb tests: skip native CPU std tests on Windows
See tracking issue #17902
2023-11-06 16:03:04 -07:00
Jacob Young
f6f2708d82 x86_64: fix compiler rt test failures 2023-10-29 07:20:36 -04:00
Jacob Young
20ade4ce7f tests: change some x86_64 backend targets to pic for more coverage 2023-10-29 05:15:35 -04:00
Jacob Young
48526c0eb6 test: enable c-abi-tests for the x86_64 backend
Add testing for `x86_64_v2` and `x86_64_v3` with the x86_64 backend.
2023-10-26 21:45:58 -04:00
Jacob Young
b55377a5ab x86_64: pass more tests
* 128-bit integer multiplication with overflow
 * more instruction encodings used by std inline asm
 * implement the `try_ptr` air instruction
 * follow correct stack frame abi
 * enable full panic handler
 * enable stack traces
2023-10-25 04:28:30 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadb.
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 0c99ba1eab, reversing
changes made to 5f92b070bf.

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
Jacob Young
70c8e7f91d x86_64: disable failing tests, enable test-compiler-rt testing 2023-10-21 10:55:41 -04:00
Jacob Young
32e85d44eb x86_64: disable failing tests, enable test-std testing 2023-10-21 10:55:41 -04:00
Jacob Young
d8f7c79298 x86_64: improve inline assembly support
* C++-style comments
 * indirect call operands
 * fix misleading immediate debug formatting
2023-10-18 13:57:28 -04:00
Krzysztof Wolicki
7edba14d7c
Step.Run: change cwd to ?Build.LazyPath (#17418)
closes #17409
2023-10-10 18:39:44 -04:00
Jakub Konka
cdd4dbfe32 test: add x86_64-linux-musl-no-lld as a test target 2023-09-28 19:28:06 +02:00
mlugg
62d077cfa1
tests: give explicit stack size to module tests on WASI
I have observed the standard library tests overflowing the default WASI
stack as of the previous commit. As best as I can tell, this isn't
directly our fault: LLVM is just emitting less efficient code in debug
builds with the new codegen patterns.
2023-09-23 22:01:08 +01:00
Andrew Kelley
5d92cc8cf6 skip all mips tests due to LLVM 17 regressions
Tracked by #16846
2023-09-19 09:37:53 -07:00
Andrew Kelley
3acf0f637e disable failing mips tests due to LLVM 17 regressions
tracked by #16846
2023-09-19 09:37:53 -07:00
Jakub Konka
517a2c7caf build: add build test check for availability of IOS SDK on the host 2023-08-18 11:57:12 +02:00
Jacob Young
9e0a34f329 llvm: fix data layout calculation for experimental llvm targets
Closes #16616
2023-08-01 19:20:22 -07:00
Jacob Young
817fa3af86 std: cleanup asm usage
After fixing some issues with inline assembly in the C backend, the std
cleanups have the side effect of making these functions compatible with
the backend, allowing it to be used on linux without linking libc.
2023-07-31 01:58:10 -04: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
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
125b453c58 llvm: fix SysV C abi for structs smaller than two eightbytes
Closes #16038
Closes #16288
2023-07-28 19:27:08 -04:00
Andrew Kelley
a707f380a5 llvm: disable LTO on C ABI tests
This required disabling some failing tests. See #14908
2023-07-26 11:07:11 -07:00
Ian Johnson
9892ec31a0 zig fmt: make --exclude work on files
Closes #16178
2023-07-24 19:41:59 -07:00
Mason Remaley
5744ceedb8
Fixes WriteFile.getFileSource failure on Windows (#15730) 2023-05-24 14:26:07 -07:00
Veikka Tuominen
3f3b1a6808 std.Build: use Step.* instead of *Step
Follow up to 13eb7251d3
2023-05-03 20:55:29 -07:00
Andrew Kelley
dc94729643 CI: disable compiling std lib C backend test with clang
Unfortunately this requires about 8G of RAM for clang to compile
and our Windows CI runners do not have this much.
2023-04-24 11:58:45 -07:00
Andrew Kelley
39644fb277 Revert "tests: add a maxrss for compiling std lib C backend .c file"
This reverts commit c75e11bf6a.

Caused this problem on some machines:
"this step declares an upper bound of 9126805504 bytes of memory,
exceeding the available 7515721728 bytes of memory".

Instead the next commit will disable std lib tests with the C backend on
Windows.
2023-04-24 11:51:46 -07:00
Andrew Kelley
c75e11bf6a tests: add a maxrss for compiling std lib C backend .c file
I observed clang taking 8G to compile the output from the std lib tests
using the C backend. This commit should make the Windows CI stop failing
due to OOM.
2023-04-23 22:24:13 -07:00
Jacob Young
871d29b1a4 std: add more missing windows libraries when running tests 2023-04-21 16:36:31 -04:00
Jacob Young
ee9ef86d89 test: exclude the last warning from cbe tests 2023-04-21 16:36:31 -04:00
Jacob Young
c5cf611516 std: add missing windows libraries when running tests
Thanks to @kcbanner for diagnosing this.
2023-04-21 16:36:11 -04:00
Jacob Young
bf6fd9ae3f cbe: enable CI for std tests 2023-04-21 16:36:10 -04:00
Jacob Young
7794186210
x86_64: disable some behavior tests
These backends doesn't support the new liveness yet.
2023-04-20 20:49:35 +01:00
Andrew Kelley
30fc160874
Merge pull request #15302 from jacobly0/x86_64-non-liveness
x86_64: liveness independent fixes
2023-04-18 17:28:19 -07:00
Jacob Young
4df87b40fd tests: fix skip_cross_glibc check
Native targets are, by definition, not cross-compiling targets.
2023-04-16 17:36:02 -07:00
Jacob Young
780f654e19 behavior: disable flaky test on x86_64
Also reenable stage2_x86_64 windows behavior tests in case it is failing
for the same reason.

Closes #15324
2023-04-16 17:07:07 -04:00
Andrew Kelley
9e6647582d disable x86_64-windows self-hosted backend behavior tests
because they are not passing on the CI yet.
2023-04-15 12:45:47 -07:00
Andrew Kelley
a281d29881 disable not-yet-passing C backend tests 2023-04-15 10:33:08 -07:00