| author | |
| committer | |
| log | 085cc54aadb327b9910be2c72b31ea046e7e8f52 |
| tree | 3474fea2fe14b4c69cdfa7022db760db82f9dce4 |
| parent | 0e876a6378b5380900cf8755f624a670e8716f80 |
2 files changed, 82 insertions(+), 36 deletions(-)
lib/std/Build/Module.zig+39-30| ... | ... | @@ -135,6 +135,44 @@ pub const IncludeDir = union(enum) { |
| 135 | 135 | framework_path_system: LazyPath, |
| 136 | 136 | other_step: *Step.Compile, |
| 137 | 137 | config_header_step: *Step.ConfigHeader, |
| 138 | ||
| 139 | pub fn appendZigProcessFlags( | |
| 140 | include_dir: IncludeDir, | |
| 141 | b: *std.Build, | |
| 142 | zig_args: *std.ArrayList([]const u8), | |
| 143 | asking_step: ?*Step, | |
| 144 | ) !void { | |
| 145 | switch (include_dir) { | |
| 146 | .path => |include_path| { | |
| 147 | try zig_args.appendSlice(&.{ "-I", include_path.getPath2(b, asking_step) }); | |
| 148 | }, | |
| 149 | .path_system => |include_path| { | |
| 150 | try zig_args.appendSlice(&.{ "-isystem", include_path.getPath2(b, asking_step) }); | |
| 151 | }, | |
| 152 | .path_after => |include_path| { | |
| 153 | try zig_args.appendSlice(&.{ "-idirafter", include_path.getPath2(b, asking_step) }); | |
| 154 | }, | |
| 155 | .framework_path => |include_path| { | |
| 156 | try zig_args.appendSlice(&.{ "-F", include_path.getPath2(b, asking_step) }); | |
| 157 | }, | |
| 158 | .framework_path_system => |include_path| { | |
| 159 | try zig_args.appendSlice(&.{ "-iframework", include_path.getPath2(b, asking_step) }); | |
| 160 | }, | |
| 161 | .other_step => |other| { | |
| 162 | if (other.generated_h) |header| { | |
| 163 | try zig_args.appendSlice(&.{ "-isystem", std.fs.path.dirname(header.getPath()).? }); | |
| 164 | } | |
| 165 | if (other.installed_headers_include_tree) |include_tree| { | |
| 166 | try zig_args.appendSlice(&.{ "-I", include_tree.generated_directory.getPath() }); | |
| 167 | } | |
| 168 | }, | |
| 169 | .config_header_step => |config_header| { | |
| 170 | const full_file_path = config_header.output_file.getPath(); | |
| 171 | const header_dir_path = full_file_path[0 .. full_file_path.len - config_header.include_path.len]; | |
| 172 | try zig_args.appendSlice(&.{ "-I", header_dir_path }); | |
| 173 | }, | |
| 174 | } | |
| 175 | } | |
| 138 | 176 | }; |
| 139 | 177 | |
| 140 | 178 | pub const LinkFrameworkOptions = struct { |
| ... | ... | @@ -690,36 +728,7 @@ pub fn appendZigProcessFlags( |
| 690 | 728 | } |
| 691 | 729 | |
| 692 | 730 | for (m.include_dirs.items) |include_dir| { |
| 693 | switch (include_dir) { | |
| 694 | .path => |include_path| { | |
| 695 | try zig_args.appendSlice(&.{ "-I", include_path.getPath2(b, asking_step) }); | |
| 696 | }, | |
| 697 | .path_system => |include_path| { | |
| 698 | try zig_args.appendSlice(&.{ "-isystem", include_path.getPath2(b, asking_step) }); | |
| 699 | }, | |
| 700 | .path_after => |include_path| { | |
| 701 | try zig_args.appendSlice(&.{ "-idirafter", include_path.getPath2(b, asking_step) }); | |
| 702 | }, | |
| 703 | .framework_path => |include_path| { | |
| 704 | try zig_args.appendSlice(&.{ "-F", include_path.getPath2(b, asking_step) }); | |
| 705 | }, | |
| 706 | .framework_path_system => |include_path| { | |
| 707 | try zig_args.appendSlice(&.{ "-iframework", include_path.getPath2(b, asking_step) }); | |
| 708 | }, | |
| 709 | .other_step => |other| { | |
| 710 | if (other.generated_h) |header| { | |
| 711 | try zig_args.appendSlice(&.{ "-isystem", std.fs.path.dirname(header.getPath()).? }); | |
| 712 | } | |
| 713 | if (other.installed_headers_include_tree) |include_tree| { | |
| 714 | try zig_args.appendSlice(&.{ "-I", include_tree.generated_directory.getPath() }); | |
| 715 | } | |
| 716 | }, | |
| 717 | .config_header_step => |config_header| { | |
| 718 | const full_file_path = config_header.output_file.getPath(); | |
| 719 | const header_dir_path = full_file_path[0 .. full_file_path.len - config_header.include_path.len]; | |
| 720 | try zig_args.appendSlice(&.{ "-I", header_dir_path }); | |
| 721 | }, | |
| 722 | } | |
| 731 | try include_dir.appendZigProcessFlags(b, zig_args, asking_step); | |
| 723 | 732 | } |
| 724 | 733 | |
| 725 | 734 | try zig_args.appendSlice(m.c_macros.items); |
lib/std/Build/Step/TranslateC.zig+43-6| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Step = std.Build.Step; |
| 3 | const LazyPath = std.Build.LazyPath; | |
| 3 | 4 | const fs = std.fs; |
| 4 | 5 | const mem = std.mem; |
| 5 | 6 | |
| ... | ... | @@ -9,7 +10,7 @@ pub const base_id: Step.Id = .translate_c; |
| 9 | 10 | |
| 10 | 11 | step: Step, |
| 11 | 12 | source: std.Build.LazyPath, |
| 12 | include_dirs: std.ArrayList([]const u8), | |
| 13 | include_dirs: std.ArrayList(std.Build.Module.IncludeDir), | |
| 13 | 14 | c_macros: std.ArrayList([]const u8), |
| 14 | 15 | out_basename: []const u8, |
| 15 | 16 | target: std.Build.ResolvedTarget, |
| ... | ... | @@ -37,7 +38,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC { |
| 37 | 38 | .makeFn = make, |
| 38 | 39 | }), |
| 39 | 40 | .source = source, |
| 40 | .include_dirs = std.ArrayList([]const u8).init(owner.allocator), | |
| 41 | .include_dirs = std.ArrayList(std.Build.Module.IncludeDir).init(owner.allocator), | |
| 41 | 42 | .c_macros = std.ArrayList([]const u8).init(owner.allocator), |
| 42 | 43 | .out_basename = undefined, |
| 43 | 44 | .target = options.target, |
| ... | ... | @@ -95,8 +96,45 @@ pub fn createModule(translate_c: *TranslateC) *std.Build.Module { |
| 95 | 96 | }); |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | pub fn addIncludeDir(translate_c: *TranslateC, include_dir: []const u8) void { | |
| 99 | translate_c.include_dirs.append(translate_c.step.owner.dupePath(include_dir)) catch @panic("OOM"); | |
| 99 | pub fn addAfterIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void { | |
| 100 | const b = translate_c.step.owner; | |
| 101 | translate_c.include_dirs.append(.{ .path_after = lazy_path.dupe(b) }) catch | |
| 102 | @panic("OOM"); | |
| 103 | lazy_path.addStepDependencies(&translate_c.step); | |
| 104 | } | |
| 105 | ||
| 106 | pub fn addSystemIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void { | |
| 107 | const b = translate_c.step.owner; | |
| 108 | translate_c.include_dirs.append(.{ .path_system = lazy_path.dupe(b) }) catch | |
| 109 | @panic("OOM"); | |
| 110 | lazy_path.addStepDependencies(&translate_c.step); | |
| 111 | } | |
| 112 | ||
| 113 | pub fn addIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void { | |
| 114 | const b = translate_c.step.owner; | |
| 115 | translate_c.include_dirs.append(.{ .path = lazy_path.dupe(b) }) catch | |
| 116 | @panic("OOM"); | |
| 117 | lazy_path.addStepDependencies(&translate_c.step); | |
| 118 | } | |
| 119 | ||
| 120 | pub fn addConfigHeader(translate_c: *TranslateC, config_header: *Step.ConfigHeader) void { | |
| 121 | translate_c.include_dirs.append(.{ .config_header_step = config_header }) catch | |
| 122 | @panic("OOM"); | |
| 123 | translate_c.step.dependOn(&config_header.step); | |
| 124 | } | |
| 125 | ||
| 126 | pub fn addSystemFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void { | |
| 127 | const b = translate_c.step.owner; | |
| 128 | translate_c.include_dirs.append(.{ .framework_path_system = directory_path.dupe(b) }) catch | |
| 129 | @panic("OOM"); | |
| 130 | directory_path.addStepDependencies(&translate_c.step); | |
| 131 | } | |
| 132 | ||
| 133 | pub fn addFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void { | |
| 134 | const b = translate_c.step.owner; | |
| 135 | translate_c.include_dirs.append(.{ .framework_path = directory_path.dupe(b) }) catch | |
| 136 | @panic("OOM"); | |
| 137 | directory_path.addStepDependencies(&translate_c.step); | |
| 100 | 138 | } |
| 101 | 139 | |
| 102 | 140 | pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile { |
| ... | ... | @@ -147,8 +185,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 147 | 185 | } |
| 148 | 186 | |
| 149 | 187 | for (translate_c.include_dirs.items) |include_dir| { |
| 150 | try argv_list.append("-I"); | |
| 151 | try argv_list.append(include_dir); | |
| 188 | try include_dir.appendZigProcessFlags(b, &argv_list, step); | |
| 152 | 189 | } |
| 153 | 190 | |
| 154 | 191 | for (translate_c.c_macros.items) |c_macro| { |