aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build.zig
AgeCommit message (Collapse)Author
2024-02-02std.Build: use a runtime panic for wrong dependency APIAndrew Kelley
This makes it easier to debug and avoids a false positive compile error in the build script.
2024-02-02build system: implement lazy dependencies, part 1Andrew Kelley
Build manifest files support `lazy: true` for dependency sections. This causes the auto-generated dependencies.zig to have 2 more possibilities: 1. It communicates whether a dependency is lazy or not. 2. The dependency might be acknowledged, but missing due to being lazy and not fetched. Lazy dependencies are not fetched by default, but if they are already fetched then they are provided to the build script. The build runner reports the set of missing lazy dependenices that are required to the parent process via stdout and indicates the situation with exit code 3. std.Build now has a `lazyDependency` function. I'll let the doc comments speak for themselves: When this function is called, it means that the current build does, in fact, require this dependency. If the dependency is already fetched, it proceeds in the same manner as `dependency`. However if the dependency was not fetched, then when the build script is finished running, the build will not proceed to the make phase. Instead, the parent process will additionally fetch all the lazy dependencies that were actually required by running the build script, rebuild the build script, and then run it again. In other words, if this function returns `null` it means that the only purpose of completing the configure phase is to find out all the other lazy dependencies that are also required. It is allowed to use this function for non-lazy dependencies, in which case it will never return `null`. This allows toggling laziness via build.zig.zon without changing build.zig logic. The CLI for `zig build` detects this situation, but the logic for then redoing the build process with these extra dependencies fetched is not yet implemented.
2024-02-02std.Build: make systemIntegrationOption take a defaultAndrew Kelley
2024-02-02build system: implement --system [dir]Andrew Kelley
This prevents package fetching and enables system_package_mode in the build system which flips the defaults for system integrations.
2024-02-02build system: implement --release[=mode]Andrew Kelley
This allows a `zig build` command to specify intention to create a release build, regardless of what per-project options exist. It also allows the command to specify a "preferred optimization mode", which is chosen if the project itself does not choose one (in other words, the project gets first choice). If neither the build command nor the project specify a preferred release mode, an error occurs.
2024-02-02std.Build.resolveTargetQuery: fix ignoring ofmt for nativeAndrew Kelley
2024-02-02std.Build: make system library integrations more generalAndrew Kelley
Before it was named "library" inconsistently. Now the CLI args are -fsys=[name] and -fno-sys=[name] and it is a more general-purpose "system integration" which could be a library name or perhaps a project name such as "ffmpeg" or a binary such as "nasm".
2024-02-02std.Build: revert moving some fields to GraphAndrew Kelley
On second thought, let's keep a bunch of these flags how they already were. Partial revert of the previous commit.
2024-02-02std.Build: implement --host-target, --host-cpu, --host-dynamic-linkerAndrew Kelley
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-02build system: introduce system library integrationAndrew Kelley
* New --help section * Add b.systemLibraryOption * Rework the build runner CLI logic a bit
2024-01-18zig build: add doc comments for functions related to optionsAndrew Kelley
closes #18204
2024-01-16Build: add namedWriteFiles to BuildLoris Cro
2024-01-06std.Build: pass code model in various compile stepsTristan Ross
2024-01-04build/LazyPath: Add dirname (#18371)Abhinav Gupta
Adds a variant to the LazyPath union representing a parent directory of a generated path. ```zig const LazyPath = union(enum) { generated_dirname: struct { generated: *const GeneratedFile, up: usize, }, // ... } ``` These can be constructed with the new method: ```zig pub fn dirname(self: LazyPath) LazyPath ``` For the cases where the LazyPath is already known (`.path`, `.cwd_relative`, and `dependency`) this is evaluated right away. For dirnames of generated files and their dirnames, this is evaluated at getPath time. dirname calls can be chained, but for safety, they are not allowed to escape outside a root defined for each case: - path: This is relative to the build root, so dirname can't escape outside the build root. - generated: Can't escape the zig-cache. - cwd_relative: This can be a relative or absolute path. If relative, can't escape the current directory, and if absolute, can't go beyond root (/). - dependency: Can't escape the dependency's root directory. Testing: I've included a standalone case for many of the happy cases. I couldn't find an easy way to test the negatives, though, because tests cannot yet expect panics.
2024-01-03Fix std.Build.findProgramKrzysztof Wolicki
2024-01-02Merge pull request #18160 from ziglang/std-build-moduleAndrew Kelley
Move many settings from being per-Compilation to being per-Module
2024-01-02add support for lists when parsing user argssammy j
2024-01-01std.Build: add error_tracing field to addExecutable and friendsAndrew Kelley
To support easily overriding error return tracing for the main module.
2024-01-01std.Build.ResolvedTarget: rename target field to resultAndrew Kelley
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-01std.Build: fix userInputOptionsFromArgs ResolvedTargetAndrew Kelley
it wasn't using the Target.Query like it was supposed to for the triple
2024-01-01std.Target.Query: remove deprecated APIAndrew Kelley
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-01std.Target: add DynamicLinkerAndrew Kelley
2024-01-01rename std.zig.CrossTarget to std.Target.QueryAndrew Kelley
2024-01-01std.Build: handle ResolvedTarget in userInputOptionsFromArgsAndrew Kelley
2024-01-01zig build system: change target, compilation, and module APIsAndrew Kelley
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-01zig build system: remove vcpkg integrationAndrew Kelley
Instead of vcpkg, users are encouraged to use the Zig package manager to fulfill dependencies on Windows.
2024-01-01introduce std.Build.Module and extract some logic into itAndrew Kelley
This moves many settings from `std.Build.Step.Compile` and into `std.Build.Module`, and then makes them transitive. In other words, it adds support for exposing Zig modules in packages, which are configured in various ways, such as depending on other link objects, include paths, or even a different optimization mode. Now, transitive dependencies will be included in the compilation, so you can, for example, make a Zig module depend on some C source code, and expose that Zig module in a package. Currently, the compiler frontend autogenerates only one `@import("builtin")` module for the entire compilation, however, a future enhancement will be to make it honor the differences in modules, so that modules can be compiled with different optimization modes, code model, valgrind integration, or even target CPU feature set. closes #14719
2023-11-26fix: Prevent segfault when using add.Module()Daniel A.C. Martin
This duplicates the source file string (as is done in other places such as `addAssemblyFile()`) in order to prevent a segfault when the supplied string is freed by the caller. This is still seen when the caller makes use of a defer statement.
2023-10-23x86_64: implement enough to pass unicode testsJacob Young
* implement vector comparison * implement reduce for bool vectors * fix `@memcpy` bug * enable passing std tests
2023-10-22child_process + Build: rename exec to run + all related codeJan Philipp Hafer
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-21fix `std.Build.addAssembly`Lee Cannon
2023-10-21std.Build: use create() instead of init() for Step.RemoveDirsnoire
2023-10-20std.Build: do not assume custom test runners support client-server modedweiller
2023-10-18std.Build: make dependencies inherit `--search-prefix`Andrew Kelley
2023-10-15Add preliminary support for Windows .manifest filesRyan Liptak
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-08get `zig fetch` working with the new systemAndrew Kelley
* 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-09-24Support non zig dependenciesantlilja
Dependencies no longer require a build.zig file. Adds path function to Dependency struct which returns a LazyPath into a dependency.
2023-09-15package manager: write deps in a flat format, eliminating the FQN conceptmlugg
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-08-16std.Build: check for native CPU when serializing CrossTargetmlugg
When using `std.Build.dependency` with target options, dependencies would sometimes get targets which are equivalent but have distinct names, e.g. `native` vs `native-native`. This is a somewhat broad issue, and it's unclear how to fix it more generally - perhaps we should special-case CrossTarget in options passing, or maybe targets should have a canonical name which we guarantee to use everywhere aside from raw user input. However, this commit fixes the most egregious issue, which was an active blocker to using the package manager for some users. This was caused by the CPU changing from `native` to a specific descriptor (e.g. `skylake+sgx`), which then changed the behavior of `zigTriple`. Resolves: #16856
2023-08-13Merge pull request #16773 from Sahnvour/build-stack-framesAndrew Kelley
std.Build: make number of collected stack frames configurable
2023-08-13std.Build: factorize Step stack trace dumping codeSahnvour
2023-08-13std.Build: make number of collected stack frames configurableSahnvour
2023-08-10Compare user input for multiple dependency build variants (#16600)Matt Knight
2023-08-09change uses of std.builtin.Mode to OptimizeMode (#16745)Zachary Raineri
std.builtin.Mode is deprecated.
2023-07-30std.Build.LazyPath: fix resolution of cwd_relativeAndrew Kelley
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-30build system: follow-up enhancements regarding LazyPathAndrew Kelley
* 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-30Introduces `Compile.getEmittedX()` functions, drops `Compile.emit_X`. ↵Felix (xq) Queißner
Resolves #14971
2023-07-30Build.zig rename orgy (aka: #16353). Renames FileSource to LazyPath and ↵Felix (xq) Queißner
removes functions that take literal paths instead of LazyPath.
2023-07-24Use builtin inference over @as where possibleZachary Raineri
2023-06-26Build: make `InstallDirStep` use a `FileSource`Ian Johnson
Closes #16187