Unverified Commit d3c83eaa authored by moto's avatar moto Committed by GitHub
Browse files

Self-contain codecs library (#625)

* Clean up extension build mechanism and extension location

* Add back the switch to depend on external sox

* Remove print

* Fix
parent b985609b
...@@ -329,18 +329,19 @@ jobs: ...@@ -329,18 +329,19 @@ jobs:
- restore_cache: - restore_cache:
keys: keys:
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} - env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
- run: - run:
name: Setup name: Setup
command: .circleci/unittest/linux/scripts/setup_env.sh command: .circleci/unittest/linux/scripts/setup_env.sh
- save_cache: - save_cache:
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
paths: paths:
- conda - conda
- env - env
- third_party/build
- run: - run:
name: Install torchaudio name: Install torchaudio
command: .circleci/unittest/linux/scripts/install.sh command: .circleci/unittest/linux/scripts/install.sh
...@@ -369,18 +370,19 @@ jobs: ...@@ -369,18 +370,19 @@ jobs:
- restore_cache: - restore_cache:
keys: keys:
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} - env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
- run: - run:
name: Setup name: Setup
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh
- save_cache: - save_cache:
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
paths: paths:
- conda - conda
- env - env
- third_party/build
- run: - run:
name: Install torchaudio name: Install torchaudio
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/install.sh command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/install.sh
...@@ -406,14 +408,14 @@ jobs: ...@@ -406,14 +408,14 @@ jobs:
- restore_cache: - restore_cache:
keys: keys:
- env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} - env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
- run: - run:
name: Setup name: Setup
command: .circleci/unittest/windows/scripts/setup_env.sh command: .circleci/unittest/windows/scripts/setup_env.sh
- save_cache: - save_cache:
key: env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} key: env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
paths: paths:
- conda - conda
......
...@@ -329,18 +329,19 @@ jobs: ...@@ -329,18 +329,19 @@ jobs:
- restore_cache: - restore_cache:
{% raw %} {% raw %}
keys: keys:
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} - env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %} {% endraw %}
- run: - run:
name: Setup name: Setup
command: .circleci/unittest/linux/scripts/setup_env.sh command: .circleci/unittest/linux/scripts/setup_env.sh
- save_cache: - save_cache:
{% raw %} {% raw %}
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %} {% endraw %}
paths: paths:
- conda - conda
- env - env
- third_party/build
- run: - run:
name: Install torchaudio name: Install torchaudio
command: .circleci/unittest/linux/scripts/install.sh command: .circleci/unittest/linux/scripts/install.sh
...@@ -369,18 +370,19 @@ jobs: ...@@ -369,18 +370,19 @@ jobs:
- restore_cache: - restore_cache:
{% raw %} {% raw %}
keys: keys:
- env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} - env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %} {% endraw %}
- run: - run:
name: Setup name: Setup
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh
- save_cache: - save_cache:
{% raw %} {% raw %}
key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %} {% endraw %}
paths: paths:
- conda - conda
- env - env
- third_party/build
- run: - run:
name: Install torchaudio name: Install torchaudio
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/install.sh command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/install.sh
...@@ -406,14 +408,14 @@ jobs: ...@@ -406,14 +408,14 @@ jobs:
- restore_cache: - restore_cache:
{% raw %} {% raw %}
keys: keys:
- env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} - env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %} {% endraw %}
- run: - run:
name: Setup name: Setup
command: .circleci/unittest/windows/scripts/setup_env.sh command: .circleci/unittest/windows/scripts/setup_env.sh
- save_cache: - save_cache:
{% raw %} {% raw %}
key: env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} key: env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %} {% endraw %}
paths: paths:
- conda - conda
......
...@@ -52,6 +52,9 @@ RUN apt update && apt install -y \ ...@@ -52,6 +52,9 @@ RUN apt update && apt install -y \
git \ git \
libatlas3-base \ libatlas3-base \
wget \ wget \
curl \
make \
file \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY --from=builder /kaldi /kaldi COPY --from=builder /kaldi /kaldi
COPY --from=builder /third_party /third_party COPY --from=builder /third_party /third_party
......
...@@ -20,9 +20,6 @@ fi ...@@ -20,9 +20,6 @@ fi
cd "$( dirname "${BASH_SOURCE[0]}" )" cd "$( dirname "${BASH_SOURCE[0]}" )"
root_dir="$(git rev-parse --show-toplevel)"
cp "${root_dir}"/packaging/build_from_source.sh ./scripts/build_third_parties.sh
# docker build also accepts reading from STDIN # docker build also accepts reading from STDIN
# but in that case, no context (other files) can be passed, so we write out Dockerfile # but in that case, no context (other files) can be passed, so we write out Dockerfile
sed "s|BASE_IMAGE|${base_image}|g" Dockerfile > Dockerfile.tmp sed "s|BASE_IMAGE|${base_image}|g" Dockerfile > Dockerfile.tmp
......
...@@ -20,6 +20,4 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}" ...@@ -20,6 +20,4 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
conda install -y -c pytorch-nightly pytorch "${cudatoolkit}" conda install -y -c pytorch-nightly pytorch "${cudatoolkit}"
printf "* Installing torchaudio\n" printf "* Installing torchaudio\n"
# Link codecs present at /third_party. See Dockerfile for how this is built python setup.py develop
ln -fs /third_party ./third_party
IS_CONDA=true python setup.py develop
...@@ -7,4 +7,4 @@ conda activate ./env ...@@ -7,4 +7,4 @@ conda activate ./env
python -m torch.utils.collect_env python -m torch.utils.collect_env
pytest --cov=torchaudio --junitxml=test-results/junit.xml -v --durations 20 test pytest --cov=torchaudio --junitxml=test-results/junit.xml -v --durations 20 test
flake8 torchaudio test flake8 torchaudio test build_tools/setup_helpers
...@@ -32,3 +32,6 @@ conda activate "${env_dir}" ...@@ -32,3 +32,6 @@ conda activate "${env_dir}"
# 3. Install Conda dependencies # 3. Install Conda dependencies
printf "* Installing dependencies (except PyTorch)\n" printf "* Installing dependencies (except PyTorch)\n"
conda env update --file "${this_dir}/environment.yml" --prune conda env update --file "${this_dir}/environment.yml" --prune
# 4. Build codecs
build_tools/setup_helpers/build_third_party.sh
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
ignore = E305,E402,E721,E741,F401,F403,F405,F999,W503,W504 ignore = E305,E402,E721,E741,F401,F403,F405,F999,W503,W504
exclude = build,docs/source,_ext exclude = build,docs/source,_ext,third_party
from .extension import * # noqa
#!/bin/bash
# Build third party libraries in `<repo_root>/third_party/build` or in `<given_prefix>/third_party/build`.
set -e
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
root_dir="${this_dir}/../.."
prefix="${1:-}"
if [ -z "${prefix}" ]; then
prefix="${root_dir}"
fi
tp_dir="${prefix}/third_party"
tmp_dir="${tp_dir}/tmp"
build_dir="${tp_dir}/build"
mkdir -p "${tmp_dir}" "${build_dir}"
. "${this_dir}/build_third_party_helper.sh"
if ! found_lame "${build_dir}" ; then
build_lame "${tmp_dir}" "${build_dir}"
fi
if ! found_flac "${build_dir}" ; then
build_flac "${tmp_dir}" "${build_dir}"
fi
if ! found_mad "${build_dir}" ; then
build_mad "${tmp_dir}" "${build_dir}"
fi
if ! found_sox "${build_dir}" ; then
build_sox "${tmp_dir}" "${build_dir}"
fi
#!/usr/bin/env bash
set -euo pipefail
# Global options
CURL_OPTS="-L --retry 10 --connect-timeout 5 --max-time 180"
MAKE_OPTS="-j"
CONFIG_OPTS=""
if [ -z ${DEBUG+x} ]; then
CURL_OPTS="${CURL_OPTS} --silent --show-error"
MAKE_OPTS="${MAKE_OPTS} --quiet"
CONFIG_OPTS="${CONFIG_OPTS} --quiet"
fi
all_found() {
dir="$1"
shift
while [ "$#" -gt 0 ]; do
if [ ! -f "${dir}/$1" ]; then
return 1
fi
shift
done
}
found_lame() {
all_found "$1" 'include/lame/lame.h' 'lib/libmp3lame.a'
}
found_flac() {
all_found "$1" \
'include/FLAC/format.h' \
'include/FLAC/stream_decoder.h' \
'include/FLAC/export.h' \
'include/FLAC/ordinals.h' \
'include/FLAC/all.h' \
'include/FLAC/assert.h' \
'include/FLAC/callback.h' \
'include/FLAC/metadata.h' \
'include/FLAC/stream_encoder.h' \
'include/FLAC++/export.h' \
'include/FLAC++/decoder.h' \
'include/FLAC++/all.h' \
'include/FLAC++/metadata.h' \
'include/FLAC++/encoder.h' \
'lib/libFLAC++.a' \
'lib/libFLAC.a'
}
found_mad() {
all_found "$1" 'include/mad.h' 'lib/libmad.a'
}
found_sox() {
all_found "$1" 'include/sox.h' 'lib/libsox.a'
}
build_lame() {
work_dir="$1"
install_dir="$2"
package="lame-3.99.5"
url="https://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz"
(
cd "${work_dir}"
if [ ! -d "${package}" ]; then
if [ ! -f "${package}.tar.gz" ]; then
printf "Fetching liblame from %s\n" "${url}"
curl $CURL_OPTS -o "${package}.tar.gz" "${url}"
fi
tar xfp "${package}.tar.gz"
fi
# build statically
printf "Building liblame\n"
cd "${package}"
if [ ! -f Makefile ]; then
./configure ${CONFIG_OPTS} \
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-pic --disable-debug --disable-dependency-tracking --enable-nasm
fi
make ${MAKE_OPTS} > make.log 2>&1
make ${MAKE_OPTS} install
)
}
build_flac() {
work_dir="$1"
install_dir="$2"
package="flac-1.3.2"
url="https://downloads.sourceforge.net/project/flac/flac-src/flac-1.3.2.tar.xz"
(
cd "${work_dir}"
if [ ! -d "${package}" ]; then
if [ ! -f "${package}.tar.xz" ]; then
printf "Fetching flac from %s\n" "${url}"
curl $CURL_OPTS -o "${package}.tar.xz" "${url}"
fi
tar xfp "${package}.tar.xz"
fi
# build statically
printf "Building flac\n"
cd "${package}"
if [ ! -f Makefile ]; then
./configure ${CONFIG_OPTS} \
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-pic --disable-debug --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
make ${MAKE_OPTS} install
)
}
build_mad() {
work_dir="$1"
install_dir="$2"
package="libmad-0.15.1b"
url="https://downloads.sourceforge.net/project/mad/libmad/0.15.1b/libmad-0.15.1b.tar.gz"
(
cd "${work_dir}"
if [ ! -d "${package}" ]; then
if [ ! -f "${package}.tar.gz" ]; then
printf "Fetching mad from %s\n" "${url}"
curl $CURL_OPTS -o "${package}.tar.gz" "${url}"
fi
tar xfp "${package}.tar.gz"
fi
# build statically
printf "Building mad\n"
cd "${package}"
if [ ! -f Makefile ]; then
# See https://stackoverflow.com/a/12864879/23845
sed -i.bak 's/-march=i486//' configure
./configure ${CONFIG_OPTS} \
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-pic --disable-debug --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
make ${MAKE_OPTS} install
)
}
build_sox() {
work_dir="$1"
install_dir="$2"
package="sox-14.4.2"
url="https://downloads.sourceforge.net/project/sox/sox/14.4.2/sox-14.4.2.tar.bz2"
(
cd "${work_dir}"
if [ ! -d "${package}" ]; then
if [ ! -f "${package}.tar.bz2" ]; then
printf "Fetching SoX from %s\n" "${url}"
curl $CURL_OPTS -o "${package}.tar.bz2" "${url}"
fi
tar xfp "${package}.tar.bz2"
fi
# build statically
printf "Building sox\n"
cd "${package}"
if [ ! -f Makefile ]; then
# --without-png makes OS X build less hazardous; somehow the build
# finds png and enables it. We don't want it; we'd need to package
# it statically if we do.
./configure ${CONFIG_OPTS} --disable-shared --enable-static --prefix="${install_dir}" \
LDFLAGS="-L${install_dir}/lib" CPPFLAGS="-I${install_dir}/include" \
--with-lame --with-flac --with-mad --without-alsa --without-coreaudio \
--without-png --without-oggvorbis --without-oss --without-sndfile \
CFLAGS=-fPIC CXXFLAGS=-fPIC --with-pic --disable-debug --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
make ${MAKE_OPTS} install
)
}
import platform
import subprocess
from pathlib import Path
from torch.utils.cpp_extension import (
CppExtension,
BuildExtension as TorchBuildExtension
)
__all__ = [
'get_ext_modules',
'BuildExtension',
]
_THIS_DIR = Path(__file__).parent.resolve()
_ROOT_DIR = _THIS_DIR.parent.parent.resolve()
_CSRC_DIR = _ROOT_DIR / 'torchaudio' / 'csrc'
_TP_BASE_DIR = _ROOT_DIR / 'third_party'
_TP_INSTALL_DIR = _TP_BASE_DIR / 'build'
# Temporary fix for building in fbcode
# at the moment, we have to use external sox in fbcode
_BUILD_DEPS = not (_ROOT_DIR / '.use_external_sox').exists()
def _get_eca(debug):
eca = []
if debug:
eca += ["-O0", "-g"]
else:
eca += ["-O3"]
return eca
def _get_ela(debug):
ela = []
if debug:
if platform.system() == "Windows":
ela += ["/DEBUG:FULL"]
else:
ela += ["-O0", "-g"]
else:
ela += ["-O3"]
return ela
def _get_srcs():
return [str(p) for p in _CSRC_DIR.glob('**/*.cpp')]
def _get_include_dirs():
dirs = [
str(_ROOT_DIR),
]
if _BUILD_DEPS:
dirs.append(str(_TP_INSTALL_DIR / 'include'))
return dirs
def _get_extra_objects():
objs = []
if _BUILD_DEPS:
# NOTE: The order of the library listed bellow matters.
#
# (the most important thing is that dependencies come after a library
# e.g., sox comes first)
libs = ['libsox.a', 'libmad.a', 'libFLAC.a', 'libmp3lame.a']
for lib in libs:
objs.append(str(_TP_INSTALL_DIR / 'lib' / lib))
return objs
def _get_libraries():
return [] if _BUILD_DEPS else ['sox']
def _build_codecs():
subprocess.run(
args=[str(_THIS_DIR / 'build_third_party.sh')],
check=True,
)
def _configure_third_party():
_build_codecs()
_EXT_NAME = 'torchaudio._torchaudio'
def get_ext_modules(debug=False):
if platform.system() == 'Windows':
return None
return [
CppExtension(
_EXT_NAME,
_get_srcs(),
libraries=_get_libraries(),
include_dirs=_get_include_dirs(),
extra_compile_args=_get_eca(debug),
extra_objects=_get_extra_objects(),
extra_link_args=_get_ela(debug),
),
]
class BuildExtension(TorchBuildExtension):
def build_extension(self, ext):
if ext.name == _EXT_NAME and _BUILD_DEPS:
_configure_third_party()
super().build_extension(ext)
...@@ -8,15 +8,12 @@ export BUILD_TYPE="wheel" ...@@ -8,15 +8,12 @@ export BUILD_TYPE="wheel"
export NO_CUDA_PACKAGE=1 export NO_CUDA_PACKAGE=1
setup_env 0.6.0 setup_env 0.6.0
setup_wheel_python setup_wheel_python
if [[ "$OSTYPE" != "msys" ]]; then
"$script_dir/build_from_source.sh" "$(pwd)" # Build static dependencies
fi
pip_install numpy future pip_install numpy future
setup_pip_pytorch_version setup_pip_pytorch_version
python setup.py clean python setup.py clean
if [[ "$OSTYPE" == "msys" ]]; then if [[ "$OSTYPE" == "msys" ]]; then
python_tag="$(echo "cp$PYTHON_VERSION" | tr -d '.')" python_tag="$(echo "cp$PYTHON_VERSION" | tr -d '.')"
IS_WHEEL=1 python setup.py bdist_wheel --plat-name win_amd64 --python-tag $python_tag python setup.py bdist_wheel --plat-name win_amd64 --python-tag $python_tag
else else
IS_WHEEL=1 python setup.py bdist_wheel python setup.py bdist_wheel
fi fi
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex set -ex
packaging/build_from_source.sh "$(pwd)" python setup.py install --single-version-externally-managed --record=record.txt
IS_CONDA=1 python setup.py install --single-version-externally-managed --record=record.txt
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import platform import shutil
import subprocess import subprocess
from pathlib import Path
import distutils.command.clean
from setuptools import setup, find_packages from setuptools import setup, find_packages
from torch.utils.cpp_extension import BuildExtension, CppExtension
def check_env_flag(name, default=''):
return os.getenv(name, default).upper() in set(['ON', '1', 'YES', 'TRUE', 'Y'])
DEBUG = check_env_flag('DEBUG')
IS_WHEEL = check_env_flag('IS_WHEEL')
IS_CONDA = check_env_flag('IS_CONDA')
print('DEBUG:', DEBUG, 'IS_WHEEL:', IS_WHEEL, 'IS_CONDA:', IS_CONDA)
eca = []
ela = []
if DEBUG:
if platform.system() == 'Windows':
ela += ['/DEBUG:FULL']
else:
eca += ['-O0', '-g']
ela += ['-O0', '-g']
from build_tools import setup_helpers
libraries = [] ROOT_DIR = Path(__file__).parent.resolve()
include_dirs = []
extra_objects = []
# Hypothetically, the conda distribution could rely on an external sox,
# but the library is pretty small and it is not available on the default
# anaconda channel. So we statically link it in, just as we do with wheels.
if IS_WHEEL or IS_CONDA:
audio_path = os.path.dirname(os.path.abspath(__file__))
include_dirs += [os.path.join(audio_path, 'third_party/flac/include')]
include_dirs += [os.path.join(audio_path, 'third_party/lame/include')]
include_dirs += [os.path.join(audio_path, 'third_party/sox/include')]
include_dirs += [os.path.join(audio_path, 'third_party/mad/include')]
# proper link order (sox, mad, flac, lame)
# (the most important thing is that dependencies come after a libraryl
# e.g., sox comes first)
extra_objects += [os.path.join(audio_path, 'third_party/sox/lib/libsox.a')]
extra_objects += [os.path.join(audio_path, 'third_party/mad/lib/libmad.a')]
extra_objects += [os.path.join(audio_path, 'third_party/flac/lib/libFLAC.a')]
extra_objects += [os.path.join(audio_path, 'third_party/lame/lib/libmp3lame.a')]
else:
libraries += ['sox']
# Creating the version file # Creating the version file
cwd = os.path.dirname(os.path.abspath(__file__))
version = '0.6.0a0' version = '0.6.0a0'
sha = 'Unknown' sha = 'Unknown'
try: try:
sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip() sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=ROOT_DIR).decode('ascii').strip()
except Exception: except Exception:
pass pass
...@@ -68,7 +26,7 @@ elif sha != 'Unknown': ...@@ -68,7 +26,7 @@ elif sha != 'Unknown':
version += '+' + sha[:7] version += '+' + sha[:7]
print('-- Building version ' + version) print('-- Building version ' + version)
version_path = os.path.join(cwd, 'torchaudio', 'version.py') version_path = ROOT_DIR / 'torchaudio' / 'version.py'
with open(version_path, 'w') as f: with open(version_path, 'w') as f:
f.write("__version__ = '{}'\n".format(version)) f.write("__version__ = '{}'\n".format(version))
f.write("git_version = {}\n".format(repr(sha))) f.write("git_version = {}\n".format(repr(sha)))
...@@ -79,19 +37,25 @@ pytorch_package_dep = 'torch' ...@@ -79,19 +37,25 @@ pytorch_package_dep = 'torch'
if pytorch_package_version is not None: if pytorch_package_version is not None:
pytorch_package_dep += "==" + pytorch_package_version pytorch_package_dep += "==" + pytorch_package_version
if platform.system() == 'Windows':
ext_modules = None class clean(distutils.command.clean.clean):
else: def run(self):
ext_modules = [ # Run default behavior first
CppExtension( distutils.command.clean.clean.run(self)
'torchaudio._torchaudio',
['torchaudio/csrc/sox.cpp'], # Remove torchaudio extension
libraries=libraries, for path in (ROOT_DIR / 'torchaudio').glob('**/*.so'):
include_dirs=include_dirs + [cwd], print(f'removing \'{path}\'')
extra_compile_args=eca, path.unlink()
extra_objects=extra_objects, # Remove build directory
extra_link_args=ela), build_dirs = [
] ROOT_DIR / 'build',
ROOT_DIR / 'third_party' / 'build',
]
for path in build_dirs:
if path.exists():
print(f'removing \'{path}\' (and everything under it)')
shutil.rmtree(str(path), ignore_errors=True)
setup( setup(
...@@ -116,8 +80,10 @@ setup( ...@@ -116,8 +80,10 @@ setup(
"Topic :: Multimedia :: Sound/Audio", "Topic :: Multimedia :: Sound/Audio",
"Topic :: Scientific/Engineering :: Artificial Intelligence" "Topic :: Scientific/Engineering :: Artificial Intelligence"
], ],
packages=find_packages(exclude=["build*", "test*", "torchaudio.csrc*"]), packages=find_packages(exclude=["build*", "test*", "torchaudio.csrc*", "third_party*", "build_tools*"]),
ext_modules=ext_modules, ext_modules=setup_helpers.get_ext_modules(),
cmdclass={'build_ext': BuildExtension}, cmdclass={
'build_ext': setup_helpers.BuildExtension.with_options(no_python_abi_suffix=True)
},
install_requires=[pytorch_package_dep] install_requires=[pytorch_package_dep]
) )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment