retire the example/ folder, rename test-build-examples to "standalone"

closes #2759
This commit is contained in:
Andrew Kelley 2019-07-16 12:15:46 -04:00
parent 92e781baa1
commit 9dcddc2249
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
15 changed files with 19 additions and 41 deletions

View File

@ -134,7 +134,7 @@ pub fn build(b: *Builder) !void {
test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native));
test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
test_step.dependOn(tests.addBuildExampleTests(b, test_filter, modes));
test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
test_step.dependOn(tests.addCliTests(b, test_filter, modes));
test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));

View File

@ -1,14 +0,0 @@
# Zig Examples
* **Tetris** - A simple Tetris clone written in Zig. See
[andrewrk/tetris](https://github.com/andrewrk/tetris).
* **hello_world** - demonstration of a printing a single line to stdout.
One version depends on libc; one does not.
* **guess_number** - simple console game where you guess the number the
computer is thinking of and it says higher or lower. No dependency on
libc.
* **cat** - implementation of the `cat` UNIX utility in Zig, with no dependency
on libc.
* **shared_library** - demonstration of building a shared library and generating
a header file for interop with C code.
* **mix_o_files** - how to mix .zig and .c files together as object files

View File

@ -1,8 +0,0 @@
use @import("std").os.windows;
extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int;
export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT {
_ = MessageBoxA(null, c"hello", c"title", 0);
return 0;
}

View File

@ -2,16 +2,16 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
const is_windows = builtin.os == builtin.Os.windows;
pub fn addCases(cases: *tests.BuildExamplesContext) void {
cases.add("example/hello_world/hello.zig");
cases.addC("example/hello_world/hello_libc.zig");
cases.add("example/cat/main.zig");
cases.add("example/guess_number/main.zig");
pub fn addCases(cases: *tests.StandaloneContext) void {
cases.add("test/standalone/hello_world/hello.zig");
cases.addC("test/standalone/hello_world/hello_libc.zig");
cases.add("test/standalone/cat/main.zig");
cases.add("test/standalone/guess_number/main.zig");
cases.add("test/standalone/main_return_error/error_u8.zig");
cases.add("test/standalone/main_return_error/error_u8_non_zero.zig");
cases.addBuildFile("test/standalone/main_pkg_path/build.zig");
cases.addBuildFile("example/shared_library/build.zig");
cases.addBuildFile("example/mix_o_files/build.zig");
cases.addBuildFile("test/standalone/shared_library/build.zig");
cases.addBuildFile("test/standalone/mix_o_files/build.zig");
cases.addBuildFile("test/standalone/static_c_lib/build.zig");
cases.addBuildFile("test/standalone/issue_339/build.zig");
cases.addBuildFile("test/standalone/issue_794/build.zig");

View File

@ -13,7 +13,7 @@ const Mode = builtin.Mode;
const LibExeObjStep = build.LibExeObjStep;
const compare_output = @import("compare_output.zig");
const build_examples = @import("build_examples.zig");
const standalone = @import("standalone.zig");
const compile_errors = @import("compile_errors.zig");
const assemble_and_link = @import("assemble_and_link.zig");
const runtime_safety = @import("runtime_safety.zig");
@ -91,17 +91,17 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8, modes:
return cases.step;
}
pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
cases.* = BuildExamplesContext{
pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
.b = b,
.step = b.step("test-build-examples", "Build the examples"),
.step = b.step("test-standalone", "Run the standalone tests"),
.test_index = 0,
.test_filter = test_filter,
.modes = modes,
};
build_examples.addCases(cases);
standalone.addCases(cases);
return cases.step;
}
@ -830,22 +830,22 @@ pub const CompileErrorContext = struct {
}
};
pub const BuildExamplesContext = struct {
pub const StandaloneContext = struct {
b: *build.Builder,
step: *build.Step,
test_index: usize,
test_filter: ?[]const u8,
modes: []const Mode,
pub fn addC(self: *BuildExamplesContext, root_src: []const u8) void {
pub fn addC(self: *StandaloneContext, root_src: []const u8) void {
self.addAllArgs(root_src, true);
}
pub fn add(self: *BuildExamplesContext, root_src: []const u8) void {
pub fn add(self: *StandaloneContext, root_src: []const u8) void {
self.addAllArgs(root_src, false);
}
pub fn addBuildFile(self: *BuildExamplesContext, build_file: []const u8) void {
pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {
const b = self.b;
const annotated_case_name = b.fmt("build {} (Debug)", build_file);
@ -875,7 +875,7 @@ pub const BuildExamplesContext = struct {
self.step.dependOn(&log_step.step);
}
pub fn addAllArgs(self: *BuildExamplesContext, root_src: []const u8, link_libc: bool) void {
pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void {
const b = self.b;
for (self.modes) |mode| {