-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89d14a4
commit b0bde50
Showing
15 changed files
with
6,273 additions
and
6,388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const std = @import("std"); | ||
|
||
/// Represents a dependency on an external package. | ||
pub const Dependency = struct { | ||
name: []const u8, | ||
module_name: []const u8, | ||
}; | ||
|
||
/// Generate an array of Build.Module.Import from the external dependencies. | ||
/// # Arguments | ||
/// * `b` - The build object. | ||
/// * `external_dependencies` - The external dependencies. | ||
/// * `dependencies_opts` - The options to use when generating the dependency modules. | ||
/// # Returns | ||
/// A new array of Build.Module.Import. | ||
pub fn generateModuleDependencies( | ||
b: *std.Build, | ||
external_dependencies: []const Dependency, | ||
dependencies_opts: anytype, | ||
) ![]std.Build.Module.Import { | ||
var dependency_modules = std.ArrayList(*std.Build.Module).init(b.allocator); | ||
defer _ = dependency_modules.deinit(); | ||
|
||
// Populate dependency modules. | ||
for (external_dependencies) |dep| { | ||
const module = b.dependency( | ||
dep.name, | ||
dependencies_opts, | ||
).module(dep.module_name); | ||
_ = dependency_modules.append(module) catch unreachable; | ||
} | ||
return try toModuleDependencyArray( | ||
b.allocator, | ||
dependency_modules.items, | ||
external_dependencies, | ||
); | ||
} | ||
|
||
/// Convert an array of Build.Module pointers to an array of Build.Module.Import. | ||
/// # Arguments | ||
/// * `allocator` - The allocator to use for the new array. | ||
/// * `modules` - The array of Build.Module pointers to convert. | ||
/// * `ext_deps` - The array of external dependencies. | ||
/// # Returns | ||
/// A new array of Build.Module.Import. | ||
fn toModuleDependencyArray( | ||
allocator: std.mem.Allocator, | ||
modules: []const *std.Build.Module, | ||
ext_deps: []const Dependency, | ||
) ![]std.Build.Module.Import { | ||
var deps = std.ArrayList(std.Build.Module.Import).init(allocator); | ||
defer deps.deinit(); | ||
|
||
for ( | ||
modules, | ||
0.., | ||
) |module_ptr, i| { | ||
try deps.append(.{ | ||
.name = ext_deps[i].name, | ||
.module = module_ptr, | ||
}); | ||
} | ||
|
||
return deps.toOwnedSlice(); | ||
} |
Oops, something went wrong.