2023-11-10 20:44:43 +08:00
|
|
|
pub fn build(b: *Build) void {
|
|
|
|
const test_step = b.step("test-link", "Run link tests");
|
|
|
|
b.default_step = test_step;
|
|
|
|
|
|
|
|
test_step.dependOn(@import("elf.zig").testAll(b));
|
|
|
|
test_step.dependOn(@import("macho.zig").testAll(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const Options = struct {
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
target: std.Build.ResolvedTarget,
|
2023-11-10 20:44:43 +08:00
|
|
|
optimize: std.builtin.OptimizeMode = .Debug,
|
|
|
|
use_llvm: bool = true,
|
|
|
|
use_lld: bool = false,
|
|
|
|
};
|
|
|
|
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step {
|
|
|
|
const target = opts.target.target.zigTriple(b.allocator) catch @panic("OOM");
|
2023-11-10 20:44:43 +08:00
|
|
|
const optimize = @tagName(opts.optimize);
|
|
|
|
const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm";
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}", .{
|
|
|
|
prefix, target, optimize, use_llvm,
|
2023-11-10 20:44:43 +08:00
|
|
|
}) catch @panic("OOM");
|
|
|
|
return b.step(name, "");
|
|
|
|
}
|
|
|
|
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
const OverlayOptions = struct {
|
|
|
|
name: []const u8,
|
|
|
|
asm_source_bytes: ?[]const u8 = null,
|
|
|
|
c_source_bytes: ?[]const u8 = null,
|
|
|
|
c_source_flags: []const []const u8 = &.{},
|
|
|
|
cpp_source_bytes: ?[]const u8 = null,
|
|
|
|
cpp_source_flags: []const []const u8 = &.{},
|
|
|
|
zig_source_bytes: ?[]const u8 = null,
|
|
|
|
pic: ?bool = null,
|
|
|
|
strip: ?bool = null,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Step.Compile {
|
|
|
|
const compile_step = b.addExecutable(.{
|
|
|
|
.name = overlay.name,
|
|
|
|
.root_source_file = rsf: {
|
|
|
|
const bytes = overlay.zig_source_bytes orelse break :rsf null;
|
|
|
|
break :rsf b.addWriteFiles().add("a.zig", bytes);
|
|
|
|
},
|
|
|
|
.target = base.target,
|
|
|
|
.optimize = base.optimize,
|
|
|
|
.use_llvm = base.use_llvm,
|
|
|
|
.use_lld = base.use_lld,
|
|
|
|
.pic = overlay.pic,
|
|
|
|
.strip = overlay.strip,
|
2023-11-10 20:44:43 +08:00
|
|
|
});
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
if (overlay.cpp_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.cpp", bytes),
|
|
|
|
.flags = overlay.cpp_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.c_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.c", bytes),
|
|
|
|
.flags = overlay.c_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.asm_source_bytes) |bytes| {
|
|
|
|
compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes));
|
|
|
|
}
|
|
|
|
return compile_step;
|
2023-11-10 20:44:43 +08:00
|
|
|
}
|
|
|
|
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Step.Compile {
|
|
|
|
const compile_step = b.addObject(.{
|
|
|
|
.name = overlay.name,
|
|
|
|
.root_source_file = rsf: {
|
|
|
|
const bytes = overlay.zig_source_bytes orelse break :rsf null;
|
|
|
|
break :rsf b.addWriteFiles().add("a.zig", bytes);
|
|
|
|
},
|
|
|
|
.target = base.target,
|
|
|
|
.optimize = base.optimize,
|
|
|
|
.use_llvm = base.use_llvm,
|
|
|
|
.use_lld = base.use_lld,
|
|
|
|
.pic = overlay.pic,
|
|
|
|
.strip = overlay.strip,
|
2023-11-10 20:44:43 +08:00
|
|
|
});
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
if (overlay.cpp_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.cpp", bytes),
|
|
|
|
.flags = overlay.cpp_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.c_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.c", bytes),
|
|
|
|
.flags = overlay.c_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.asm_source_bytes) |bytes| {
|
|
|
|
compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes));
|
|
|
|
}
|
|
|
|
return compile_step;
|
2023-11-10 20:44:43 +08:00
|
|
|
}
|
|
|
|
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
|
|
|
|
const compile_step = b.addStaticLibrary(.{
|
|
|
|
.name = overlay.name,
|
|
|
|
.root_source_file = rsf: {
|
|
|
|
const bytes = overlay.zig_source_bytes orelse break :rsf null;
|
|
|
|
break :rsf b.addWriteFiles().add("a.zig", bytes);
|
|
|
|
},
|
|
|
|
.target = base.target,
|
|
|
|
.optimize = base.optimize,
|
|
|
|
.use_llvm = base.use_llvm,
|
|
|
|
.use_lld = base.use_lld,
|
|
|
|
.pic = overlay.pic,
|
|
|
|
.strip = overlay.strip,
|
2023-11-10 20:44:43 +08:00
|
|
|
});
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
if (overlay.cpp_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.cpp", bytes),
|
|
|
|
.flags = overlay.cpp_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.c_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.c", bytes),
|
|
|
|
.flags = overlay.c_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.asm_source_bytes) |bytes| {
|
|
|
|
compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes));
|
|
|
|
}
|
|
|
|
return compile_step;
|
2023-11-10 20:44:43 +08:00
|
|
|
}
|
|
|
|
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
|
|
|
|
const compile_step = b.addSharedLibrary(.{
|
|
|
|
.name = overlay.name,
|
|
|
|
.root_source_file = rsf: {
|
|
|
|
const bytes = overlay.zig_source_bytes orelse break :rsf null;
|
|
|
|
break :rsf b.addWriteFiles().add("a.zig", bytes);
|
|
|
|
},
|
|
|
|
.target = base.target,
|
|
|
|
.optimize = base.optimize,
|
|
|
|
.use_llvm = base.use_llvm,
|
|
|
|
.use_lld = base.use_lld,
|
|
|
|
.pic = overlay.pic,
|
|
|
|
.strip = overlay.strip,
|
2023-11-10 20:44:43 +08:00
|
|
|
});
|
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.
2023-12-03 12:51:34 +08:00
|
|
|
if (overlay.cpp_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.cpp", bytes),
|
|
|
|
.flags = overlay.cpp_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.c_source_bytes) |bytes| {
|
|
|
|
compile_step.addCSourceFile(.{
|
|
|
|
.file = b.addWriteFiles().add("a.c", bytes),
|
|
|
|
.flags = overlay.c_source_flags,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (overlay.asm_source_bytes) |bytes| {
|
|
|
|
compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes));
|
|
|
|
}
|
|
|
|
return compile_step;
|
2023-11-10 20:44:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addRunArtifact(comp: *Compile) *Run {
|
|
|
|
const b = comp.step.owner;
|
|
|
|
const run = b.addRunArtifact(comp);
|
|
|
|
run.skip_foreign_checks = true;
|
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void {
|
|
|
|
const b = comp.step.owner;
|
|
|
|
const file = WriteFile.create(b).add("a.c", bytes);
|
|
|
|
comp.addCSourceFile(.{ .file = file, .flags = flags });
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCppSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void {
|
|
|
|
const b = comp.step.owner;
|
|
|
|
const file = WriteFile.create(b).add("a.cpp", bytes);
|
|
|
|
comp.addCSourceFile(.{ .file = file, .flags = flags });
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addAsmSourceBytes(comp: *Compile, bytes: []const u8) void {
|
|
|
|
const b = comp.step.owner;
|
|
|
|
const actual_bytes = std.fmt.allocPrint(b.allocator, "{s}\n", .{bytes}) catch @panic("OOM");
|
|
|
|
const file = WriteFile.create(b).add("a.s", actual_bytes);
|
|
|
|
comp.addAssemblyFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expectLinkErrors(comp: *Compile, test_step: *Step, expected_errors: Compile.ExpectedCompileErrors) void {
|
|
|
|
comp.expect_errors = expected_errors;
|
|
|
|
const bin_file = comp.getEmittedBin();
|
|
|
|
bin_file.addStepDependencies(test_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
const Build = std.Build;
|
|
|
|
const Compile = Step.Compile;
|
|
|
|
const Run = Step.Run;
|
|
|
|
const Step = Build.Step;
|
|
|
|
const WriteFile = Step.WriteFile;
|