Skip to content

Commit

Permalink
Build libsrtp with OpenSSL
Browse files Browse the repository at this point in the history
This allows us to make use of GCM.
  • Loading branch information
jlaine committed Jan 11, 2024
1 parent 19809b5 commit 571de1c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BEFORE_BUILD: python scripts/build-libsrtp.py /tmp/vendor
CIBW_BEFORE_BUILD_WINDOWS: scripts\build-libsrtp.bat C:\cibw\vendor
CIBW_ENVIRONMENT: CFLAGS=-I/tmp/vendor/include LDFLAGS=-L/tmp/vendor/lib
CIBW_ENVIRONMENT: CFLAGS=-I/tmp/vendor/include LDFLAGS=-L/tmp/vendor/lib PKG_CONFIG_PATH=/tmp/vendor/lib/pkgconfig
CIBW_ENVIRONMENT_WINDOWS: INCLUDE=C:\\cibw\\vendor\\include LIB=C:\\cibw\\vendor\\lib
CIBW_SKIP: '*-musllinux*'
CIBW_TEST_COMMAND: python -m unittest discover -s {project}/tests
Expand Down
6 changes: 4 additions & 2 deletions scripts/build-libsrtp.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
set destdir=%1

for %%d in (libsrtp %destdir%) do (
python scripts\fetch-vendor.py %destdir%

for %%d in (libsrtp) do (
if exist %%d (
rmdir /s /q %%d
)
Expand All @@ -15,7 +17,7 @@ if "%PYTHON_ARCH%" == "64" (
) else (
set CMAKE_OPTIONS=-A Win32
)
cmake . -G "Visual Studio 17 2022" %CMAKE_OPTIONS%
cmake . -G "Visual Studio 17 2022" %CMAKE_OPTIONS% -DENABLE_OPENSSL=ON
cmake --build . --config Release

mkdir %destdir%
Expand Down
5 changes: 4 additions & 1 deletion scripts/build-libsrtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
dest_dir = sys.argv[1]
build_dir = os.path.abspath("build")

for d in [build_dir, dest_dir]:
for d in [build_dir]:
if os.path.exists(d):
shutil.rmtree(d)

Expand All @@ -25,11 +25,14 @@ def run(cmd):
"-DCMAKE_INSTALL_PREFIX=" + dest_dir,
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
"-DENABLE_OPENSSL=ON",
]
if platform.system() == "Darwin" and "ARCHFLAGS" in os.environ:
archs = [x for x in os.environ["ARCHFLAGS"].split() if x != "-arch"]
cmake_args.append("-DCMAKE_OSX_ARCHITECTURES=" + ";".join(archs))

run(["python", "scripts/fetch-vendor.py", dest_dir])

run(["git", "clone", "https://github.com/cisco/libsrtp/", build_dir])
os.chdir(build_dir)
run(["git", "checkout", "-qf", "v2.5.0"])
Expand Down
3 changes: 3 additions & 0 deletions scripts/fetch-vendor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"urls": ["https://github.com/aiortc/aioquic-openssl/releases/download/3.2.0-1/openssl-{platform}.tar.gz"]
}
64 changes: 64 additions & 0 deletions scripts/fetch-vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import argparse
import logging
import json
import os
import platform
import shutil
import struct
import subprocess


def get_platform():
system = platform.system()
machine = platform.machine()
if system == "Linux":
return f"manylinux_{machine}"
elif system == "Darwin":
# cibuildwheel sets ARCHFLAGS:
# https://github.com/pypa/cibuildwheel/blob/5255155bc57eb6224354356df648dc42e31a0028/cibuildwheel/macos.py#L207-L220
if "ARCHFLAGS" in os.environ:
machine = os.environ["ARCHFLAGS"].split()[1]
return f"macosx_{machine}"
elif system == "Windows":
if struct.calcsize("P") * 8 == 64:
return "win_amd64"
else:
return "win32"
else:
raise Exception(f"Unsupported system {system}")


parser = argparse.ArgumentParser(description="Fetch and extract tarballs")
parser.add_argument("destination_dir")
parser.add_argument("--cache-dir", default="tarballs")
parser.add_argument("--config-file", default=os.path.splitext(__file__)[0] + ".json")
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)

# read config file
with open(args.config_file, "r") as fp:
config = json.load(fp)

# create fresh destination directory
logging.info("Creating directory %s" % args.destination_dir)
if os.path.exists(args.destination_dir):
shutil.rmtree(args.destination_dir)
os.makedirs(args.destination_dir)

for url_template in config["urls"]:
tarball_url = url_template.replace("{platform}", get_platform())

# download tarball
tarball_name = tarball_url.split("/")[-1]
tarball_file = os.path.join(args.cache_dir, tarball_name)
if not os.path.exists(tarball_file):
logging.info("Downloading %s" % tarball_url)
if not os.path.exists(args.cache_dir):
os.mkdir(args.cache_dir)
subprocess.check_call(
["curl", "--location", "--output", tarball_file, "--silent", tarball_url]
)

# extract tarball
logging.info("Extracting %s" % tarball_name)
subprocess.check_call(["tar", "-C", args.destination_dir, "-xf", tarball_file])
4 changes: 3 additions & 1 deletion src/_cffi_src/build_srtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

libraries = ["srtp2"]
if sys.platform == "win32":
libraries += ["ws2_32"]
libraries += ["libcrypto", "advapi32", "crypt32", "gdi32", "user32", "ws2_32"]
else:
libraries += ["crypto"]

ffibuilder = FFI()
ffibuilder.set_source(
Expand Down

0 comments on commit 571de1c

Please sign in to comment.