131 Commits

Author SHA1 Message Date
Veikka Tuominen
92f1a29c40 AstGen: make @compileError operand implicitly comptime
This matches the language reference.
2022-12-07 14:48:24 +02:00
Andrew Kelley
50eb7983cd remove most conditional compilation based on stage1
There are still a few occurrences of "stage1" in the standard library
and self-hosted compiler source, however, these instances need a bit
more careful inspection to ensure no breakage.
2022-12-06 20:38:54 -07:00
Andrew Kelley
28514476ef remove -fstage1 option
After this commit, the self-hosted compiler does not offer the option to
use stage1 as a backend anymore.
2022-12-06 12:15:04 -07:00
GethDW
024bac7f53 std.build: fix typo
This would only fail to compile when building *on* WASI.
2022-11-15 23:23:27 +02:00
Nick Cernis
8a5818535b
Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526)
* Export invalidFmtErr

To allow consistent use of "invalid format string" compile error
response for badly formatted format strings.

See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340.

* Replace format compile errors with invalidFmtErr

- Provides more consistent compile errors.
- Gives user info about the type of the badly formated value.

* Rename invalidFmtErr as invalidFmtError

For consistency. Zig seems to use “Error” more often than “Err”.

* std: add invalid format string checks to remaining custom formatters

* pass reference-trace to comp when building build file; fix checkobjectstep
2022-11-12 21:03:24 +02:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Luuk de Gram
b14f605dd7
CheckObjectStep: parse and dump target_features
When an object file or binary contains the target_features section
we can now parse and then dump its contents in string format so
we can use them in our linker tests to verify the features section.
2022-10-25 20:48:08 +02:00
Luuk de Gram
7d6596e979
Merge pull request #13218 from Luukdegram/fix-emulatable-step
std: CheckObject - correctly depend on its own step when creating an EmulatableRunStep
2022-10-19 08:36:14 +02:00
Luuk de Gram
10b56b21d4
CheckObjectStep: correctly depend on its own step
When creating an `EmulatableRunStep`, it now correctly depends
on its own step rather than only the executable that was created.
This means we do not need to add extra `dependOn` statements on
both the emulatable step as well as the check object step.
2022-10-18 17:15:58 +02:00
Ali Chraghi
ca27055cda all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
jacobly0
bd0dd225e8
Sema: implement linksection on functions
* Sema: implement linksection on functions

 * Implement function linksection in Sema.
 * Don't clobber function linksection/align/addrspace in Sema.
 * Fix copy-paste typo in tests.
 * Add a bunch of missing test_step.dependOn.
 * Fix checkInSymtab match.

Closes #12546
2022-10-18 14:02:10 +03:00
Luuk de Gram
3beef5a94f
CheckObjectStep: parsing and dumping producers 2022-10-08 09:43:40 +02:00
Lee Cannon
8d288a5fa7
Fix Step.cast for OptionsStep and CheckObjectStep 2022-09-29 14:41:39 +03:00
Andrew Kelley
3ee01c14ee std.zig.system.NativeTargetInfo: detection ignores self exe
Before, native glibc and dynamic linker detection attempted to use the
executable's own binary if it was dynamically linked to answer both the
C ABI question and the dynamic linker question. However, this could be
problematic on a system that uses a RUNPATH for the compiler binary,
locking it to an older glibc version, while system binaries such as
/usr/bin/env use a newer glibc version. The problem is that libc.so.6
glibc version will match that of the system while the dynamic linker
will match that of the compiler binary. Executables with these versions
mismatching will fail to run.

Therefore, this commit changes the logic to be the same regardless of
whether the compiler binary is dynamically or statically linked. It
inspects `/usr/bin/env` as an ELF file to find the answer to these
questions, or if there is a shebang line, then it chases the referenced
file recursively. If that does not provide the answer, then the function
falls back to defaults.

This commit also solves a TODO to remove an Allocator parameter to the
detect() function.
2022-09-08 20:52:49 -07:00
Felix "xq" Queißner
b466f8c817 Enables std.build.TranslateCStep to use stage1/stage2 selectively. Unbreaks projects using stage1 and manual TranslateC 2022-08-24 15:41:27 -04:00
Luuk de Gram
d4c56804df
std: fix EmulatableRunStep
Fixes a compilation error when using the `EmulatableRunStep`
that is being generated from a step directly using `runEmulatable`.
2022-08-21 16:42:11 +02:00
Ben Fiedler
7d674d5fb6 build: Allow comptime_int in OptionsStep.addOption 2022-08-18 23:00:44 +02:00
Jakub Konka
f26d5ee7ea macho: sync with zld
gitrev a2c32e972f8c5adfcda8ed2d99379ae868f59c24

a2c32e972f
2022-08-03 21:19:41 +02:00
Luuk de Gram
2429c3d73c
Share logic between EmulatableRunStep & RunStep 2022-07-23 10:08:53 +02:00
Luuk de Gram
4776065036
Use EmulatableRunStep for MachO linker tests 2022-07-23 10:03:51 +02:00
Luuk de Gram
735b6eefe9
rename:RunCompareStep -> EmulatableRunStep
Renamed to better convery the intention of the step
2022-07-23 10:03:51 +02:00
Luuk de Gram
0dc3a0180b
show/hide warning for incompatible warnings
Implements running and verifying the expected output when a binary is run.
Also adds warnings when a binary is skipped because of incompatibility.
This warning can be hidden by either setting the option manually through build.zig,
or by providing the option `-Dhide_foreign_warnings`.
2022-07-23 10:03:51 +02:00
Luuk de Gram
fd26c12469
RunCompareStep: implement new step
This creates a new step that can run foreign binaries when
emulation is enabled using options such as `enable_qemu`.
When an incompatible binary is found, the binary will not be executed.
This differs from `RunStep` which will always execute a binary,
regardless of the compatibility.

This is useful for usecases where the user wishes to allow for running the
binary on any supported platform either natively or through emulation,
but not generate an error when met with an incompatibility.
The above is useful when creating test cases that rely on running the binary
and optionally verifying its output.

The addition of this Step was generated by the need for our linker tests.
For that reason, a handy function was created on `CheckObjectStep` to ease
the setup for that.
2022-07-23 10:03:46 +02:00
Jakub Konka
2c184f9a5f link-tests: add checkNotPresent and add -dead_strip smoke test
`checkNotPresent` is the inverse of `checkNext` - if the phrase is
found in the output, then it fails the test.
2022-07-22 16:58:21 +02:00
Luuk de Gram
8033767082
wasm-linker: Implement linker tests (#12006)
* test/link: initial wasm support

This adds basic parsing and dumping of wasm section so they
can be tested using the new linker-test infrastructure.

* test/link: all wasm sections parsing and dumping

We now parse and dump all sections for the wasm binary format.
Currently, this only dumps the name of a custom section.
Later this should also dump symbol table, name, linking metadata and relocations.
All of those live within the custom sections.

* Add wasm linker test

This also fixes a parser mistake in reading the flags.

* test/link: implement linker tests wasm & fixes

Adds several test cases to test the wasm self-hosted linker.
This also introduces fixes that were caught during the implementation
of those tests.

* test-runner: obey omit_stage2 for standalone

When a standalone test requires stage2, but stage2 is omit
from the compiler, such test case will not be included as part
of the test suite that is being ran. This is to support CI's
where we omit stage2 to lower the memory usage.
2022-07-12 14:36:33 +02:00
Jakub Konka
5834a608fc link-tests: do not save global extracted var unless a match
Improve testing MachO binaries by verbose printing of the symtab
which includes segment,section names for defined symbols, and
import (dylib) name for imports.
2022-06-28 10:23:25 +02:00
Jakub Konka
075f5bc5ff link-tests: test -weak-lx and -weak_framework x 2022-06-28 09:22:04 +02:00
Jakub Konka
f91503e577 link-tests: defer parsing of the RPN program until running the action 2022-06-25 17:56:03 +02:00
Jakub Konka
03ddb42b8b link-tests: rename check() to checkStart()
Do not hardcode the symtab label; instead allow each parser to define
its own.

Check for missing extractor value in the matcher when matching `{}`.
2022-06-23 13:16:03 +02:00
Jakub Konka
6e04c2faab link-tests: fix parsing symtab for macho 2022-06-23 13:16:03 +02:00
Jakub Konka
e6c012c743 link-tests: add better docs 2022-06-22 22:40:05 +02:00
Jakub Konka
51f2442fc4 link-tests: clean up error messages in case of failure 2022-06-22 22:24:52 +02:00
Jakub Konka
b35e434cae link-tests: clean up linker testing harness 2022-06-22 18:34:39 +02:00
Jakub Konka
211de9b63b link-tests: fix dumping of LOAD_DYLIB: name instead of path field 2022-06-22 10:40:10 +02:00
Jakub Konka
23a63f4ce4 link-tests: rename CheckMachOStep to CheckObjectStep and accept obj format 2022-06-22 10:27:51 +02:00
Jakub Konka
b5601a2da6 link-tests: extract values into variables
We can then collect multiple variables (currently assumed always
in global scope) and run a comparison with some very basic
arithmetic on the values.
2022-06-22 00:49:22 +02:00
Jakub Konka
3bb4d65b2f link-tests: move macho tests to subfolder
Handle `-e` option in MachO linker allowing the user to set a custom
entrypoint address.
2022-06-21 23:01:09 +02:00
Jakub Konka
937464f398 link-tests: dump metadata to string and grep results
This approach is more inline with what LLVM/LLD does for testing
of their output, and seems to be more generic and easier to extend
than implementing a lot of repetitive and nontrivial comparison
logic when working directly on structures.
2022-06-21 22:19:57 +02:00
Jakub Konka
5fbdfb3f34 link-tests: add CheckMachOStep
CheckMachOStep specialises CheckFileStep into directed (surgical)
MachO file fuzzy searches. This will be the building block for
comprehensive MachO linker tests.
2022-06-21 15:44:24 +02:00
Jakub Konka
38edef35bf test: introduce link(er) tests - builds on standalone tests 2022-06-20 17:59:17 +02:00
Hanna
4e918873e7
Rename std.build.Pkg.path to std.build.Pkg.source (#11557) 2022-05-26 19:32:28 -04:00
Jonathan Marler
71f69190ef some fixes to the EnvMap HashContext 2022-05-11 18:41:23 -06:00
Ryan Liptak
a2069612a5 Fix regression in RunStep.addPathDir
`key` was never being given a value, caused by b83cea12f31feaa0aff9489d5f7bd6159d284567
2022-05-11 18:40:53 -06:00
Jonathan Marler
9e89000ffc Update usages of process.getEnvMap and change BufMap -> EnvMap where applicable
# Conflicts:
#	lib/std/build/RunStep.zig
2022-05-11 18:40:53 -06:00
Jimmi Holst Christensen
a0a2ce92ca std: Do not allocate the result for ChildProcess.init
Instead, just return ChildProcess directly. This structure does not
require a stable address, so we can put it on the stack just fine. If
someone wants it on the heap they should do.

  const proc = try allocator.create(ChildProcess);
  proc.* = ChildProcess.init(args, allocator);
2022-04-29 22:50:34 -04:00
Veikka Tuominen
691c7cb3cd std.build: fix functions returning address of by value parameter 2022-03-28 13:06:11 -07:00
Lee Cannon
3d8d6c0a6d OptionsStep: Always use fmtId for type names. 2022-03-21 02:22:43 -04:00
Cody Tapscott
c1cf158729 Replace argvCmd with std.mem.join 2022-02-06 22:21:46 -07:00
Cody Tapscott
5065830aa0 Avoid depending on child process execution when not supported by host OS
In accordance with the requesting issue (#10750):
- `zig test` skips any tests that it cannot spawn, returning success
- `zig run` and `zig build` exit with failure, reporting the command the cannot be run
- `zig clang`, `zig ar`, etc. already punt directly to the appropriate clang/lld main(), even before this change
- Native `libc` Detection is not supported

Additionally, `exec()` and related Builder functions error at run-time, reporting the command that cannot be run
2022-02-06 22:21:46 -07:00
rohlem
fbc06f9c91 std.build.TranslateCStep: add C macro support
The string construction code is moved out of std.build.LibExeObjStep
into std.build.constructCMacroArg, to allow reusing it elsewhere.
2022-02-05 03:17:07 -05:00