Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build codecs from source on Windows #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ jobs:
include:
- os: macos-latest
arch: arm64
shell: bash
- os: macos-latest
arch: x86_64
shell: bash
- os: ubuntu-latest
arch: aarch64
shell: bash
- os: ubuntu-latest
arch: i686
shell: bash
- os: ubuntu-latest
arch: x86_64
shell: bash
- os: windows-latest
arch: AMD64
- os: windows-latest
arch: x86
shell: 'msys2 {0}'
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -31,19 +38,24 @@ jobs:
- name: Install qemu (linux)
if: matrix.os == 'ubuntu-latest'
uses: docker/setup-qemu-action@v2
- name: Install msys2 (Windows)
if: matrix.os == 'windows-latest'
uses: msys2/setup-msys2@v2
with:
install: base-devel mingw-w64-x86_64-gcc mingw-w64-x86_64-nasm
path-type: inherit
- name: Build codecs
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BEFORE_BUILD: python scripts/build-codecs.py /tmp/vendor
CIBW_BEFORE_BUILD_WINDOWS: scripts\build-codecs.bat C:\cibw\vendor
CIBW_BEFORE_BUILD_WINDOWS: python scripts\build-codecs.py C:\cibw\vendor
CIBW_BUILD: cp38-*
CIBW_SKIP: "*musllinux*"
CIBW_TEST_COMMAND: python -c "import dummy"
run: |
pip install cibuildwheel
cibuildwheel --output-dir output
rm -f output/*.whl
shell: bash
- name: Upload codecs
uses: actions/upload-artifact@v3
with:
Expand Down
50 changes: 40 additions & 10 deletions scripts/build-codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,36 @@
shutil.rmtree(d)


def fetch(url, path):
run(["curl", "-L", "-o", path, url])


def mangle_path(path):
if platform.system() == "Windows":
return path.replace(os.path.sep, "/").replace("C:", "/c").replace("D:", "/d")
else:
return path


def build(package, configure_args=[]):
path = os.path.join(build_dir, package)
os.chdir(path)
run(["./configure"] + configure_args + ["--prefix=" + dest_dir])
package_path = os.path.join(build_dir, package)

# update config.guess and config.sub
config_files = ("config.guess", "config.sub")
for root, dirs, files in os.walk(package_path):
for name in filter(lambda x: x in config_files, files):
script_path = os.path.join(root, name)
cache_path = os.path.join(source_dir, name)
if not os.path.exists(cache_path):
fetch(
"https://git.savannah.gnu.org/cgit/config.git/plain/" + name,
cache_path,
)
shutil.copy(cache_path, script_path)
os.chmod(script_path, 0o755)

os.chdir(package_path)
run(["sh", "./configure"] + configure_args + ["--prefix=" + mangle_path(dest_dir)])
run(["make"])
run(["make", "install"])
os.chdir(build_dir)
Expand Down Expand Up @@ -63,7 +89,7 @@ def extract(package, url, *, strip_components=1):

# download tarball
if not os.path.exists(tarball):
run(["curl", "-L", "-o", tarball, url])
fetch(url, tarball)

# extract tarball
os.mkdir(path)
Expand All @@ -81,7 +107,7 @@ def run(cmd):


output_dir = os.path.abspath("output")
if platform.system() == "Linux":
if platform.system() == "Linux" and os.environ.get("CIBUILDWHEEL") == "1":
output_dir = "/output"
output_tarball = os.path.join(output_dir, f"codecs-{get_platform()}.tar.gz")

Expand All @@ -100,18 +126,22 @@ def run(cmd):
"amd64-apple-darwin20.6.0",
]
vpx_configure_args = ["--target=arm64-darwin20-gcc"]
elif platform.system() == "Windows":
opus_configure_args = []
vpx_configure_args = ["--target=x86_64-win64-gcc"]
else:
opus_configure_args = []
vpx_configure_args = []

#### BUILD TOOLS ####

# install nasm
extract(
"nasm",
"https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2",
)
build("nasm")
if platform.system() != "Windows":
extract(
"nasm",
"https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2",
)
build("nasm")

#### CODECS ###

Expand Down