11const std = @import ("std" );
22
33fn buildSecp256k1 (libsecp_c : * std.Build.Dependency , b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) ! * std.Build.Step.Compile {
4- const lib = b .addStaticLibrary (.{
4+ const lib = b .addLibrary (.{
5+ .linkage = .static ,
56 .name = "libsecp" ,
6- .target = target ,
7- .optimize = optimize ,
8- .root_source_file = b .path ("src/secp256k1.zig" ),
7+ .root_module = b .createModule (.{
8+ .target = target ,
9+ .optimize = optimize ,
10+ .root_source_file = b .path ("src/secp256k1.zig" ),
11+ }),
912 });
1013
1114 lib .addIncludePath (libsecp_c .path ("" ));
1215 lib .addIncludePath (libsecp_c .path ("src" ));
1316 lib .addIncludePath (libsecp_c .path ("include" ));
1417
15- var flags = std .ArrayList ([]const u8 ).init (b .allocator );
16- defer flags .deinit ();
17-
18- try flags .appendSlice (&.{"-DENABLE_MODULE_RECOVERY=1" });
19- try flags .appendSlice (&.{"-DENABLE_MODULE_SCHNORRSIG=1" });
20- try flags .appendSlice (&.{"-DENABLE_MODULE_ECDH=1" });
21- try flags .appendSlice (&.{"-DENABLE_MODULE_EXTRAKEYS=1" });
22-
2318 lib .addCSourceFiles (.{
2419 .root = libsecp_c .path ("" ),
25- .flags = flags .items ,
20+ .flags = &.{
21+ "-DENABLE_MODULE_RECOVERY=1" ,
22+ "-DENABLE_MODULE_SCHNORRSIG=1" ,
23+ "-DENABLE_MODULE_ECDH=1" ,
24+ "-DENABLE_MODULE_EXTRAKEYS=1" ,
25+ },
2626 .files = &.{
2727 "./src/secp256k1.c" ,
2828 "./src/precomputed_ecmult.c" ,
@@ -58,10 +58,7 @@ pub fn build(b: *std.Build) !void {
5858 // set a preferred release mode, allowing the user to decide how to optimize.
5959 const optimize = b .standardOptimizeOption (.{});
6060
61- const libsecp_c = b .dependency ("libsecp256k1" , .{
62- .target = target ,
63- .optimize = optimize ,
64- });
61+ const libsecp_c = b .dependency ("libsecp256k1" , .{});
6562
6663 // libsecp256k1 static C library.
6764 const libsecp256k1 = try buildSecp256k1 (libsecp_c , b , target , optimize );
@@ -80,21 +77,25 @@ pub fn build(b: *std.Build) !void {
8077 // Creates a step for unit testing. This only builds the test executable
8178 // but does not run it.
8279 const lib_unit_tests = b .addTest (.{
83- .root_source_file = b .path ("src/secp256k1.zig" ),
84- .target = target ,
80+ .root_module = b .createModule (.{
81+ .root_source_file = b .path ("src/secp256k1.zig" ),
82+ .target = target ,
83+ }),
8584 });
8685 lib_unit_tests .linkLibrary (libsecp256k1 );
8786 const run_lib_unit_tests = b .addRunArtifact (lib_unit_tests );
8887
8988 const example_tests = b .addTest (.{
90- .root_source_file = b .path ("src/examples.zig" ),
91- .target = target ,
89+ .root_module = b .createModule (.{
90+ .root_source_file = b .path ("src/examples.zig" ),
91+ .target = target ,
92+ }),
9293 });
9394 example_tests .linkLibrary (libsecp256k1 );
9495 const run_example_test = b .addRunArtifact (example_tests );
9596
9697 // Similar to creating the run step earlier, this exposes a `test` step to
97- // the `zig build --help ` menu, providing a way for the user to request
98+ // the `` menu, providing a way for the user to request
9899 // running the unit tests.
99100 const test_step = b .step ("test" , "Run tests" );
100101 test_step .dependOn (& run_lib_unit_tests .step );
0 commit comments