Skip to content

Commit

Permalink
Merge pull request #3150 from mozilla/ios-build
Browse files Browse the repository at this point in the history
iOS support
  • Loading branch information
reuben authored Jul 20, 2020
2 parents 972f303 + 2672878 commit ffcec7f
Show file tree
Hide file tree
Showing 49 changed files with 2,661 additions and 156 deletions.
1 change: 1 addition & 0 deletions native_client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ tf_cc_shared_object(
}) + tflite_copts(),
linkopts = select({
"//tensorflow:macos": [],
"//tensorflow:ios": ["-fembed-bitcode"],
"//tensorflow:linux_x86_64": LINUX_LINKOPTS,
"//tensorflow:rpi3": LINUX_LINKOPTS,
"//tensorflow:rpi3-armv8": LINUX_LINKOPTS,
Expand Down
10 changes: 7 additions & 3 deletions native_client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <sstream>
#include <string>

#if defined(__ANDROID__) || defined(_MSC_VER)
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif

#if defined(__ANDROID__) || defined(_MSC_VER) || TARGET_OS_IPHONE
#define NO_SOX
#endif

Expand Down Expand Up @@ -244,7 +248,7 @@ GetAudioBuffer(const char* path, int desired_sample_rate)
sox_false // Reverse endianness
};

#ifdef __APPLE__
#if TARGET_OS_OSX
// It would be preferable to use sox_open_memstream_write here, but OS-X
// doesn't support POSIX 2008, which it requires. See Issue #461.
// Instead, we write to a temporary file.
Expand Down Expand Up @@ -348,7 +352,7 @@ GetAudioBuffer(const char* path, int desired_sample_rate)
fclose(wave);
#endif // NO_SOX

#ifdef __APPLE__
#if TARGET_OS_OSX
res.buffer_size = (size_t)(output->olength * 2);
res.buffer = (char*)malloc(sizeof(char) * res.buffer_size);
FILE* output_file = fopen(output_name, "rb");
Expand Down
22 changes: 20 additions & 2 deletions native_client/definitions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,34 @@ NODE_PLATFORM_TARGET := --target_arch=arm64 --target_platform=linux
TOOLCHAIN_LDD_OPTS := --root $(RASPBIAN)/
endif # ($(TARGET),rpi3-armv8)

ifeq ($(TARGET),ios-simulator)
CFLAGS := -isysroot $(shell xcrun -sdk iphonesimulator13.5 -show-sdk-path)
SOX_CFLAGS :=
SOX_LDFLAGS :=
LDFLAGS :=
endif

ifeq ($(TARGET),ios-arm64)
CFLAGS := -target arm64-apple-ios -isysroot $(shell xcrun -sdk iphoneos13.5 -show-sdk-path)
SOX_CFLAGS :=
SOX_LDFLAGS :=
LDFLAGS :=
endif

# -Wl,--no-as-needed is required to force linker not to evict libs it thinks we
# dont need ; will fail the build on OSX because that option does not exists
ifeq ($(OS),Linux)
LDFLAGS_NEEDED := -Wl,--no-as-needed
LDFLAGS_RPATH := -Wl,-rpath,\$$ORIGIN
endif
ifeq ($(OS),Darwin)
CXXFLAGS += -stdlib=libc++ -mmacosx-version-min=10.10
LDFLAGS_NEEDED := -stdlib=libc++ -mmacosx-version-min=10.10
CXXFLAGS += -stdlib=libc++
LDFLAGS_NEEDED := -stdlib=libc++
LDFLAGS_RPATH := -Wl,-rpath,@executable_path
ifeq ($(TARGET),host)
CXXFLAGS += -mmacosx-version-min=10.10
LDFLAGS_NEEDED += -mmacosx-version-min=10.10
endif
endif

CFLAGS += $(EXTRA_CFLAGS)
Expand Down
4 changes: 4 additions & 0 deletions native_client/swift/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
build/
xcuserdata/
/deepspeech_ios/libdeepspeech.dylib
Loading

0 comments on commit ffcec7f

Please sign in to comment.