commit 9dcddc2249217c8c99c9d07bb0187904847d2ae2 (tree) parent 92e781baa147a7d07af4cb3c1f08c08bed8613e4 Author: Andrew Kelley <andrew@ziglang.org> Date: Tue, 16 Jul 2019 12:15:46 -0400 retire the example/ folder, rename test-build-examples to "standalone" closes #2759 Diffstat:
16 files changed, 43 insertions(+), 65 deletions(-)
diff --git a/build.zig b/build.zig @@ -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)); diff --git a/example/README.md b/example/README.md @@ -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 diff --git a/example/hello_world/hello_windows.zig b/example/hello_world/hello_windows.zig @@ -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; -} diff --git a/test/build_examples.zig b/test/build_examples.zig @@ -1,31 +0,0 @@ -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"); - 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/static_c_lib/build.zig"); - cases.addBuildFile("test/standalone/issue_339/build.zig"); - cases.addBuildFile("test/standalone/issue_794/build.zig"); - cases.addBuildFile("test/standalone/pkg_import/build.zig"); - cases.addBuildFile("test/standalone/use_alias/build.zig"); - cases.addBuildFile("test/standalone/brace_expansion/build.zig"); - cases.addBuildFile("test/standalone/empty_env/build.zig"); - if (builtin.os == builtin.Os.linux) { - // TODO hook up the DynLib API for windows using LoadLibraryA - // TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it - cases.addBuildFile("test/standalone/load_dynamic_library/build.zig"); - } - - if (builtin.arch == builtin.Arch.x86_64) { // TODO add C ABI support for other architectures - cases.addBuildFile("test/stage1/c_abi/build.zig"); - } -} diff --git a/test/standalone.zig b/test/standalone.zig @@ -0,0 +1,31 @@ +const tests = @import("tests.zig"); +const builtin = @import("builtin"); +const is_windows = builtin.os == builtin.Os.windows; + +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("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"); + cases.addBuildFile("test/standalone/pkg_import/build.zig"); + cases.addBuildFile("test/standalone/use_alias/build.zig"); + cases.addBuildFile("test/standalone/brace_expansion/build.zig"); + cases.addBuildFile("test/standalone/empty_env/build.zig"); + if (builtin.os == builtin.Os.linux) { + // TODO hook up the DynLib API for windows using LoadLibraryA + // TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it + cases.addBuildFile("test/standalone/load_dynamic_library/build.zig"); + } + + if (builtin.arch == builtin.Arch.x86_64) { // TODO add C ABI support for other architectures + cases.addBuildFile("test/stage1/c_abi/build.zig"); + } +} diff --git a/example/cat/main.zig b/test/standalone/cat/main.zig diff --git a/example/guess_number/main.zig b/test/standalone/guess_number/main.zig diff --git a/example/hello_world/hello.zig b/test/standalone/hello_world/hello.zig diff --git a/example/hello_world/hello_libc.zig b/test/standalone/hello_world/hello_libc.zig diff --git a/example/mix_o_files/base64.zig b/test/standalone/mix_o_files/base64.zig diff --git a/example/mix_o_files/build.zig b/test/standalone/mix_o_files/build.zig diff --git a/example/mix_o_files/test.c b/test/standalone/mix_o_files/test.c diff --git a/example/shared_library/build.zig b/test/standalone/shared_library/build.zig diff --git a/example/shared_library/mathtest.zig b/test/standalone/shared_library/mathtest.zig diff --git a/example/shared_library/test.c b/test/standalone/shared_library/test.c diff --git a/test/tests.zig b/test/tests.zig @@ -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| {