| ... | @@ -1700,8 +1700,23 @@ pub const LibExeObjStep = struct { | ... | @@ -1700,8 +1700,23 @@ pub const LibExeObjStep = struct { |
| 1700 | } | 1700 | } |
| 1701 | } | 1701 | } |
| 1702 | | 1702 | |
| | 1703 | /// If the value is omitted, it is set to 1. |
| | 1704 | /// `name` and `value` need not live longer than the function call. |
| | 1705 | pub fn defineCMacro(self: *LibExeObjStep, name: []const u8, value: ?[]const u8) void { |
| | 1706 | var macro = self.builder.allocator.alloc( |
| | 1707 | u8, |
| | 1708 | name.len + if (value) |value_slice| value_slice.len + 1 else 0, |
| | 1709 | ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable; |
| | 1710 | mem.copy(u8, macro, name); |
| | 1711 | if (value) |value_slice| { |
| | 1712 | macro[name.len] = '='; |
| | 1713 | mem.copy(u8, macro[name.len + 1 ..], value_slice); |
| | 1714 | } |
| | 1715 | self.c_macros.append(macro) catch unreachable; |
| | 1716 | } |
| | 1717 | |
| 1703 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. | 1718 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. |
| 1704 | pub fn defineCMacro(self: *LibExeObjStep, name_and_value: []const u8) void { | 1719 | pub fn defineCMacroRaw(self: *LibExeObjStep, name_and_value: []const u8) void { |
| 1705 | self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable; | 1720 | self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable; |
| 1706 | } | 1721 | } |
| 1707 | | 1722 | |
| ... | @@ -1790,9 +1805,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1790,9 +1805,9 @@ pub const LibExeObjStep = struct { |
| 1790 | self.linkSystemLibraryName(tok["-l".len..]); | 1805 | self.linkSystemLibraryName(tok["-l".len..]); |
| 1791 | } else if (mem.eql(u8, tok, "-D")) { | 1806 | } else if (mem.eql(u8, tok, "-D")) { |
| 1792 | const macro = it.next() orelse return error.PkgConfigInvalidOutput; | 1807 | const macro = it.next() orelse return error.PkgConfigInvalidOutput; |
| 1793 | self.defineCMacro(macro); | 1808 | self.defineCMacroRaw(macro); |
| 1794 | } else if (mem.startsWith(u8, tok, "-D")) { | 1809 | } else if (mem.startsWith(u8, tok, "-D")) { |
| 1795 | self.defineCMacro(tok["-D".len..]); | 1810 | self.defineCMacroRaw(tok["-D".len..]); |
| 1796 | } else if (mem.eql(u8, tok, "-pthread")) { | 1811 | } else if (mem.eql(u8, tok, "-pthread")) { |
| 1797 | self.linkLibC(); | 1812 | self.linkLibC(); |
| 1798 | } else if (self.builder.verbose) { | 1813 | } else if (self.builder.verbose) { |