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 {
151151 return obj_step;
152152 }
153153
154 pub fn addCStaticLibrary(self: &Builder, name: []const u8) -> &CLibrary {
155 const lib = %%self.allocator.create(CLibrary);
156 *lib = CLibrary.initStatic(self, name);
157 return lib;
154 pub fn addCStaticLibrary(self: &Builder, name: []const u8) -> &CLibExeObjStep {
155 return CLibExeObjStep.createStaticLibrary(self, name);
158156 }
159157
160 pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) -> &CLibrary {
161 const lib = %%self.allocator.create(CLibrary);
162 *lib = CLibrary.initShared(self, name, ver);
163 return lib;
158 pub fn addCSharedLibrary(self: &Builder, name: []const u8, ver: &const Version) -> &CLibExeObjStep {
159 return CLibExeObjStep.createSharedLibrary(self, name, ver);
164160 }
165161
166 pub fn addCExecutable(self: &Builder, name: []const u8) -> &CExecutable {
167 const exe = %%self.allocator.create(CExecutable);
168 *exe = CExecutable.init(self, name);
169 return exe;
162 pub fn addCExecutable(self: &Builder, name: []const u8) -> &CLibExeObjStep {
163 return CLibExeObjStep.createExecutable(self, name);
164 }
165
166 pub fn addCObject(self: &Builder, name: []const u8, src: []const u8) -> &CLibExeObjStep {
167 return CLibExeObjStep.createObject(self, name, src);
170168 }
171169
172170 pub fn addCommand(self: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
......@@ -533,7 +531,7 @@ pub const Builder = struct {
533531 };
534532 }
535533
536 pub fn installCLibrary(self: &Builder, lib: &CLibrary) -> &InstallCLibraryStep {
534 pub fn installCLibrary(self: &Builder, lib: &CLibExeObjStep) -> &InstallCLibraryStep {
537535 const install_step = %%self.allocator.create(InstallCLibraryStep);
538536 *install_step = InstallCLibraryStep.init(self, lib);
539537 install_step.step.dependOn(&lib.step);
......@@ -1007,8 +1005,7 @@ pub const TestStep = struct {
10071005 }
10081006};
10091007
1010// TODO merge with CExecutable
1011pub const CLibrary = struct {
1008pub const CLibExeObjStep = struct {
10121009 step: Step,
10131010 name: []const u8,
10141011 out_filename: []const u8,
......@@ -1019,24 +1016,51 @@ pub const CLibrary = struct {
10191016 source_files: List([]const u8),
10201017 object_files: List([]const u8),
10211018 link_libs: BufSet,
1019 full_path_libs: List([]const u8),
10221020 target: Target,
10231021 builder: &Builder,
10241022 include_dirs: List([]const u8),
10251023 major_only_filename: []const u8,
10261024 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 {
1029 return init(builder, name, version, false);
1028 const Kind = enum {
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;
10301038 }
10311039
1032 pub fn initStatic(builder: &Builder, name: []const u8) -> CLibrary {
1033 return init(builder, name, builder.version(0, 0, 0), true);
1040 pub fn createStaticLibrary(builder: &Builder, name: []const u8) -> &CLibExeObjStep {
1041 const self = %%builder.allocator.create(CLibExeObjStep);
1042 *self = init(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
1043 return self;
10341044 }
10351045
1036 fn init(builder: &Builder, name: []const u8, version: &const Version, static: bool) -> CLibrary {
1037 var clib = CLibrary {
1046 pub fn createObject(builder: &Builder, name: []const u8, src: []const u8) -> &CLibExeObjStep {
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 {
10381061 .builder = builder,
10391062 .name = name,
1063 .kind = kind,
10401064 .version = *version,
10411065 .static = static,
10421066 .target = Target.Native,
......@@ -1045,32 +1069,44 @@ pub const CLibrary = struct {
10451069 .object_files = List([]const u8).init(builder.allocator),
10461070 .step = Step.init(name, builder.allocator, make),
10471071 .link_libs = BufSet.init(builder.allocator),
1072 .full_path_libs = List([]const u8).init(builder.allocator),
10481073 .include_dirs = List([]const u8).init(builder.allocator),
10491074 .output_path = null,
10501075 .out_filename = undefined,
10511076 .major_only_filename = undefined,
10521077 .name_only_filename = undefined,
1078 .object_src = undefined,
10531079 };
1054 clib.computeOutFileName();
1080 clib.computeOutFileNames();
10551081 return clib;
10561082 }
10571083
1058 fn computeOutFileName(self: &CLibrary) {
1059 if (self.static) {
1060 self.out_filename = self.builder.fmt("lib{}.a", self.name);
1061 } else {
1062 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}",
1063 self.name, self.version.major, self.version.minor, self.version.patch);
1064 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major);
1065 self.name_only_filename = self.builder.fmt("lib{}.so", self.name);
1084 fn computeOutFileNames(self: &CLibExeObjStep) {
1085 switch (self.kind) {
1086 Kind.Obj => {
1087 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
1088 },
1089 Kind.Exe => {
1090 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
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 },
10661102 }
10671103 }
10681104
1069 pub fn setOutputPath(self: &CLibrary, value: []const u8) {
1105 pub fn setOutputPath(self: &CLibExeObjStep, value: []const u8) {
10701106 self.output_path = value;
10711107 }
10721108
1073 pub fn getOutputPath(self: &CLibrary) -> []const u8 {
1109 pub fn getOutputPath(self: &CLibExeObjStep) -> []const u8 {
10741110 test (self.output_path) |output_path| {
10751111 output_path
10761112 } else {
......@@ -1079,28 +1115,54 @@ pub const CLibrary = struct {
10791115 }
10801116 }
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);
10831129 %%self.link_libs.put(name);
10841130 }
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);
10871135 self.step.dependOn(&other.step);
1088 %%self.link_libs.put(other.name);
1136 %%self.full_path_libs.append(other.getOutputPath());
10891137 }
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);
10921141 %%self.source_files.append(file);
10931142 }
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);
10961146 %%self.object_files.append(file);
10971147 }
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) {
11001162 %%self.include_dirs.append(path);
11011163 }
11021164
1103 pub fn addCompileFlagsForRelease(self: &CLibrary, release: bool) {
1165 pub fn addCompileFlagsForRelease(self: &CLibExeObjStep, release: bool) {
11041166 if (release) {
11051167 %%self.cflags.append("-g");
11061168 %%self.cflags.append("-O2");
......@@ -1109,256 +1171,164 @@ pub const CLibrary = struct {
11091171 }
11101172 }
11111173
1112 pub fn addCompileFlags(self: &CLibrary, flags: []const []const u8) {
1174 pub fn addCompileFlags(self: &CLibExeObjStep, flags: []const []const u8) {
11131175 for (flags) |flag| {
11141176 %%self.cflags.append(flag);
11151177 }
11161178 }
11171179
11181180 fn make(step: &Step) -> %void {
1119 const self = @fieldParentPtr(CLibrary, "step", step);
1181 const self = @fieldParentPtr(CLibExeObjStep, "step", step);
11201182 const cc = os.getEnv("CC") ?? "cc";
11211183 const builder = self.builder;
11221184
11231185 var cc_args = List([]const u8).init(builder.allocator);
11241186 defer cc_args.deinit();
11251187
1126 for (self.source_files.toSliceConst()) |source_file| {
1127 %%cc_args.resize(0);
1128
1129 if (!self.static) {
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 }
1188 switch (self.kind) {
1189 Kind.Obj => {
1190 %%cc_args.append("-c");
1191 %%cc_args.append(builder.pathFromRoot(self.object_src));
12281192
1229 fn computeOutFileName(self: &CExecutable) {
1230 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
1231 }
1193 const output_path = builder.pathFromRoot(self.getOutputPath());
1194 %%cc_args.append("-o");
1195 %%cc_args.append(output_path);
12321196
1233 pub fn setOutputPath(self: &CExecutable, value: []const u8) {
1234 self.output_path = value;
1235 }
1197 for (self.cflags.toSliceConst()) |cflag| {
1198 %%cc_args.append(cflag);
1199 }
12361200
1237 pub fn getOutputPath(self: &CExecutable) -> []const u8 {
1238 test (self.output_path) |output_path| {
1239 self.builder.pathFromRoot(output_path)
1240 } else {
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 }
1201 for (self.include_dirs.toSliceConst()) |dir| {
1202 %%cc_args.append("-I");
1203 %%cc_args.append(builder.pathFromRoot(dir));
1204 }
12451205
1246 pub fn linkSystemLibrary(self: &CExecutable, name: []const u8) {
1247 %%self.link_libs.put(name);
1248 }
1206 %return builder.spawnChild(cc, cc_args.toSliceConst());
1207 },
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) {
1251 self.step.dependOn(&clib.step);
1252 %%self.full_path_libs.append(clib.getOutputPath());
1253 }
1212 if (!self.static) {
1213 %%cc_args.append("-fPIC");
1214 }
12541215
1255 pub fn linkLibrary(self: &CExecutable, lib: &LibExeObjStep) {
1256 assert(lib.kind == LibExeObjStep.Kind.Lib);
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 }
1216 %%cc_args.append("-c");
1217 %%cc_args.append(source_file);
12621218
1263 pub fn addObject(self: &CExecutable, obj: &LibExeObjStep) {
1264 assert(obj.kind == LibExeObjStep.Kind.Obj);
1219 const rel_src_path = %%os.path.relative(builder.allocator, builder.build_root, source_file);
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 it
1271 %%self.include_dirs.append(self.builder.cache_root);
1272 }
1236 %return builder.spawnChild(cc, cc_args.toSliceConst());
12731237
1274 pub fn addSourceFile(self: &CExecutable, file: []const u8) {
1275 %%self.source_files.append(file);
1276 }
1238 %%self.object_files.append(cache_o_file);
1239 }
12771240
1278 pub fn addObjectFile(self: &CExecutable, file: []const u8) {
1279 %%self.object_files.append(file);
1280 }
1241 if (self.static) {
1242 debug.panic("TODO static library");
1243 } else {
1244 %%cc_args.resize(0);
12811245
1282 pub fn addIncludeDir(self: &CExecutable, path: []const u8) {
1283 %%self.include_dirs.append(path);
1284 }
1246 %%cc_args.append("-fPIC");
1247 %%cc_args.append("-shared");
12851248
1286 pub fn addCompileFlagsForRelease(self: &CExecutable, release: bool) {
1287 if (release) {
1288 %%self.cflags.append("-g");
1289 %%self.cflags.append("-O2");
1290 } else {
1291 %%self.cflags.append("-g");
1292 }
1293 }
1249 const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major);
1250 defer builder.allocator.free(soname_arg);
1251 %%cc_args.append(soname_arg);
12941252
1295 pub fn addCompileFlags(self: &CExecutable, flags: []const []const u8) {
1296 for (flags) |flag| {
1297 %%self.cflags.append(flag);
1298 }
1299 }
1253 const output_path = builder.pathFromRoot(self.getOutputPath());
1254 %%cc_args.append("-o");
1255 %%cc_args.append(output_path);
13001256
1301 fn make(step: &Step) -> %void {
1302 const self = @fieldParentPtr(CExecutable, "step", step);
1303 const cc = os.getEnv("CC") ?? "cc";
1304 const builder = self.builder;
1257 for (self.object_files.toSliceConst()) |object_file| {
1258 %%cc_args.append(builder.pathFromRoot(object_file));
1259 }
13051260
1306 var cc_args = List([]const u8).init(builder.allocator);
1307 defer cc_args.deinit();
1261 const rpath_arg = builder.fmt("-Wl,-rpath,{}",
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| {
1310 %%cc_args.resize(0);
1266 %%cc_args.append("-rdynamic");
13111267
1312 %%cc_args.append("-c");
1313 %%cc_args.append(builder.pathFromRoot(source_file));
1268 for (self.full_path_libs.toSliceConst()) |full_path_lib| {
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);
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);
1272 %return builder.spawnChild(cc, cc_args.toSliceConst());
13221273
1323 for (self.cflags.toSliceConst()) |cflag| {
1324 %%cc_args.append(cflag);
1325 }
1274 %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename,
1275 self.name_only_filename);
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| {
1328 %%cc_args.append("-I");
1329 %%cc_args.append(builder.pathFromRoot(dir));
1330 }
1297 for (self.include_dirs.toSliceConst()) |dir| {
1298 %%cc_args.append("-I");
1299 %%cc_args.append(builder.pathFromRoot(dir));
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));
1335 }
1304 %%self.object_files.append(%%os.path.relative(builder.allocator, builder.build_root, cache_o_file));
1305 }
13361306
1337 %%cc_args.resize(0);
1307 %%cc_args.resize(0);
13381308
1339 for (self.object_files.toSliceConst()) |object_file| {
1340 %%cc_args.append(builder.pathFromRoot(object_file));
1341 }
1309 for (self.object_files.toSliceConst()) |object_file| {
1310 %%cc_args.append(builder.pathFromRoot(object_file));
1311 }
13421312
1343 const output_path = builder.pathFromRoot(self.getOutputPath());
1344 %%cc_args.append("-o");
1345 %%cc_args.append(output_path);
1313 const output_path = builder.pathFromRoot(self.getOutputPath());
1314 %%cc_args.append("-o");
1315 %%cc_args.append(output_path);
13461316
1347 const rpath_arg = builder.fmt("-Wl,-rpath,{}",
1348 %%os.path.real(builder.allocator, builder.cache_root));
1349 defer builder.allocator.free(rpath_arg);
1350 %%cc_args.append(rpath_arg);
1317 const rpath_arg = builder.fmt("-Wl,-rpath,{}",
1318 %%os.path.real(builder.allocator, builder.cache_root));
1319 defer builder.allocator.free(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| {
1355 %%cc_args.append(builder.pathFromRoot(full_path_lib));
1324 for (self.full_path_libs.toSliceConst()) |full_path_lib| {
1325 %%cc_args.append(builder.pathFromRoot(full_path_lib));
1326 }
1327 },
13561328 }
1357
1358 %return builder.spawnChild(cc, cc_args.toSliceConst());
13591329 }
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) {
13621332 self.target = Target.Cross {
13631333 CrossTarget {
13641334 .arch = target_arch,
......@@ -1403,10 +1373,10 @@ pub const CommandStep = struct {
14031373pub const InstallCLibraryStep = struct {
14041374 step: Step,
14051375 builder: &Builder,
1406 lib: &CLibrary,
1376 lib: &CLibExeObjStep,
14071377 dest_file: []const u8,
14081378
1409 pub fn init(builder: &Builder, lib: &CLibrary) -> InstallCLibraryStep {
1379 pub fn init(builder: &Builder, lib: &CLibExeObjStep) -> InstallCLibraryStep {
14101380 var self = InstallCLibraryStep {
14111381 .builder = builder,
14121382 .step = Step.init(builder.fmt("install {}", lib.step.name), builder.allocator, make),