Skip to content

Commit

Permalink
fix: fix windows build by linking pcre via system library
Browse files Browse the repository at this point in the history
  • Loading branch information
freedmand committed Nov 24, 2021
1 parent df9322e commit d8c13a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ jobs:
shell: bash
- run: c:; cd \vcpkg; git pull; .\bootstrap-vcpkg.bat
- run: vcpkg integrate install
- run: vcpkg install curl --triplet x64-windows-static
- run: zig build --search-prefix C:/vcpkg/packages/curl_x64-windows-static --search-prefix C:/vcpkg/packages/zlib_x64-windows-static -Dtarget=x86_64-windows-msvc
- run: vcpkg install pcre curl --triplet x64-windows-static
- run: zig build --search-prefix C:/vcpkg/packages/pcre_x64-windows-static --search-prefix C:/vcpkg/packages/curl_x64-windows-static --search-prefix C:/vcpkg/packages/zlib_x64-windows-static -Dtarget=x86_64-windows-msvc
- run: Compress-Archive zig-out/bin/fastfec.exe fastfec-windows-x86_64-${{ steps.get_version.outputs.VERSION }}.zip
- run: mv zig-out/lib/fastfec.dll libfastfec-windows-x86_64-${{ steps.get_version.outputs.VERSION }}.dll
shell: bash
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The short form of flags can be combined, e.g. `-is` would include filing IDs and
The following libraries are used:

- curl (needed for the CLI, not the library)
- pcre (only needed on Windows)

Installing these libraries varies by OS:

Expand All @@ -78,7 +79,7 @@ Install [vcpkg](https://vcpkg.io) and run the following:

```sh
vcpkg integrate install
vcpkg install curl --triplet x64-windows-static
vcpkg install pcre curl --triplet x64-windows-static
```

### Building
Expand All @@ -92,7 +93,7 @@ zig build
On Windows, you may have to supply additional arguments to locate vcpkg dependencies and ensure the msvc toolchain is used:

```sh
zig build --search-prefix C:/vcpkg/packages/curl_x64-windows-static --search-prefix C:/vcpkg/packages/zlib_x64-windows-static -Dtarget=x86_64-windows-msvc
zig build --search-prefix C:/vcpkg/packages/pcre_x64-windows-static --search-prefix C:/vcpkg/packages/curl_x64-windows-static --search-prefix C:/vcpkg/packages/zlib_x64-windows-static -Dtarget=x86_64-windows-msvc
```

The above commands will output a binary at `zig-out/bin/fastfec` and a shared library file in the `zig-out/lib/` directory. If you want to only build the library, you can pass `-Dlib-only=true` as a build option following `zig build`.
Expand Down
21 changes: 15 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ pub fn build(b: *std.build.Builder) !void {

// Add curl
fastfec_cli.linkLibC();
fastfec_cli.addIncludeDir(pcreIncludeDir);
fastfec_cli.linkLibrary(pcre);
if (builtin.os.tag == .windows) {
fastfec_cli.linkSystemLibrary("ws2_32");
fastfec_cli.linkSystemLibrary("advapi32");
fastfec_cli.linkSystemLibrary("crypt32");
fastfec_cli.linkSystemLibrary("libcurl");
fastfec_cli.linkSystemLibraryName("zlib");
fastfec_cli.linkSystemLibrary("pcre");
} else {
fastfec_cli.linkSystemLibrary("curl");
fastfec_cli.addIncludeDir(pcreIncludeDir);
fastfec_cli.linkLibrary(pcre);
}

fastfec_cli.addCSourceFiles(&libSources, &buildOptions);
Expand All @@ -50,9 +51,13 @@ pub fn build(b: *std.build.Builder) !void {
fastfec_lib.setBuildMode(mode);
fastfec_lib.install();
fastfec_lib.linkLibC();
fastfec_lib.addIncludeDir(pcreIncludeDir);
fastfec_lib.linkLibrary(pcre);
fastfec_lib.addCSourceFiles(&libSources, &buildOptions);
if (builtin.os.tag == .windows) {
fastfec_lib.linkSystemLibrary("pcre");
} else {
fastfec_lib.addIncludeDir(pcreIncludeDir);
fastfec_lib.linkLibrary(pcre);
}

// Test step
var prev_test_step: ?*std.build.Step = null;
Expand All @@ -63,8 +68,12 @@ pub fn build(b: *std.build.Builder) !void {
subtest_exe.addCSourceFiles(&testIncludes, &buildOptions);
subtest_exe.addCSourceFile(test_file, &buildOptions);
// Link PCRE
subtest_exe.addIncludeDir(pcreIncludeDir);
subtest_exe.linkLibrary(pcre);
if (builtin.os.tag == .windows) {
subtest_exe.linkSystemLibrary("pcre");
} else {
subtest_exe.addIncludeDir(pcreIncludeDir);
subtest_exe.linkLibrary(pcre);
}
const subtest_cmd = subtest_exe.run();
if (prev_test_step != null) {
subtest_cmd.step.dependOn(prev_test_step.?);
Expand Down

0 comments on commit d8c13a1

Please sign in to comment.