adds cross-compiled multiplatform builds and infrastructure to load them

This commit is contained in:
Spencer Russell 2017-05-18 12:38:13 -04:00
parent 3e7c6b5c1b
commit efd70272ab
17 changed files with 1385 additions and 47 deletions

3
.gitignore vendored
View file

@ -5,3 +5,6 @@ deps/deps.jl
*.flac
*.cov
coverage
deps/usr/lib/pa_shim.so
deps/usr/lib/pa_shim.dylib
deps/usr/lib/pa_shim.dll

90
deps/src/Makefile vendored
View file

@ -1,68 +1,80 @@
# Makefile lifted from Clang.jl
# Makefile originally lifted from Clang.jl
# Copyright (c) 2012-: Isaiah Norton and [contributors](https://github.com/ihnorton/Clang.jl/graphs/contributors)
ifeq (exists, $(shell [ -e Make.user ] && echo exists ))
include Make.user
endif
TARGETDIR = ../usr/lib
TARGETDIR=../usr/lib
TARGETBASENAME=pa_shim
OBJS = pa_shim.o
# Figure out OS and architecture
OS=$(shell uname)
ifneq (,$(findstring MINGW,$(OS)))
OS=WINNT
# check to see if the user passed in a HOST variable for cross-compiling
ifeq ($(HOST),)
# Figure out OS and architecture
OS=$(shell uname)
ifneq ($(findstring MINGW,$(OS)),)
OS=WINNT
endif
else
HOSTSUFFIX=_$(HOST)
ifneq ($(findstring linux,$(HOST)),)
OS=Linux
else ifneq ($(findstring darwin,$(HOST)),)
OS=Darwin
else ifneq ($(findstring mingw,$(HOST)),)
OS=WINNT
endif
endif
# file extensions and platform-specific libs
CFLAGS = -Wall -Wno-strict-aliasing -fno-omit-frame-pointer -I../../../RingBuffers/deps/src
LDFLAGS +=
ifeq ($(OS), WINNT)
LIBS +=
LDFLAGS += -shared -L../../../RingBuffers/deps/usr/lib -lpa_ringbuffer
INC +=
SHACMD = sha256sum
SHLIB_EXT = dll
LIBS +=
LDFLAGS += -shared -L../../../RingBuffers/deps/usr/lib -lpa_ringbuffer$(HOSTSUFFIX)
INC +=
SHACMD = sha256sum
SHLIB_EXT = dll
else ifeq ($(OS), Darwin)
LIBS +=
INC +=
# we'll rely on Julia to load RingBuffers.jl, which will in turn load the C
# library that we depend on for these symbols
LDFLAGS += -dynamiclib -Wl,-undefined,dynamic_lookup
SHLIB_EXT = dylib
SHACMD = shasum -a256
LIBS +=
INC +=
# we'll rely on Julia to load RingBuffers.jl, which will in turn load the C
# library that we depend on for these symbols
LDFLAGS += -dynamiclib -Wl,-undefined,dynamic_lookup
SHLIB_EXT = dylib
SHACMD = shasum -a256
else
LIBS +=
INC +=
LDFLAGS += -shared
SHLIB_EXT = so
SHACMD = sha256sum
CFLAGS += -fPIC
LIBS +=
INC +=
LDFLAGS += -shared
SHLIB_EXT = so
SHACMD = sha256sum
endif
SOURCEHASH = $(shell $(SHACMD) pa_shim.c | awk '{print $$1}')
CFLAGS += -DSOURCEHASH=\"$(SOURCEHASH)\"
CFLAGS += -I../../../RingBuffers/deps/src -Wall -Wno-strict-aliasing -fno-omit-frame-pointer -fPIC -DSOURCEHASH=\"$(SOURCEHASH)\"
LDFLAGS +=
# LINUX_LIBS =-lrt
# LINUX_LDFLAGS =-rdynamic
# add the Homebrew.jl tree to the include dirs in case we used it for
# portaudio and libsndfile
# DARWIN_LDFLAGS =-L../../../Homebrew/deps/usr/lib
# DARWIN_INC =-I../../../Homebrew/deps/usr/include
TARGET=$(TARGETDIR)/$(TARGETBASENAME)$(HOSTSUFFIX).$(SHLIB_EXT)
TARGET = $(TARGETDIR)/pa_shim.$(SHLIB_EXT)
.PHONY: clean default
.PHONY: clean cleantemp default
default: $(TARGET)
%.o: %.c Makefile
$(CC) $< -fPIC -c -o $@ $(INC) $(CFLAGS)
$(CC) $< -c -o $@ $(INC) $(CFLAGS)
$(TARGETDIR):
mkdir -p $@
$(TARGET): $(OBJS) $(TARGETDIR) Makefile
$(CC) $(OBJS) -shared -o $@ $(LDFLAGS) $(LIBS)
$(CC) $(OBJS) $(LDFLAGS) -o $@ $(LIBS)
clean:
cleantemp:
rm -f $(OBJS)
rm -f $(TARGET)
clean: cleantemp
rm -f $(TARGETDIR)/$(TARGETBASENAME)*.so
rm -f $(TARGETDIR)/$(TARGETBASENAME)*.dylib
rm -f $(TARGETDIR)/$(TARGETBASENAME)*.dll

54
deps/src/build.sh vendored Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# User docker to build pa_shim library for all supported platforms.
set -e
make clean
echo ""
# NOTE: the darwin build ends up actually being x86_64-apple-darwin14. It gets
# mapped within the docker machine
for platform in \
arm-linux-gnueabihf \
powerpc64le-linux-gnu \
x86_64-apple-darwin \
x86_64-w64-mingw32 \
i686-w64-mingw32; do
echo "================================"
echo "building for $platform..."
docker run --rm \
-v $(pwd)/../..:/workdir \
-v $(pwd)/../../../RingBuffers:/RingBuffers \
-w /workdir/deps/src \
-e CROSS_TRIPLE=$platform \
multiarch/crossbuild \
./dockerbuild_cb.sh
echo "================================"
echo ""
done
# we use holy-build-box for the x86 linux builds because it uses an older
# glibc so it should be compatible with more user environments
echo "================================"
echo "building for x86_64-linux-gnu..."
docker run --rm \
-v $(pwd)/../..:/workdir \
-v $(pwd)/../../../RingBuffers:/RingBuffers \
-w /workdir/deps/src \
-e HOST=x86_64-linux-gnu \
phusion/holy-build-box-64 \
./dockerbuild_hbb.sh
echo "================================"
echo ""
echo "================================"
echo "building for i686-linux-gnu..."
docker run --rm \
-v $(pwd)/../..:/workdir \
-v $(pwd)/../../../RingBuffers:/RingBuffers \
-w /workdir/deps/src \
-e HOST=i686-linux-gnu \
phusion/holy-build-box-32 \
./dockerbuild_hbb.sh
echo "================================"

8
deps/src/dockerbuild_cb.sh vendored Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
# this script is run by build.sh within each docker instance to do the build.
set -e
make HOST=$CROSS_TRIPLE
make cleantemp

13
deps/src/dockerbuild_hbb.sh vendored Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
# this script is run by build.sh within each docker instance to do the build.
# it's meant to be run from within a "Holy Build Box" docker instance.
set -e
# Activate Holy Build Box environment.
source /hbb_exe/activate
set -x
make HOST=$HOST
make cleantemp

2
deps/src/pa_shim.c vendored
View file

@ -1,4 +1,4 @@
#include <portaudio.h>
#include "portaudio.h"
#include <pa_ringbuffer.h>
#include <stdio.h>
#include <unistd.h>

1225
deps/src/portaudio.h vendored Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.

BIN
deps/usr/lib/pa_shim_arm-linux-gnueabihf.so vendored Executable file

Binary file not shown.

BIN
deps/usr/lib/pa_shim_i686-linux-gnu.so vendored Executable file

Binary file not shown.

BIN
deps/usr/lib/pa_shim_i686-w64-mingw32.dll vendored Executable file

Binary file not shown.

BIN
deps/usr/lib/pa_shim_powerpc64le-linux-gnu.so vendored Executable file

Binary file not shown.

BIN
deps/usr/lib/pa_shim_x86_64-linux-gnu.so vendored Executable file

Binary file not shown.

BIN
deps/usr/lib/pa_shim_x86_64-w64-mingw32.dll vendored Executable file

Binary file not shown.

View file

@ -1,7 +1,28 @@
function init_pa_shim()
global const libpa_shim = Libdl.find_library(
["pa_shim"],
[joinpath(dirname(@__FILE__), "..", "deps", "usr", "lib")])
libdir = joinpath(dirname(@__FILE__), "..", "deps", "usr", "lib")
libsuffix = ""
basename = "pa_shim"
@static if is_linux() && Sys.ARCH == :x86_64
libsuffix = "x86_64-linux-gnu"
elseif is_linux() && Sys.ARCH == :i686
libsuffix = "i686-linux-gnu"
elseif is_apple() && Sys.ARCH == :x86_64
libsuffix = "x86_64-apple-darwin14"
elseif is_windows() && Sys.ARCH == :x86_64
libsuffix = "x86_64-w64-mingw32"
elseif is_windows() && Sys.ARCH == :i686
libsuffix = "i686-w64-mingw32"
elseif !any(
(sfx) -> isfile(joinpath(libdir, "$basename.$sfx")),
("so", "dll", "dylib"))
error("Unsupported platform $(Sys.MACHINE). You can build your own library by running `make` from $(joinpath(@__FILE__, "..", "deps", "src"))")
end
# if there's a suffix-less library, it was built natively on this machine,
# so load that one first, otherwise load the pre-built one
global const libpa_shim = Base.Libdl.find_library(
[basename, "$(basename)_$libsuffix"],
[libdir])
libpa_shim == "" && error("Could not load $basename library, please file an issue at https://github.com/JuliaAudio/RingBuffers.jl/issues with your `versioninfo()` output")
shim_dlib = Libdl.dlopen(libpa_shim)
# pointer to the shim's process callback
global const shim_processcb_c = Libdl.dlsym(shim_dlib, :pa_shim_processcb)

View file

@ -177,9 +177,8 @@ function test_callback_overflow(inchans, outchans, synced)
end
end
# these test are currently set up to run on OSX
@testset DottedTestSet "PortAudio Tests" begin
# these default values are specific to my machines
@testset ExtendedTestSet "PortAudio Tests" begin
if is_windows()
default_indev = "Microphone Array (Realtek High "
default_outdev = "Speaker/Headphone (Realtek High"
@ -205,7 +204,10 @@ end
result = split(String(take!((io))), "\n")
# make sure this is the same version I tested with
@test startswith(result[1], "PortAudio V19")
@test result[3] == "Shim Source Hash: 4ea2a8526b"
end
@testset "using correct shim version" begin
@test PortAudio.shimhash() == "87021557a9f999545828eb11e4ebad2cd278b734dd91a8bd3faf05c89912cf80"
end
@testset "Basic callback functionality" begin