Skip to content

Commit 7db4006

Browse files
committed
add lk console command with PortAudio + WebRTC AEC
1 parent 43c8e51 commit 7db4006

1,484 files changed

Lines changed: 266796 additions & 95 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
pkg/provider/resources/*.h264 filter=lfs diff=lfs merge=lfs -text
22
pkg/provider/resources/*.ivf filter=lfs diff=lfs merge=lfs -text
33
pkg/provider/resources/*.ogg filter=lfs diff=lfs merge=lfs -text
4+
5+
# Vendored C/C++ source (WebRTC APM, PortAudio, abseil, pffft, rnnoise)
6+
pkg/apm/webrtc/**/*.cc linguist-vendored
7+
pkg/apm/webrtc/**/*.c linguist-vendored
8+
pkg/apm/webrtc/**/*.h linguist-vendored
9+
pkg/apm/webrtc/**/*.m linguist-vendored
10+
pkg/apm/webrtc/**/*.inc linguist-vendored
11+
pkg/portaudio/pa_src/** linguist-vendored
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Copyright 2023 LiveKit, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Build binaries
16+
17+
on:
18+
workflow_call:
19+
inputs:
20+
output_dir:
21+
type: string
22+
default: bin
23+
upload_release:
24+
type: boolean
25+
default: false
26+
27+
jobs:
28+
build:
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include:
33+
- os: macos-latest
34+
suffix: darwin_arm64
35+
- os: ubuntu-latest
36+
suffix: linux_amd64
37+
zig_target: x86_64-linux-gnu.2.28
38+
alsa_arch: amd64
39+
alsa_triple: x86_64-linux-gnu
40+
- os: ubuntu-latest
41+
suffix: linux_arm64
42+
zig_target: aarch64-linux-gnu.2.28
43+
alsa_arch: arm64
44+
alsa_triple: aarch64-linux-gnu
45+
goarch: arm64
46+
- os: ubuntu-latest
47+
suffix: linux_arm
48+
zig_target: arm-linux-gnueabihf.2.28
49+
alsa_arch: armhf
50+
alsa_triple: arm-linux-gnueabihf
51+
goarch: arm
52+
goarm: "7"
53+
- os: ubuntu-latest
54+
suffix: windows_amd64
55+
zig_target: x86_64-windows-gnu
56+
goos: windows
57+
goarch: amd64
58+
- os: ubuntu-latest
59+
suffix: windows_arm64
60+
zig_target: aarch64-windows-gnu
61+
goos: windows
62+
goarch: arm64
63+
- os: ubuntu-latest
64+
suffix: windows_arm
65+
goos: windows
66+
goarch: arm
67+
goarm: "7"
68+
runs-on: ${{ matrix.os }}
69+
steps:
70+
- uses: actions/checkout@v6
71+
with:
72+
lfs: 'true'
73+
submodules: true
74+
75+
- run: git lfs pull
76+
77+
- name: Set up Go
78+
uses: actions/setup-go@v6
79+
with:
80+
go-version: "1.25"
81+
82+
- name: Install Zig
83+
if: matrix.zig_target
84+
uses: mlugg/setup-zig@v2
85+
with:
86+
version: 0.14.1
87+
88+
- name: Install ALSA headers
89+
if: matrix.alsa_arch
90+
run: |
91+
sudo dpkg --add-architecture ${{ matrix.alsa_arch }}
92+
if [ "${{ matrix.alsa_arch }}" != "amd64" ]; then
93+
CODENAME=$(lsb_release -cs)
94+
# Restrict existing sources to amd64 to avoid 404s for foreign arch
95+
for f in /etc/apt/sources.list.d/*.sources; do
96+
grep -q '^Architectures:' "$f" || sudo sed -i '/^Types:/a Architectures: amd64 i386' "$f"
97+
done
98+
# Add ports.ubuntu.com for the foreign architecture
99+
printf 'Types: deb\nURIs: http://ports.ubuntu.com/ubuntu-ports\nSuites: %s %s-updates\nComponents: main universe\nArchitectures: %s\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg\n' \
100+
"$CODENAME" "$CODENAME" "${{ matrix.alsa_arch }}" | sudo tee /etc/apt/sources.list.d/ports.sources
101+
fi
102+
sudo apt-get update
103+
sudo apt-get install -y libasound2-dev:${{ matrix.alsa_arch }}
104+
105+
- name: Generate Windows import libraries
106+
if: matrix.goos == 'windows' && matrix.zig_target
107+
run: |
108+
ZIG_LIB=$(zig env | jq -r '.lib_dir')
109+
echo "ZIG_LIB=${ZIG_LIB}" >> "$GITHUB_ENV"
110+
LIB_DIR="${ZIG_LIB}/libc/mingw/lib-common"
111+
# Zig bundles MinGW .def files but lld needs .a import libraries.
112+
# Go's compiled objects embed COFF /DEFAULTLIB directives (e.g. dbghelp,
113+
# bcrypt) that lld resolves directly, bypassing Zig's lazy .def→.a
114+
# generation. Pre-generate all import libraries so lld can find them.
115+
MACHINE=${{ matrix.goarch == 'amd64' && 'i386:x86-64' || 'arm64' }}
116+
for def in "${LIB_DIR}"/*.def; do
117+
lib=$(basename "$def" .def)
118+
[ -f "${LIB_DIR}/lib${lib}.a" ] && continue
119+
zig dlltool -d "$def" -l "${LIB_DIR}/lib${lib}.a" -m "$MACHINE" 2>/dev/null || true
120+
done
121+
122+
- name: Build
123+
env:
124+
CGO_ENABLED: ${{ (matrix.goos && !matrix.zig_target) && '0' || '1' }}
125+
CC: ${{ matrix.zig_target && format('zig cc -target {0}', matrix.zig_target) || '' }}
126+
CXX: ${{ matrix.zig_target && format('zig c++ -target {0}', matrix.zig_target) || '' }}
127+
# Zig uses its own sysroot; point it at the system ALSA headers and libraries
128+
CGO_CFLAGS: ${{ matrix.alsa_triple && format('-isystem /usr/include -isystem /usr/include/{0}', matrix.alsa_triple) || '' }}
129+
CGO_LDFLAGS: ${{ matrix.alsa_triple && format('-L/usr/lib/{0}', matrix.alsa_triple) || '' }}
130+
# -fms-extensions: enable __try/__except (SEH) used by WebRTC
131+
# -DNTDDI_VERSION: target Windows 10 base to skip WinRT includes absent from MinGW
132+
CGO_CXXFLAGS: ${{ matrix.goos == 'windows' && '-fms-extensions -DNTDDI_VERSION=0x0A000000' || '' }}
133+
GOOS: ${{ matrix.goos || '' }}
134+
GOARCH: ${{ matrix.goarch || '' }}
135+
GOARM: ${{ matrix.goarm || '' }}
136+
shell: bash
137+
run: |
138+
EXT=""; if [ "${GOOS:-}" = "windows" ]; then EXT=".exe"; fi
139+
TAGS=""
140+
if [ "$CGO_ENABLED" = "1" ]; then TAGS="-tags console"; fi
141+
# Force external linking for Windows so Go uses zig cc (CC) as the linker,
142+
# and add Zig's MinGW lib path so lld can find the generated import libraries.
143+
EXTLD=""
144+
if [ "${GOOS:-}" = "windows" ] && [ "$CGO_ENABLED" = "1" ]; then
145+
EXTLD="-linkmode=external -extldflags '-L${ZIG_LIB}/libc/mingw/lib-common'"
146+
fi
147+
go build $TAGS -ldflags "-w -s $EXTLD" -o "${{ inputs.output_dir }}/lk${EXT}" ./cmd/lk
148+
149+
- name: Verify binary
150+
if: "!matrix.goos && !matrix.goarch"
151+
run: ${{ inputs.output_dir }}/lk --help > /dev/null
152+
153+
- name: Package and upload
154+
if: inputs.upload_release
155+
env:
156+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
shell: bash
158+
run: |
159+
TAG="${GITHUB_REF#refs/tags/}"
160+
VERSION="${TAG#v}"
161+
NAME="lk_${VERSION}_${{ matrix.suffix }}"
162+
cp LICENSE ${{ inputs.output_dir }}/
163+
cp -r autocomplete ${{ inputs.output_dir }}/
164+
if [[ "${{ matrix.suffix }}" == windows_* ]]; then
165+
cd ${{ inputs.output_dir }} && zip -r "../${NAME}.zip" lk.exe LICENSE autocomplete && cd ..
166+
gh release upload "$TAG" "${NAME}.zip" --clobber
167+
else
168+
tar -czf "${NAME}.tar.gz" -C ${{ inputs.output_dir }} lk LICENSE autocomplete
169+
gh release upload "$TAG" "${NAME}.tar.gz" --clobber
170+
fi

.github/workflows/build.yaml

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,149 @@ on:
2020
pull_request:
2121
branches: [ main ]
2222

23+
permissions:
24+
contents: read
25+
2326
jobs:
24-
build:
27+
lint-and-test:
2528
runs-on: ubuntu-latest
2629
steps:
2730
- uses: actions/checkout@v6
28-
- uses: actions/cache@v5
2931
with:
30-
path: |
31-
~/go/pkg/mod
32-
~/go/bin
33-
~/.cache
34-
key: livekit-cli
32+
submodules: true
3533

3634
- name: Set up Go
3735
uses: actions/setup-go@v6
3836
with:
3937
go-version: "1.25"
4038

41-
- name: Download Go modules
42-
run: go mod download
43-
4439
- name: Static Check
4540
uses: dominikh/staticcheck-action@v1.4.0
4641
with:
4742
version: "latest"
4843
install-go: false
4944

50-
- name: Run Go tests
45+
- name: Test
5146
run: go test -v ./...
47+
48+
build:
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
include:
53+
- os: macos-latest
54+
suffix: darwin_arm64
55+
- os: ubuntu-latest
56+
suffix: linux_amd64
57+
zig_target: x86_64-linux-gnu.2.28
58+
alsa_arch: amd64
59+
alsa_triple: x86_64-linux-gnu
60+
- os: ubuntu-latest
61+
suffix: linux_arm64
62+
zig_target: aarch64-linux-gnu.2.28
63+
alsa_arch: arm64
64+
alsa_triple: aarch64-linux-gnu
65+
goarch: arm64
66+
- os: ubuntu-latest
67+
suffix: linux_arm
68+
zig_target: arm-linux-gnueabihf.2.28
69+
alsa_arch: armhf
70+
alsa_triple: arm-linux-gnueabihf
71+
goarch: arm
72+
goarm: "7"
73+
- os: ubuntu-latest
74+
suffix: windows_amd64
75+
zig_target: x86_64-windows-gnu
76+
goos: windows
77+
goarch: amd64
78+
- os: ubuntu-latest
79+
suffix: windows_arm64
80+
zig_target: aarch64-windows-gnu
81+
goos: windows
82+
goarch: arm64
83+
- os: ubuntu-latest
84+
suffix: windows_arm
85+
goos: windows
86+
goarch: arm
87+
goarm: "7"
88+
runs-on: ${{ matrix.os }}
89+
steps:
90+
- uses: actions/checkout@v6
91+
with:
92+
submodules: true
93+
94+
- name: Set up Go
95+
uses: actions/setup-go@v6
96+
with:
97+
go-version: "1.25"
98+
99+
- name: Install Zig
100+
if: matrix.zig_target
101+
uses: mlugg/setup-zig@v2
102+
with:
103+
version: 0.14.1
104+
105+
- name: Install ALSA headers
106+
if: matrix.alsa_arch
107+
run: |
108+
sudo dpkg --add-architecture ${{ matrix.alsa_arch }}
109+
if [ "${{ matrix.alsa_arch }}" != "amd64" ]; then
110+
CODENAME=$(lsb_release -cs)
111+
# Restrict existing sources to amd64 to avoid 404s for foreign arch
112+
for f in /etc/apt/sources.list.d/*.sources; do
113+
grep -q '^Architectures:' "$f" || sudo sed -i '/^Types:/a Architectures: amd64 i386' "$f"
114+
done
115+
# Add ports.ubuntu.com for the foreign architecture
116+
printf 'Types: deb\nURIs: http://ports.ubuntu.com/ubuntu-ports\nSuites: %s %s-updates\nComponents: main universe\nArchitectures: %s\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg\n' \
117+
"$CODENAME" "$CODENAME" "${{ matrix.alsa_arch }}" | sudo tee /etc/apt/sources.list.d/ports.sources
118+
fi
119+
sudo apt-get update
120+
sudo apt-get install -y libasound2-dev:${{ matrix.alsa_arch }}
121+
122+
- name: Generate Windows import libraries
123+
if: matrix.goos == 'windows' && matrix.zig_target
124+
run: |
125+
ZIG_LIB=$(zig env | jq -r '.lib_dir')
126+
echo "ZIG_LIB=${ZIG_LIB}" >> "$GITHUB_ENV"
127+
LIB_DIR="${ZIG_LIB}/libc/mingw/lib-common"
128+
# Zig bundles MinGW .def files but lld needs .a import libraries.
129+
# Go's compiled objects embed COFF /DEFAULTLIB directives (e.g. dbghelp,
130+
# bcrypt) that lld resolves directly, bypassing Zig's lazy .def→.a
131+
# generation. Pre-generate all import libraries so lld can find them.
132+
MACHINE=${{ matrix.goarch == 'amd64' && 'i386:x86-64' || 'arm64' }}
133+
for def in "${LIB_DIR}"/*.def; do
134+
lib=$(basename "$def" .def)
135+
[ -f "${LIB_DIR}/lib${lib}.a" ] && continue
136+
zig dlltool -d "$def" -l "${LIB_DIR}/lib${lib}.a" -m "$MACHINE" 2>/dev/null || true
137+
done
138+
139+
- name: Build
140+
env:
141+
CGO_ENABLED: ${{ (matrix.goos && !matrix.zig_target) && '0' || '1' }}
142+
CC: ${{ matrix.zig_target && format('zig cc -target {0}', matrix.zig_target) || '' }}
143+
CXX: ${{ matrix.zig_target && format('zig c++ -target {0}', matrix.zig_target) || '' }}
144+
# Zig uses its own sysroot; point it at the system ALSA headers and libraries
145+
CGO_CFLAGS: ${{ matrix.alsa_triple && format('-isystem /usr/include -isystem /usr/include/{0}', matrix.alsa_triple) || '' }}
146+
CGO_LDFLAGS: ${{ matrix.alsa_triple && format('-L/usr/lib/{0}', matrix.alsa_triple) || '' }}
147+
# -fms-extensions: enable __try/__except (SEH) used by WebRTC
148+
# -DNTDDI_VERSION: target Windows 10 base to skip WinRT includes absent from MinGW
149+
CGO_CXXFLAGS: ${{ matrix.goos == 'windows' && '-fms-extensions -DNTDDI_VERSION=0x0A000000' || '' }}
150+
GOOS: ${{ matrix.goos || '' }}
151+
GOARCH: ${{ matrix.goarch || '' }}
152+
GOARM: ${{ matrix.goarm || '' }}
153+
shell: bash
154+
run: |
155+
EXT=""; if [ "${GOOS:-}" = "windows" ]; then EXT=".exe"; fi
156+
TAGS=""
157+
if [ "$CGO_ENABLED" = "1" ]; then TAGS="-tags console"; fi
158+
# Force external linking for Windows so Go uses zig cc (CC) as the linker,
159+
# and add Zig's MinGW lib path so lld can find the generated import libraries.
160+
EXTLD=""
161+
if [ "${GOOS:-}" = "windows" ] && [ "$CGO_ENABLED" = "1" ]; then
162+
EXTLD="-linkmode=external -extldflags '-L${ZIG_LIB}/libc/mingw/lib-common'"
163+
fi
164+
go build $TAGS -ldflags "-w -s $EXTLD" -o "bin/lk${EXT}" ./cmd/lk
165+
166+
- name: Verify binary
167+
if: "!matrix.goos && !matrix.goarch"
168+
run: bin/lk --help > /dev/null

0 commit comments

Comments
 (0)