authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-30 19:48:45-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-30 19:48:45-04:00
log1ec89b02866cdf14b1c4309bbae7d4f5e4ee6ae7
treedadc6d9470a40c331825778ab82e62d6fc822e1b
parent363d9038c9b52878054505e905e133310b53086e

zig build: refactor CLibrary and CExecutable into same struct


1 files changed, 216 insertions(+), 246 deletions(-)

std/build.zig+216-246
...@@ -151,22 +151,20 @@ pub const Builder = struct {...@@ -151,22 +151,20 @@ pub const Builder = struct {
151 return obj_step;151 return obj_step;
152 }152 }
153153
154 pub fn addCStaticLibrary(self: &Builder, name: []const u8) -> &CLibrary {154 pub fn addCStaticLibrary(self: &Builder, name: []const u8) -> &CLibExeObjStep {
155 const lib = %%self.allocator.create(CLibrary);155 return CLibExeObjStep.createStaticLibrary(self, name);
156 *lib = CLibrary.initStatic(self, name);
157 return lib;
158 }156 }
159157
160 pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) -> &CLibrary {158 pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) -> &CLibExeObjStep {
161 const lib = %%self.allocator.create(CLibrary);159 return CLibExeObjStep.createSharedLibrary(self, name, ver);
162 *lib = CLibrary.initShared(self, name, ver);
163 return lib;
164 }160 }
165161
166 pub fn addCExecutable(self: &Builder, name: []const u8) -> &CExecutable {162 pub fn addCExecutable(self: &Builder, name: []const u8) -> &CLibExeObjStep {
167 const exe = %%self.allocator.create(CExecutable);163 return CLibExeObjStep.createExecutable(self, name);
168 *exe = CExecutable.init(self, name);164 }
169 return exe;165
166 pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) -> &CLibExeObjStep {
167 return CLibExeObjStep.createObject(self, name, src);
170 }168 }
171169
172 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,170 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
...@@ -533,7 +531,7 @@ pub const Builder = struct {...@@ -533,7 +531,7 @@ pub const Builder = struct {
533 };531 };
534 }532 }
535533
536 pub fn installCLibrary(self: &Builder, lib: &CLibrary) -> &InstallCLibraryStep {534 pub fn installCLibrary(self: &Builder, lib: &CLibExeObjStep) -> &InstallCLibraryStep {
537 const install_step = %%self.allocator.create(InstallCLibraryStep);535 const install_step = %%self.allocator.create(InstallCLibraryStep);
538 *install_step = InstallCLibraryStep.init(self, lib);536 *install_step = InstallCLibraryStep.init(self, lib);
539 install_step.step.dependOn(&lib.step);537 install_step.step.dependOn(&lib.step);
...@@ -1007,8 +1005,7 @@ pub const TestStep = struct {...@@ -1007,8 +1005,7 @@ pub const TestStep = struct {
1007 }1005 }
1008};1006};
10091007
1010// TODO merge with CExecutable1008pub const CLibExeObjStep = struct {
1011pub const CLibrary = struct {
1012 step: Step,1009 step: Step,
1013 name: []const u8,1010 name: []const u8,
1014 out_filename: []const u8,1011 out_filename: []const u8,
...@@ -1019,24 +1016,51 @@ pub const CLibrary = struct {...@@ -1019,24 +1016,51 @@ pub const CLibrary = struct {
1019 source_files: List([]const u8),1016 source_files: List([]const u8),
1020 object_files: List([]const u8),1017 object_files: List([]const u8),
1021 link_libs: BufSet,1018 link_libs: BufSet,
1019 full_path_libs: List([]const u8),
1022 target: Target,1020 target: Target,
1023 builder: &Builder,1021 builder: &Builder,
1024 include_dirs: List([]const u8),1022 include_dirs: List([]const u8),
1025 major_only_filename: []const u8,1023 major_only_filename: []const u8,
1026 name_only_filename: []const u8,1024 name_only_filename: []const u8,
1025 object_src: []const u8,
1026 kind: Kind,
10271027
1028 pub fn initShared(builder: &Builder, name: []const u8, version: &const Version) -> CLibrary {1028 const Kind = enum {
1029 return init(builder, name, version, false);1029 Exe,
1030 Lib,
1031 Obj,
1032 };
1033
1034 pub fn createSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) -> &CLibExeObjStep {
1035 const self = %%builder.allocator.create(CLibExeObjStep);
1036 *self = init(builder, name, Kind.Lib, builder.version(0, 0, 0), false);
1037 return self;
1030 }1038 }
10311039
1032 pub fn initStatic(builder: &Builder, name: []const u8) -> CLibrary {1040 pub fn createStaticLibrary(builder: &Builder, name: []const u8) -> &CLibExeObjStep {
1033 return init(builder, name, builder.version(0, 0, 0), true);1041 const self = %%builder.allocator.create(CLibExeObjStep);
1042 *self = init(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
1043 return self;
1034 }1044 }
10351045
1036 fn init(builder: &Builder, name: []const u8, version: &const Version, static: bool) -> CLibrary {1046 pub fn createObject(builder: &Builder, name: []const u8, src: []const u8) -> &CLibExeObjStep {
1037 var clib = CLibrary {1047 const self = %%builder.allocator.create(CLibExeObjStep);
1048 *self = init(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
1049 self.object_src = src;
1050 return self;
1051 }
1052
1053 pub fn createExecutable(builder: &Builder, name: []const u8) -> &CLibExeObjStep {
1054 const self = %%builder.allocator.create(CLibExeObjStep);
1055 *self = init(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
1056 return self;
1057 }
1058
1059 fn init(builder: &Builder, name: []const u8, kind: Kind, version: &const Version, static: bool) -> CLibExeObjStep {
1060 var clib = CLibExeObjStep {
1038 .builder = builder,1061 .builder = builder,
1039 .name = name,1062 .name = name,
1063 .kind = kind,
1040 .version = *version,1064 .version = *version,
1041 .static = static,1065 .static = static,
1042 .target = Target.Native,1066 .target = Target.Native,
...@@ -1045,32 +1069,44 @@ pub const CLibrary = struct {...@@ -1045,32 +1069,44 @@ pub const CLibrary = struct {
1045 .object_files = List([]const u8).init(builder.allocator),1069 .object_files = List([]const u8).init(builder.allocator),
1046 .step = Step.init(name, builder.allocator, make),1070 .step = Step.init(name, builder.allocator, make),
1047 .link_libs = BufSet.init(builder.allocator),1071 .link_libs = BufSet.init(builder.allocator),
1072 .full_path_libs = List([]const u8).init(builder.allocator),
1048 .include_dirs = List([]const u8).init(builder.allocator),1073 .include_dirs = List([]const u8).init(builder.allocator),
1049 .output_path = null,1074 .output_path = null,
1050 .out_filename = undefined,1075 .out_filename = undefined,
1051 .major_only_filename = undefined,1076 .major_only_filename = undefined,
1052 .name_only_filename = undefined,1077 .name_only_filename = undefined,
1078 .object_src = undefined,
1053 };1079 };
1054 clib.computeOutFileName();1080 clib.computeOutFileNames();
1055 return clib;1081 return clib;
1056 }1082 }
10571083
1058 fn computeOutFileName(self: &CLibrary) {1084 fn computeOutFileNames(self: &CLibExeObjStep) {
1059 if (self.static) {1085 switch (self.kind) {
1060 self.out_filename = self.builder.fmt("lib{}.a", self.name);1086 Kind.Obj => {
1061 } else {1087 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
1062 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}",1088 },
1063 self.name, self.version.major, self.version.minor, self.version.patch);1089 Kind.Exe => {
1064 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major);1090 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
1065 self.name_only_filename = self.builder.fmt("lib{}.so", self.name);1091 },
1092 Kind.Lib => {
1093 if (self.static) {
1094 self.out_filename = self.builder.fmt("lib{}.a", self.name);
1095 } else {
1096 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}",
1097 self.name, self.version.major, self.version.minor, self.version.patch);
1098 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major);
1099 self.name_only_filename = self.builder.fmt("lib{}.so", self.name);
1100 }
1101 },
1066 }1102 }
1067 }1103 }
10681104
1069 pub fn setOutputPath(self: &CLibrary, value: []const u8) {1105 pub fn setOutputPath(self: &CLibExeObjStep, value: []const u8) {
1070 self.output_path = value;1106 self.output_path = value;
1071 }1107 }
10721108
1073 pub fn getOutputPath(self: &CLibrary) -> []const u8 {1109 pub fn getOutputPath(self: &CLibExeObjStep) -> []const u8 {
1074 test (self.output_path) |output_path| {1110 test (self.output_path) |output_path| {
1075 output_path1111 output_path
1076 } else {1112 } else {
...@@ -1079,28 +1115,54 @@ pub const CLibrary = struct {...@@ -1079,28 +1115,54 @@ pub const CLibrary = struct {
1079 }1115 }
1080 }1116 }
10811117
1082 pub fn linkSystemLibrary(self: &CLibrary, name: []const u8) {1118 pub fn linkLibrary(self: &CLibExeObjStep, lib: &LibExeObjStep) {
1119 assert(self.kind != Kind.Obj);
1120 assert(lib.kind == LibExeObjStep.Kind.Lib);
1121 self.step.dependOn(&lib.step);
1122 %%self.full_path_libs.append(lib.getOutputPath());
1123 // TODO should be some kind of isolated directory that only has this header in it
1124 %%self.include_dirs.append(self.builder.cache_root);
1125 }
1126
1127 pub fn linkSystemLibrary(self: &CLibExeObjStep, name: []const u8) {
1128 assert(self.kind != Kind.Obj);
1083 %%self.link_libs.put(name);1129 %%self.link_libs.put(name);
1084 }1130 }
10851131
1086 pub fn linkCLibrary(self: &CLibrary, other: &CLibrary) {1132 pub fn linkCLibrary(self: &CLibExeObjStep, other: &CLibExeObjStep) {
1133 assert(self.kind != Kind.Obj);
1134 assert(other.kind == Kind.Lib);
1087 self.step.dependOn(&other.step);1135 self.step.dependOn(&other.step);
1088 %%self.link_libs.put(other.name);1136 %%self.full_path_libs.append(other.getOutputPath());
1089 }1137 }
10901138
1091 pub fn addSourceFile(self: &CLibrary, file: []const u8) {1139 pub fn addSourceFile(self: &CLibExeObjStep, file: []const u8) {
1140 assert(self.kind != Kind.Obj);
1092 %%self.source_files.append(file);1141 %%self.source_files.append(file);
1093 }1142 }
10941143
1095 pub fn addObjectFile(self: &CLibrary, file: []const u8) {1144 pub fn addObjectFile(self: &CLibExeObjStep, file: []const u8) {
1145 assert(self.kind != Kind.Obj);
1096 %%self.object_files.append(file);1146 %%self.object_files.append(file);
1097 }1147 }
10981148
1099 pub fn addIncludeDir(self: &CLibrary, path: []const u8) {1149 pub fn addObject(self: &CLibExeObjStep, obj: &LibExeObjStep) {
1150 assert(self.kind != Kind.Obj);
1151 assert(obj.kind == LibExeObjStep.Kind.Obj);
1152
1153 self.step.dependOn(&obj.step);
1154
1155 %%self.object_files.append(obj.getOutputPath());
1156
1157 // TODO should be some kind of isolated directory that only has this header in it
1158 %%self.include_dirs.append(self.builder.cache_root);
1159 }
1160
1161 pub fn addIncludeDir(self: &CLibExeObjStep, path: []const u8) {
1100 %%self.include_dirs.append(path);1162 %%self.include_dirs.append(path);
1101 }1163 }
11021164
1103 pub fn addCompileFlagsForRelease(self: &CLibrary, release: bool) {1165 pub fn addCompileFlagsForRelease(self: &CLibExeObjStep, release: bool) {
1104 if (release) {1166 if (release) {
1105 %%self.cflags.append("-g");1167 %%self.cflags.append("-g");
1106 %%self.cflags.append("-O2");1168 %%self.cflags.append("-O2");
...@@ -1109,256 +1171,164 @@ pub const CLibrary = struct {...@@ -1109,256 +1171,164 @@ pub const CLibrary = struct {
1109 }1171 }
1110 }1172 }
11111173
1112 pub fn addCompileFlags(self: &CLibrary, flags: []const []const u8) {1174 pub fn addCompileFlags(self: &CLibExeObjStep, flags: []const []const u8) {
1113 for (flags) |flag| {1175 for (flags) |flag| {
1114 %%self.cflags.append(flag);1176 %%self.cflags.append(flag);
1115 }1177 }
1116 }1178 }
11171179
1118 fn make(step: &Step) -> %void {1180 fn make(step: &Step) -> %void {
1119 const self = @fieldParentPtr(CLibrary, "step", step);1181 const self = @fieldParentPtr(CLibExeObjStep, "step", step);
1120 const cc = os.getEnv("CC") ?? "cc";1182 const cc = os.getEnv("CC") ?? "cc";
1121 const builder = self.builder;1183 const builder = self.builder;
11221184
1123 var cc_args = List([]const u8).init(builder.allocator);1185 var cc_args = List([]const u8).init(builder.allocator);
1124 defer cc_args.deinit();1186 defer cc_args.deinit();
11251187
1126 for (self.source_files.toSliceConst()) |source_file| {1188 switch (self.kind) {
1127 %%cc_args.resize(0);1189 Kind.Obj => {
11281190 %%cc_args.append("-c");
1129 if (!self.static) {1191 %%cc_args.append(builder.pathFromRoot(self.object_src));
1130 %%cc_args.append("-fPIC");
1131 }
1132
1133 %%cc_args.append("-c");
1134 %%cc_args.append(source_file);
1135
1136 const rel_src_path = %%os.path.relative(builder.allocator, builder.build_root, source_file);
1137 const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, rel_src_path);
1138 const cache_o_dir = os.path.dirname(cache_o_src);
1139 %return builder.makePath(cache_o_dir);
1140 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
1141 %%cc_args.append("-o");
1142 %%cc_args.append(cache_o_file);
1143
1144 for (self.cflags.toSliceConst()) |cflag| {
1145 %%cc_args.append(cflag);
1146 }
1147
1148 for (self.include_dirs.toSliceConst()) |dir| {
1149 %%cc_args.append("-I");
1150 %%cc_args.append(dir);
1151 }
1152
1153 %return builder.spawnChild(cc, cc_args.toSliceConst());
1154
1155 %%self.object_files.append(cache_o_file);
1156 }
1157
1158 if (self.static) {
1159 debug.panic("TODO static library");
1160 } else {
1161 %%cc_args.resize(0);
1162
1163 %%cc_args.append("-fPIC");
1164 %%cc_args.append("-shared");
1165
1166 const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major);
1167 defer builder.allocator.free(soname_arg);
1168 %%cc_args.append(soname_arg);
1169
1170 const output_path = builder.pathFromRoot(self.getOutputPath());
1171 %%cc_args.append("-o");
1172 %%cc_args.append(output_path);
1173
1174 for (self.object_files.toSliceConst()) |object_file| {
1175 %%cc_args.append(builder.pathFromRoot(object_file));
1176 }
1177
1178 %return builder.spawnChild(cc, cc_args.toSliceConst());
1179
1180 %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename,
1181 self.name_only_filename);
1182 }
1183 }
1184
1185 pub fn setTarget(self: &CLibrary, target_arch: Arch, target_os: Os, target_environ: Environ) {
1186 self.target = Target.Cross {
1187 CrossTarget {
1188 .arch = target_arch,
1189 .os = target_os,
1190 .environ = target_environ,
1191 }
1192 };
1193 }
1194};
1195
1196pub const CExecutable = struct {
1197 step: Step,
1198 builder: &Builder,
1199 name: []const u8,
1200 cflags: List([]const u8),
1201 source_files: List([]const u8),
1202 object_files: List([]const u8),
1203 full_path_libs: List([]const u8),
1204 link_libs: BufSet,
1205 target: Target,
1206 include_dirs: List([]const u8),
1207 output_path: ?[]const u8,
1208 out_filename: []const u8,
1209
1210 pub fn init(builder: &Builder, name: []const u8) -> CExecutable {
1211 var self = CExecutable {
1212 .builder = builder,
1213 .name = name,
1214 .target = Target.Native,
1215 .cflags = List([]const u8).init(builder.allocator),
1216 .source_files = List([]const u8).init(builder.allocator),
1217 .object_files = List([]const u8).init(builder.allocator),
1218 .full_path_libs = List([]const u8).init(builder.allocator),
1219 .step = Step.init(name, builder.allocator, make),
1220 .link_libs = BufSet.init(builder.allocator),
1221 .include_dirs = List([]const u8).init(builder.allocator),
1222 .output_path = null,
1223 .out_filename = undefined,
1224 };
1225 self.computeOutFileName();
1226 return self;
1227 }
12281192
1229 fn computeOutFileName(self: &CExecutable) {1193 const output_path = builder.pathFromRoot(self.getOutputPath());
1230 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());1194 %%cc_args.append("-o");
1231 }1195 %%cc_args.append(output_path);
12321196
1233 pub fn setOutputPath(self: &CExecutable, value: []const u8) {1197 for (self.cflags.toSliceConst()) |cflag| {
1234 self.output_path = value;1198 %%cc_args.append(cflag);
1235 }1199 }
12361200
1237 pub fn getOutputPath(self: &CExecutable) -> []const u8 {1201 for (self.include_dirs.toSliceConst()) |dir| {
1238 test (self.output_path) |output_path| {1202 %%cc_args.append("-I");
1239 self.builder.pathFromRoot(output_path)1203 %%cc_args.append(builder.pathFromRoot(dir));
1240 } else {1204 }
1241 const wanted_path = %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename);
1242 %%os.path.relative(self.builder.allocator, self.builder.build_root, wanted_path)
1243 }
1244 }
12451205
1246 pub fn linkSystemLibrary(self: &CExecutable, name: []const u8) {1206 %return builder.spawnChild(cc, cc_args.toSliceConst());
1247 %%self.link_libs.put(name);1207 },
1248 }1208 Kind.Lib => {
1209 for (self.source_files.toSliceConst()) |source_file| {
1210 %%cc_args.resize(0);
12491211
1250 pub fn linkCLibrary(self: &CExecutable, clib: &CLibrary) {1212 if (!self.static) {
1251 self.step.dependOn(&clib.step);1213 %%cc_args.append("-fPIC");
1252 %%self.full_path_libs.append(clib.getOutputPath());1214 }
1253 }
12541215
1255 pub fn linkLibrary(self: &CExecutable, lib: &LibExeObjStep) {1216 %%cc_args.append("-c");
1256 assert(lib.kind == LibExeObjStep.Kind.Lib);1217 %%cc_args.append(source_file);
1257 self.step.dependOn(&lib.step);
1258 %%self.full_path_libs.append(lib.getOutputPath());
1259 // TODO should be some kind of isolated directory that only has this header in it
1260 %%self.include_dirs.append(self.builder.cache_root);
1261 }
12621218
1263 pub fn addObject(self: &CExecutable, obj: &LibExeObjStep) {1219 const rel_src_path = %%os.path.relative(builder.allocator, builder.build_root, source_file);
1264 assert(obj.kind == LibExeObjStep.Kind.Obj);1220 const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, rel_src_path);
1221 const cache_o_dir = os.path.dirname(cache_o_src);
1222 %return builder.makePath(cache_o_dir);
1223 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
1224 %%cc_args.append("-o");
1225 %%cc_args.append(cache_o_file);
12651226
1266 self.step.dependOn(&obj.step);1227 for (self.cflags.toSliceConst()) |cflag| {
1228 %%cc_args.append(cflag);
1229 }
12671230
1268 %%self.object_files.append(obj.getOutputPath());1231 for (self.include_dirs.toSliceConst()) |dir| {
1232 %%cc_args.append("-I");
1233 %%cc_args.append(dir);
1234 }
12691235
1270 // TODO should be some kind of isolated directory that only has this header in it1236 %return builder.spawnChild(cc, cc_args.toSliceConst());
1271 %%self.include_dirs.append(self.builder.cache_root);
1272 }
12731237
1274 pub fn addSourceFile(self: &CExecutable, file: []const u8) {1238 %%self.object_files.append(cache_o_file);
1275 %%self.source_files.append(file);1239 }
1276 }
12771240
1278 pub fn addObjectFile(self: &CExecutable, file: []const u8) {1241 if (self.static) {
1279 %%self.object_files.append(file);1242 debug.panic("TODO static library");
1280 }1243 } else {
1244 %%cc_args.resize(0);
12811245
1282 pub fn addIncludeDir(self: &CExecutable, path: []const u8) {1246 %%cc_args.append("-fPIC");
1283 %%self.include_dirs.append(path);1247 %%cc_args.append("-shared");
1284 }
12851248
1286 pub fn addCompileFlagsForRelease(self: &CExecutable, release: bool) {1249 const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major);
1287 if (release) {1250 defer builder.allocator.free(soname_arg);
1288 %%self.cflags.append("-g");1251 %%cc_args.append(soname_arg);
1289 %%self.cflags.append("-O2");
1290 } else {
1291 %%self.cflags.append("-g");
1292 }
1293 }
12941252
1295 pub fn addCompileFlags(self: &CExecutable, flags: []const []const u8) {1253 const output_path = builder.pathFromRoot(self.getOutputPath());
1296 for (flags) |flag| {1254 %%cc_args.append("-o");
1297 %%self.cflags.append(flag);1255 %%cc_args.append(output_path);
1298 }
1299 }
13001256
1301 fn make(step: &Step) -> %void {1257 for (self.object_files.toSliceConst()) |object_file| {
1302 const self = @fieldParentPtr(CExecutable, "step", step);1258 %%cc_args.append(builder.pathFromRoot(object_file));
1303 const cc = os.getEnv("CC") ?? "cc";1259 }
1304 const builder = self.builder;
13051260
1306 var cc_args = List([]const u8).init(builder.allocator);1261 const rpath_arg = builder.fmt("-Wl,-rpath,{}",
1307 defer cc_args.deinit();1262 %%os.path.real(builder.allocator, builder.cache_root));
1263 defer builder.allocator.free(rpath_arg);
1264 %%cc_args.append(rpath_arg);
13081265
1309 for (self.source_files.toSliceConst()) |source_file| {1266 %%cc_args.append("-rdynamic");
1310 %%cc_args.resize(0);
13111267
1312 %%cc_args.append("-c");1268 for (self.full_path_libs.toSliceConst()) |full_path_lib| {
1313 %%cc_args.append(builder.pathFromRoot(source_file));1269 %%cc_args.append(builder.pathFromRoot(full_path_lib));
1270 }
13141271
1315 const rel_src_path = %%os.path.relative(builder.allocator, builder.build_root, source_file);1272 %return builder.spawnChild(cc, cc_args.toSliceConst());
1316 const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, rel_src_path);
1317 const cache_o_dir = os.path.dirname(cache_o_src);
1318 %return builder.makePath(cache_o_dir);
1319 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
1320 %%cc_args.append("-o");
1321 %%cc_args.append(cache_o_file);
13221273
1323 for (self.cflags.toSliceConst()) |cflag| {1274 %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename,
1324 %%cc_args.append(cflag);1275 self.name_only_filename);
1325 }1276 }
1277 },
1278 Kind.Exe => {
1279 for (self.source_files.toSliceConst()) |source_file| {
1280 %%cc_args.resize(0);
1281
1282 %%cc_args.append("-c");
1283 %%cc_args.append(builder.pathFromRoot(source_file));
1284
1285 const rel_src_path = %%os.path.relative(builder.allocator, builder.build_root, source_file);
1286 const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, rel_src_path);
1287 const cache_o_dir = os.path.dirname(cache_o_src);
1288 %return builder.makePath(cache_o_dir);
1289 const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
1290 %%cc_args.append("-o");
1291 %%cc_args.append(cache_o_file);
1292
1293 for (self.cflags.toSliceConst()) |cflag| {
1294 %%cc_args.append(cflag);
1295 }
13261296
1327 for (self.include_dirs.toSliceConst()) |dir| {1297 for (self.include_dirs.toSliceConst()) |dir| {
1328 %%cc_args.append("-I");1298 %%cc_args.append("-I");
1329 %%cc_args.append(builder.pathFromRoot(dir));1299 %%cc_args.append(builder.pathFromRoot(dir));
1330 }1300 }
13311301
1332 %return builder.spawnChild(cc, cc_args.toSliceConst());1302 %return builder.spawnChild(cc, cc_args.toSliceConst());
13331303
1334 %%self.object_files.append(%%os.path.relative(builder.allocator, builder.build_root, cache_o_file));1304 %%self.object_files.append(%%os.path.relative(builder.allocator, builder.build_root, cache_o_file));
1335 }1305 }
13361306
1337 %%cc_args.resize(0);1307 %%cc_args.resize(0);
13381308
1339 for (self.object_files.toSliceConst()) |object_file| {1309 for (self.object_files.toSliceConst()) |object_file| {
1340 %%cc_args.append(builder.pathFromRoot(object_file));1310 %%cc_args.append(builder.pathFromRoot(object_file));
1341 }1311 }
13421312
1343 const output_path = builder.pathFromRoot(self.getOutputPath());1313 const output_path = builder.pathFromRoot(self.getOutputPath());
1344 %%cc_args.append("-o");1314 %%cc_args.append("-o");
1345 %%cc_args.append(output_path);1315 %%cc_args.append(output_path);
13461316
1347 const rpath_arg = builder.fmt("-Wl,-rpath,{}",1317 const rpath_arg = builder.fmt("-Wl,-rpath,{}",
1348 %%os.path.real(builder.allocator, builder.cache_root));1318 %%os.path.real(builder.allocator, builder.cache_root));
1349 defer builder.allocator.free(rpath_arg);1319 defer builder.allocator.free(rpath_arg);
1350 %%cc_args.append(rpath_arg);1320 %%cc_args.append(rpath_arg);
13511321
1352 %%cc_args.append("-rdynamic");1322 %%cc_args.append("-rdynamic");
13531323
1354 for (self.full_path_libs.toSliceConst()) |full_path_lib| {1324 for (self.full_path_libs.toSliceConst()) |full_path_lib| {
1355 %%cc_args.append(builder.pathFromRoot(full_path_lib));1325 %%cc_args.append(builder.pathFromRoot(full_path_lib));
1326 }
1327 },
1356 }1328 }
1357
1358 %return builder.spawnChild(cc, cc_args.toSliceConst());
1359 }1329 }
13601330
1361 pub fn setTarget(self: &CExecutable, target_arch: Arch, target_os: Os, target_environ: Environ) {1331 pub fn setTarget(self: &CLibExeObjStep, target_arch: Arch, target_os: Os, target_environ: Environ) {
1362 self.target = Target.Cross {1332 self.target = Target.Cross {
1363 CrossTarget {1333 CrossTarget {
1364 .arch = target_arch,1334 .arch = target_arch,
...@@ -1403,10 +1373,10 @@ pub const CommandStep = struct {...@@ -1403,10 +1373,10 @@ pub const CommandStep = struct {
1403pub const InstallCLibraryStep = struct {1373pub const InstallCLibraryStep = struct {
1404 step: Step,1374 step: Step,
1405 builder: &Builder,1375 builder: &Builder,
1406 lib: &CLibrary,1376 lib: &CLibExeObjStep,
1407 dest_file: []const u8,1377 dest_file: []const u8,
14081378
1409 pub fn init(builder: &Builder, lib: &CLibrary) -> InstallCLibraryStep {1379 pub fn init(builder: &Builder, lib: &CLibExeObjStep) -> InstallCLibraryStep {
1410 var self = InstallCLibraryStep {1380 var self = InstallCLibraryStep {
1411 .builder = builder,1381 .builder = builder,
1412 .step = Step.init(builder.fmt("install {}", lib.step.name), builder.allocator, make),1382 .step = Step.init(builder.fmt("install {}", lib.step.name), builder.allocator, make),