diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-10-16 01:14:28 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-10-16 01:14:28 -0400 |
| commit | d08c57741ae190c587c42861e71b0e361903733e (patch) | |
| tree | ee79c77ec4a568d90ae1cfaefa6fd786cc788926 /std | |
| parent | 78b753af9dd9818b9dc848f590330c61b2ca7c3f (diff) | |
| download | zig-d08c57741ae190c587c42861e71b0e361903733e.tar.gz zig-d08c57741ae190c587c42861e71b0e361903733e.zip | |
ability to make a DLL
See #302
Diffstat (limited to 'std')
| -rw-r--r-- | std/build.zig | 44 | ||||
| -rw-r--r-- | std/special/bootstrap_lib.zig | 9 |
2 files changed, 42 insertions, 11 deletions
diff --git a/std/build.zig b/std/build.zig index 22aac84199..4004a4db0e 100644 --- a/std/build.zig +++ b/std/build.zig @@ -636,6 +636,20 @@ pub const Builder = struct { pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 { return %%fmt_lib.allocPrint(self.allocator, format, args); } + + fn getCCExe(self: &Builder) -> []const u8 { + if (builtin.environ == builtin.Environ.msvc) { + return "cl.exe"; + } else { + return os.getEnvVarOwned(self.builder.allocator, "CC") %% |err| { + if (err == error.EnvironmentVariableNotFound) { + ([]const u8)("cc") + } else { + return err + } + }; + } + } }; const Version = struct { @@ -685,6 +699,17 @@ const Target = enum { else => false, }; } + + pub fn isWindows(self: &const Target) -> bool { + return switch (self.getOs()) { + builtin.Os.windows => true, + else => false, + }; + } + + pub fn wantSharedLibSymLinks(self: &const Target) -> bool { + return !self.isWindows(); + } }; pub const LibExeObjStep = struct { @@ -885,7 +910,7 @@ pub const LibExeObjStep = struct { self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name); }, builtin.Os.windows => { - self.out_filename = self.builder.fmt("lib{}.dll", self.name); + self.out_filename = self.builder.fmt("{}.dll", self.name); }, else => { self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", @@ -1200,7 +1225,7 @@ pub const LibExeObjStep = struct { %return builder.spawnChild(zig_args.toSliceConst()); - if (self.kind == Kind.Lib and !self.static) { + if (self.kind == Kind.Lib and !self.static and self.target.wantSharedLibSymLinks()) { %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename, self.name_only_filename); } @@ -1252,15 +1277,10 @@ pub const LibExeObjStep = struct { } fn makeC(self: &LibExeObjStep) -> %void { - const cc = os.getEnvVarOwned(self.builder.allocator, "CC") %% |err| { - if (err == error.EnvironmentVariableNotFound) { - ([]const u8)("cc") - } else { - return err - } - }; const builder = self.builder; + const cc = builder.getCCExe(); + assert(!self.is_zig); var cc_args = ArrayList([]const u8).init(builder.allocator); @@ -1390,8 +1410,10 @@ pub const LibExeObjStep = struct { %return builder.spawnChild(cc_args.toSliceConst()); - %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename, - self.name_only_filename); + if (self.target.wantSharedLibSymLinks()) { + %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename, + self.name_only_filename); + } } }, Kind.Exe => { diff --git a/std/special/bootstrap_lib.zig b/std/special/bootstrap_lib.zig new file mode 100644 index 0000000000..7412d64fa6 --- /dev/null +++ b/std/special/bootstrap_lib.zig @@ -0,0 +1,9 @@ +// This file is included in the compilation unit when exporting a library on windows. + +const std = @import("std"); + +export stdcallcc fn _DllMainCRTStartup(hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD, + lpReserved: std.os.windows.LPVOID) -> std.os.windows.BOOL +{ + return std.os.windows.TRUE; +} |
