add library for stuff
This commit is contained in:
		
							parent
							
								
									110e306e05
								
							
						
					
					
						commit
						08dec6a978
					
				
					 2 changed files with 37 additions and 12 deletions
				
			
		
							
								
								
									
										39
									
								
								build.zig
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								build.zig
									
										
									
									
									
								
							|  | @ -24,11 +24,25 @@ pub fn build(b: *std.Build) void { | ||||||
|         .optimize = optimize, |         .optimize = optimize, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |     const lib = b.addSharedLibrary(.{ | ||||||
|  |         .name = "faas-proxy-sample-lib", | ||||||
|  |         // In this case the main source file is merely a path, however, in more | ||||||
|  |         // complicated build scripts, this could be a generated file. | ||||||
|  |         .root_source_file = .{ .path = "src/main-lib.zig" }, | ||||||
|  |         .target = target, | ||||||
|  |         .optimize = optimize, | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     // This declares intent for the executable to be installed into the |     // This declares intent for the executable to be installed into the | ||||||
|     // standard location when the user invokes the "install" step (the default |     // standard location when the user invokes the "install" step (the default | ||||||
|     // step when running `zig build`). |     // step when running `zig build`). | ||||||
|     b.installArtifact(exe); |     b.installArtifact(exe); | ||||||
| 
 | 
 | ||||||
|  |     // This declares intent for the library to be installed into the standard | ||||||
|  |     // location when the user invokes the "install" step (the default step when | ||||||
|  |     // running `zig build`). | ||||||
|  |     b.installArtifact(lib); | ||||||
|  | 
 | ||||||
|     // This *creates* a RunStep in the build graph, to be executed when another |     // This *creates* a RunStep in the build graph, to be executed when another | ||||||
|     // step is evaluated that depends on it. The next line below will establish |     // step is evaluated that depends on it. The next line below will establish | ||||||
|     // such a dependency. |     // such a dependency. | ||||||
|  | @ -46,25 +60,26 @@ pub fn build(b: *std.Build) void { | ||||||
|         run_cmd.addArgs(args); |         run_cmd.addArgs(args); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // This creates a build step. It will be visible in the `zig build --help` menu, |  | ||||||
|     // and can be selected like this: `zig build run` |  | ||||||
|     // This will evaluate the `run` step rather than the default, which is "install". |  | ||||||
|     const run_step = b.step("run", "Run the app"); |  | ||||||
|     run_step.dependOn(&run_cmd.step); |  | ||||||
| 
 |  | ||||||
|     // Creates a step for unit testing. This only builds the test executable |     // Creates a step for unit testing. This only builds the test executable | ||||||
|     // but does not run it. |     // but does not run it. | ||||||
|     const unit_tests = b.addTest(.{ |     const main_tests = b.addTest(.{ | ||||||
|         .root_source_file = .{ .path = "src/main.zig" }, |         .root_source_file = .{ .path = "src/main.zig" }, | ||||||
|         .target = target, |         .target = target, | ||||||
|         .optimize = optimize, |         .optimize = optimize, | ||||||
|     }); |     }); | ||||||
|  |     const lib_tests = b.addTest(.{ | ||||||
|  |         .root_source_file = .{ .path = "src/main-lib.zig" }, | ||||||
|  |         .target = target, | ||||||
|  |         .optimize = optimize, | ||||||
|  |     }); | ||||||
| 
 | 
 | ||||||
|     const run_unit_tests = b.addRunArtifact(unit_tests); |     const run_main_tests = b.addRunArtifact(main_tests); | ||||||
|  |     const run_lib_tests = b.addRunArtifact(lib_tests); | ||||||
| 
 | 
 | ||||||
|     // Similar to creating the run step earlier, this exposes a `test` step to |     // This creates a build step. It will be visible in the `zig build --help` menu, | ||||||
|     // the `zig build --help` menu, providing a way for the user to request |     // and can be selected like this: `zig build test` | ||||||
|     // running the unit tests. |     // This will evaluate the `test` step rather than the default, which is "install". | ||||||
|     const test_step = b.step("test", "Run unit tests"); |     const test_step = b.step("test", "Run unit tests"); | ||||||
|     test_step.dependOn(&run_unit_tests.step); |     test_step.dependOn(&run_main_tests.step); | ||||||
|  |     test_step.dependOn(&run_lib_tests.step); | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/main-lib.zig
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/main-lib.zig
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | ||||||
|  | const std = @import("std"); | ||||||
|  | const testing = std.testing; | ||||||
|  | 
 | ||||||
|  | export fn add(a: i32, b: i32) i32 { | ||||||
|  |     return a + b; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | test "basic add functionality" { | ||||||
|  |     try testing.expect(add(3, 7) == 10); | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue