Skip to content

Commit

Permalink
ci: build for macos.10.13...14.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jethrodaniel committed Apr 5, 2024
1 parent 22258f6 commit 0a5206f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ jobs:
- name: build x86_64
run: |
zig build --summary all --verbose -Doptimize=ReleaseFast -Dtarget=x86_64-native -p vosk/x86_64-macos
zig build -Dtarget=x86_64-macos.10.13...14.4.1-none -p vosk/x86_64-macos -Doptimize=ReleaseFast --summary all --verbose
- name: build aarch64
run: |
zig build --summary all --verbose -Doptimize=ReleaseFast -Dtarget=aarch64-native -p vosk/aarch64-macos
zig build -Dtarget=aarch64-macos.10.13...14.4.1-none -p vosk/aarch64-macos -Doptimize=ReleaseFast --summary all --verbose
- uses: actions/upload-artifact@v4
with:
Expand Down
87 changes: 39 additions & 48 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn build(b: *std.Build) void {
"src/base/kaldi-utils.cc",
"src/base/timer.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.defineCMacro("KALDI_VERSION", "\"5.5\""); // kaldi/src/.version
lib.defineCMacro("NDEBUG", "1");
Expand Down Expand Up @@ -123,20 +123,13 @@ pub fn build(b: *std.Build) void {
"src/matrix/srfft.cc",
"src/matrix/tp-matrix.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);
// lib.linkLibrary(kaldi_base);

lib.defineCMacro("HAVE_CLAPACK", "1");
// lib.defineCMacro("HAVE_OPENBLAS", "1");

// NOTE: needed for `kaldi-matrix`
if (target.result.os.tag == .macos) {
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse
@panic("macOS SDK is missing");
lib.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) });
lib.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) });
lib.addLibraryPath(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib" }) });

// NOTE: Using Xcode's `Accelerate` framework means that we have to
// comply with Apple's Xcode license:
//
Expand Down Expand Up @@ -175,7 +168,7 @@ pub fn build(b: *std.Build) void {
"src/util/simple-options.cc",
"src/util/text-utils.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

kaldi_util.linkLibrary(kaldi_matrix);
kaldi_util.linkLibrary(kaldi_base);
Expand All @@ -202,7 +195,7 @@ pub fn build(b: *std.Build) void {
"src/tree/event-map.cc",
"src/tree/tree-renderer.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_util);
lib.linkLibrary(kaldi_matrix);
Expand Down Expand Up @@ -233,7 +226,7 @@ pub fn build(b: *std.Build) void {
"src/gmm/mle-full-gmm.cc",
"src/gmm/model-common.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_tree);
lib.linkLibrary(kaldi_util);
Expand Down Expand Up @@ -269,7 +262,7 @@ pub fn build(b: *std.Build) void {
"src/transform/regtree-mllr-diag-gmm.cc",
"src/transform/transform-common.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_gmm);
lib.linkLibrary(kaldi_tree);
Expand All @@ -296,7 +289,7 @@ pub fn build(b: *std.Build) void {
"src/ivector/plda.cc",
"src/ivector/voice-activity-detection.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_transform);
lib.linkLibrary(kaldi_gmm);
Expand Down Expand Up @@ -332,7 +325,7 @@ pub fn build(b: *std.Build) void {
"src/cudamatrix/cu-tp-matrix.cc",
"src/cudamatrix/cu-vector.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_util);
lib.linkLibrary(kaldi_matrix);
Expand All @@ -359,7 +352,7 @@ pub fn build(b: *std.Build) void {
"src/hmm/transition-model.cc",
"src/hmm/tree-accu.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_tree);
lib.linkLibrary(kaldi_util);
Expand Down Expand Up @@ -391,7 +384,7 @@ pub fn build(b: *std.Build) void {
"src/lat/word-align-lattice-lexicon.cc",
"src/lat/word-align-lattice.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_hmm);
lib.linkLibrary(kaldi_tree);
Expand All @@ -416,7 +409,7 @@ pub fn build(b: *std.Build) void {
"src/fstext/kaldi-fst-io.cc",
"src/fstext/push-special.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);
}

//
Expand All @@ -438,7 +431,7 @@ pub fn build(b: *std.Build) void {
"src/chain/chain-training.cc",
"src/chain/chain-generic-numerator.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);
lib.defineCMacro("HAVE_CUDA", "0");

lib.linkLibrary(kaldi_cudamatrix);
Expand Down Expand Up @@ -474,7 +467,7 @@ pub fn build(b: *std.Build) void {
"src/decoder/simple-decoder.cc",
"src/decoder/training-graph-compiler.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_lat);
lib.linkLibrary(kaldi_fstext);
Expand Down Expand Up @@ -545,7 +538,7 @@ pub fn build(b: *std.Build) void {
"src/nnet3/nnet-training.cc",
"src/nnet3/nnet-utils.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);
lib.defineCMacro("HAVE_CUDA", "0");

lib.linkLibrary(kaldi_chain);
Expand Down Expand Up @@ -586,7 +579,7 @@ pub fn build(b: *std.Build) void {
"src/feat/signal.cc",
"src/feat/wave-reader.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_transform);
lib.linkLibrary(kaldi_gmm);
Expand Down Expand Up @@ -614,7 +607,7 @@ pub fn build(b: *std.Build) void {
"src/lm/kenlm.cc",
"src/lm/mikolov-rnnlm-lib.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_fstext);
lib.linkLibrary(kaldi_util);
Expand Down Expand Up @@ -646,7 +639,7 @@ pub fn build(b: *std.Build) void {
"src/rnnlm/sampling-lm-estimate.cc",
"src/rnnlm/sampling-lm.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);
lib.linkLibCpp();

lib.linkLibrary(kaldi_nnet3);
Expand Down Expand Up @@ -696,7 +689,7 @@ pub fn build(b: *std.Build) void {
"src/nnet2/train-nnet.cc",
"src/nnet2/widen-nnet.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);
lib.defineCMacro("HAVE_CUDA", "0");

lib.linkLibrary(kaldi_cudamatrix);
Expand Down Expand Up @@ -736,7 +729,7 @@ pub fn build(b: *std.Build) void {
"src/online2/online-timing.cc",
"src/online2/onlinebin-util.cc",
};
kaldiLibrary(lib, kaldi_dep, fst_dep, srcs);
kaldiLibrary(b, target, lib, kaldi_dep, fst_dep, srcs);

lib.linkLibrary(kaldi_ivector);
lib.linkLibrary(kaldi_nnet3);
Expand All @@ -755,27 +748,6 @@ pub fn build(b: *std.Build) void {
lib.linkLibrary(kaldi_base);
}

//

const kaldi = b.addStaticLibrary(.{
.name = "kaldi",
.target = target,
.optimize = kaldi_optimize,
.strip = true,
.root_source_file = b.addWriteFiles().add("empty.c", ""),
});
{
const lib = kaldi;

lib.linkLibCpp();

// NOTE: vosk only needs -lrnnlm -lonline2
lib.linkLibrary(kaldi_rnnlm);
lib.linkLibrary(kaldi_online2);

lib.pie = true;
}

//----

const static_lib = b.addStaticLibrary(.{
Expand Down Expand Up @@ -814,9 +786,18 @@ pub fn build(b: *std.Build) void {
lib.addIncludePath(fst_dep.path("src/include"));

lib.linkLibCpp();
lib.linkLibrary(kaldi);
lib.linkLibrary(kaldi_rnnlm);
lib.linkLibrary(kaldi_online2);
lib.linkLibrary(fstngram);

if (target.result.os.tag == .macos) {
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse
@panic("macOS SDK is missing");
lib.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) });
lib.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) });
lib.addLibraryPath(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib" }) });
}

lib.installHeader(
vosk_dep.path("src/vosk_api.h").getPath(b),
"vosk_api.h",
Expand Down Expand Up @@ -900,6 +881,8 @@ pub fn build(b: *std.Build) void {
}

fn kaldiLibrary(
b: *std.Build,
target: std.Build.ResolvedTarget,
lib: *std.Build.Step.Compile,
kaldi_dep: *std.Build.Dependency,
fst_dep: *std.Build.Dependency,
Expand All @@ -916,5 +899,13 @@ fn kaldiLibrary(
lib.addIncludePath(fst_dep.path("src/include"));
lib.linkLibCpp();

if (target.result.os.tag == .macos) {
const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse
@panic("macOS SDK is missing");
lib.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) });
lib.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) });
lib.addLibraryPath(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib" }) });
}

lib.pie = true;
}

0 comments on commit 0a5206f

Please sign in to comment.