From cb4a695e38c9e82937b06e4c743e2d6d591105fe Mon Sep 17 00:00:00 2001 From: Steven Sherry Date: Fri, 5 Mar 2021 21:48:15 -0600 Subject: [PATCH] Feature/m1 and friends (#6) * Initial run at m1 support * Fix task call --- .github/workflows/build.yml | 8 +- .github/workflows/deliver.yml | 27 +- .gitignore | 4 +- Makefile | 378 -------------------- Taskfile.yml | 646 ++++++++++++++++++++++++++++++++++ build.sh | 9 - build_all.sh | 76 ---- update_package_swift.py | 39 ++ 8 files changed, 709 insertions(+), 478 deletions(-) delete mode 100644 Makefile create mode 100644 Taskfile.yml delete mode 100644 build.sh delete mode 100644 build_all.sh create mode 100644 update_package_swift.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 315da07..45256d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,8 +18,8 @@ jobs: steps: - uses: actions/checkout@v1 - name: Install automake and pkg-config - run: brew install automake pkg-config - - name: Switch to Xcode 12 - run: sudo xcode-select --switch /Applications/Xcode_12_beta.app/Contents/Developer + run: brew install automake pkg-config go-task/tap/go-task + - name: Switch to Xcode 12.4 + run: sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer - name: Build libtesseract - run: sh build_all.sh + run: task build-tesseract-xcframework diff --git a/.github/workflows/deliver.yml b/.github/workflows/deliver.yml index abdc994..8ec8db8 100644 --- a/.github/workflows/deliver.yml +++ b/.github/workflows/deliver.yml @@ -11,21 +11,28 @@ jobs: if: "!contains(github.event.head_commit.message, 'Do not upload')" steps: - uses: actions/checkout@v1 - - name: Install automake and pkg-config - run: brew install automake pkg-config - - name: Switch to Xcode 12 - run: sudo xcode-select --switch /Applications/Xcode_12_beta.app/Contents/Developer - - name: Build libtesseract - run: sh build_all.sh + - name: Install automake, pkg-config, and task + run: brew install automake pkg-config go-task/tap/go-task + - name: Switch to Xcode 12.4 + run: sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer - name: Assign Tag Number to RELEASE_VERSION environment variable run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF#refs/*/*/} - - name: Push artifact to Bintray - run: go run publish.go -path ../build/libtesseract.xcframework -version $RELEASE_VERSION -bintray-key ${{ secrets.BINTRAY_KEY }} - working-directory: publish + - name: Build libtesseract + run: task build-tesseract-xcframework-zip + - name: Update Package.swift + run: python3 update_package_swift.py --version $RELEASE_VERSION - name: Commit Package.swift update uses: EndBug/add-and-commit@v4 with: add: 'Package.swift' message: 'Auto-updating Package.swift' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create draft release + uses: ncipollo/release-action@v1 + with: + artifact: "libtesseract-${{env.RELEASE_VERSION}}.xcframework.zip" + draft: true + allowUpdates: true + tag: ${{env.RELEASE_VERSION}} + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index c632e79..b757ae9 100644 --- a/.gitignore +++ b/.gitignore @@ -93,4 +93,6 @@ leptonica-* tiff-* libpng-* 4.*.zip -tesseract-* \ No newline at end of file +tesseract-* +.vscode +.swiftpm \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index c5bf49b..0000000 --- a/Makefile +++ /dev/null @@ -1,378 +0,0 @@ -# Beware, this Makefile is a hot-mess hodgpodge that has accumulated cruft -# and changes and additions over the last couple of years and -# probably makes zero sense at first (and probably second and third) glance. -# You will see references to "fat" libaries that haven't been renamed after -# this was adapted to only build single architecture binaries. -# Many dragons lie beyond this comment block -PNG_VERSION := 1.6.36 -PNG_NAME := libpng-$(PNG_VERSION) -JPEG_SRC_NAME := jpegsrc.v9c -# folder name after the JPEG_SRC_NAME archive has been unpacked -JPEG_DIR_NAME := jpeg-9c -TIFF_NAME := tiff-4.0.10 - -TESSERACT_VERSION ?= 4.1.0 -TESSERACT_NAME := tesseract-$(TESSERACT_VERSION) -LEPTONICA_VERSION ?= 1.79.0 -LEPTON_NAME := leptonica-$(LEPTONICA_VERSION) - - -SRC_DIR = $(shell pwd) -TESSERACT_SRC = $(SRC_DIR)/$(TESSERACT_NAME) -LEPTON_SRC = $(SRC_DIR)/$(LEPTON_NAME) -PNG_SRC = $(SRC_DIR)/$(PNG_NAME) -JPEG_SRC = $(SRC_DIR)/$(JPEG_DIR_NAME) -TIFF_SRC = $(SRC_DIR)/$(TIFF_NAME) - -libtessfiles = libtesseract.a -libleptfiles = liblept.a -libpngfiles = libpng.a -libjpegfiles = libjpeg.a -libtifffiles = libtiff.a - -libpngconfig = $(PNG_SRC)/configure -libjpegconfig = $(JPEG_SRC)/configure -libtiffconfig = $(TIFF_SRC)/configure -libtessautogen = $(TESSERACT_SRC)/autogen.sh -libtessconfig = $(TESSERACT_SRC)/configure -libleptautogen = $(LEPTON_SRC)/autogen.sh -libleptconfig = $(LEPTON_SRC)/configure - -XCODE_DEVELOPER_PATH="`xcode-select -p`" -XCODE_DEVELOPER_PATH_BIN=$(XCODE_DEVELOPER_PATH)/usr/bin -TARGET_CXX="$(XCODE_DEVELOPER_PATH_BIN)/g++" -TARGET_CXX_FOR_BUILD="$(XCODE_DEVELOPER_PATH_BIN)/g++" -TARGET_CC="$(XCODE_DEVELOPER_PATH_BIN)/gcc" - -# platform specific config -ifeq ($(platform), ios) - PLATFORM_PREFIX=ios - sdk = $(shell xcrun --sdk iphoneos --show-sdk-path) - platform_version_min = iphoneos-version-min="11.0" - arch = arm64 - arch_name = arm-apple-darwin64 - host = $(arch_name) - ARCHS ?= $(arch) -else ifeq ($(platform), simulator) - PLATFORM_PREFIX=simulator - sdk = $(shell xcrun --sdk iphonesimulator --show-sdk-path) - platform_version_min = ios-simulator-version-min="11.0" - arch = x86_64 - arch_name = x86_64-apple-darwin - host = $(arch_name) - ARCHS ?= $(arch) -else ifeq ($(platform), catalyst) - PLATFORM_PREFIX=catalyst - sdk = $(shell xcrun --sdk macosx --show-sdk-path) - platform_version_min = iphoneos-version-min="13.0" - arch = x86_64 - arch_name = x86_64-apple-ios13.0-macabi - host = x86_64-apple-darwin - ARCHS ?= $(arch) -else ifeq ($(platform), macos) - PLATFORM_PREFIX=macos - sdk = $(shell xcrun --sdk macosx --show-sdk-path) - platform_version_min = macosx-version-min="10.13" - arch = x86_64 - arch_name = x86_64-apple-darwin - host = $(arch_name) - ARCHS ?= $(arch) -endif - -INCLUDE_DIR = $(shell pwd)/$(PLATFORM_PREFIX)/include -LEPT_INC_DIR = $(INCLUDE_DIR) -TESS_INC_DIR = $(INCLUDE_DIR) -IMAGE_LIB_DIR = $(INCLUDE_DIR) -IMAGE_INC_DIR = $(INCLUDE_DIR) -LIB_FAT_DIR = $(INCLUDE_DIR) - -libpngfolder = $(PNG_SRC)/$(arch)/ -libjpegfolder = $(JPEG_SRC)/$(arch)/ -libtifffolder = $(TIFF_SRC)/$(arch)/ -libleptfolder = $(LEPTON_SRC)/$(PLATFORM_PREFIX)/$(arch)/ -libtessfolder = $(TESSERACT_SRC)/$(PLATFORM_PREFIX)/$(arch)/ - -libpngmakefile = $(addprefix $(libpngfolder), Makefile) -libjpegmakefile = $(addprefix $(libjpegfolder), Makefile) -libtiffmakefile = $(addprefix $(libtifffolder), Makefile) -libleptmakefile = $(addprefix $(libleptfolder), Makefile) -libtessmakefile = $(addprefix $(libtessfolder), Makefile) - -install_liblept = $(LIB_FAT_DIR)/$(libleptfiles) -install_libtess = $(LIB_FAT_DIR)/$(libtessfiles) -install_libpngfat = $(LIB_FAT_DIR)/$(libpngfiles) -install_libjpegfat = $(LIB_FAT_DIR)/$(libjpegfiles) -install_libtifffat = $(LIB_FAT_DIR)/$(libtifffiles) - -libtess = $(addprefix $(libtessfolder)lib/, $(libtessfiles)) -liblept = $(addprefix $(libleptfolder)lib/, $(libleptfiles)) -libpng = $(addprefix $(libpngfolder)lib/, $(libpngfiles)) -libjpeg = $(addprefix $(libjpegfolder)lib/, $(libjpegfiles)) -libtiff = $(addprefix $(libtifffolder)lib/, $(libtifffiles)) - -dependant_libs = $(install_libpngfat) $(install_libjpegfat) $(install_libtifffat) $(install_liblept) $(install_libtess) - -common_cflags = -arch $(arch) -pipe -no-cpp-precomp -isysroot $$SDKROOT -m$(platform_version_min) -O2 - -ifneq (,$(filter $(platform),ios simulator catalyst macos)) -.PHONY : all -all : $(dependant_libs) -else -.PHONY : all -all : - $(MAKE) platform=ios - $(MAKE) platform=simulator - $(MAKE) platform=catalyst - $(MAKE) platform=macos -endif - -####################### -# Build libtiff and all of its dependencies -####################### - -$(install_libtifffat) : $(libtiff) - mkdir -p $(@D) - cp $(realpath $(addsuffix lib/$(@F), $(libtifffolder)) ) $@ - mkdir -p $(IMAGE_INC_DIR) - cp -rvf $(firstword $(libtifffolder))include/*.h $(IMAGE_INC_DIR) - -$(libtiff) : $(libtiffmakefile) - cd $(abspath $(@D)/..) ; \ - $(MAKE) -sj8 && $(MAKE) install - -$(TIFF_SRC)/%/Makefile : $(libtiffconfig) - export SDKROOT="$(sdk)" ; \ - export CFLAGS="$(common_cflags) -fembed-bitcode" ; \ - export CPPFLAGS=$$CFLAGS ; \ - export CXXFLAGS="$$CFLAGS -Wno-deprecated-register"; \ - export LDFLAGS="-L$$SDKROOT/usr/lib/" ; \ - mkdir -p $(@D) ; \ - cd $(@D) ; \ - ../configure CXX="$(TARGET_CXX) --target=$(arch_name)" CC="$(TARGET_CC) --target=$(arch_name)" --host=$(host) --enable-fast-install --enable-shared=no --prefix=`pwd` --without-x --with-jpeg-include-dir=$(abspath $(@D)/../../$(JPEG_DIR_NAME)/$(arch)/include) --with-jpeg-lib-dir=$(abspath $(@D)/../../$(JPEG_DIR_NAME)/$(arch)/lib) - - -$(install_libpngfat) : $(libpng) - mkdir -p $(@D) - cp $(realpath $(addsuffix lib/$(@F), $(libpngfolder)) ) $@ - mkdir -p $(IMAGE_INC_DIR)/libpng - cp -rvf $(firstword $(libpngfolder))include/*.h $(IMAGE_INC_DIR) - -$(libpng) : $(libpngmakefile) - cd $(abspath $(@D)/..) ; \ - $(MAKE) -sj8 && $(MAKE) install - -$(PNG_SRC)/%/Makefile : $(libpngconfig) - export SDKROOT="$(sdk)" ; \ - export CFLAGS="$(common_cflags) -fembed-bitcode" ; \ - export CPPFLAGS=$$CFLAGS ; \ - export CXXFLAGS="$$CFLAGS -Wno-deprecated-register"; \ - export LDFLAGS="-L$$SDKROOT/usr/lib/" ; \ - mkdir -p $(@D) ; \ - cd $(@D) ; \ - ../configure CXX="$(TARGET_CXX) --target=$(arch_name)" CC="$(TARGET_CC) --target=$(arch_name)" --host=$(host) --enable-shared=no --prefix=`pwd` - -$(install_libjpegfat) : $(libjpeg) - mkdir -p $(@D) - cp $(realpath $(addsuffix lib/$(@F), $(libjpegfolder)) ) $@ - mkdir -p $(IMAGE_INC_DIR)/libjpeg - cp -rvf $(firstword $(libjpegfolder))include/*.h $(IMAGE_INC_DIR) - -$(libjpeg) : $(libjpegmakefile) - cd $(abspath $(@D)/..) ; \ - $(MAKE) -sj8 && $(MAKE) install - -$(JPEG_SRC)/%/Makefile : $(libjpegconfig) - export SDKROOT="$(sdk)" ; \ - export CFLAGS="$(common_cflags) -fembed-bitcode" ; \ - export CPPFLAGS=$$CFLAGS ; \ - export CXXFLAGS="$$CFLAGS -Wno-deprecated-register"; \ - export LDFLAGS="-L$$SDKROOT/usr/lib/" ; \ - mkdir -p $(@D) ; \ - cd $(@D) ; \ - ../configure CXX="$(TARGET_CXX) --target=$(arch_name)" CC="$(TARGET_CC) --target=$(arch_name)" --host=$(host) --enable-shared=no --prefix=`pwd` - -####################### -# TESSERACT-OCR -####################### -$(install_libtess) : $(libtess) - mkdir -p $(LIB_FAT_DIR) - cp $(realpath $(addsuffix lib/$(@F), $(libtessfolder)) ) $@ - mkdir -p $(TESS_INC_DIR) - cp -rvf $(firstword $(libtessfolder))include/tesseract/** $(TESS_INC_DIR) - -$(libtess) : $(libtessmakefile) - cd $(abspath $(@D)/..) && $(MAKE) -sj8 && $(MAKE) install - -$(TESSERACT_SRC)/$(PLATFORM_PREFIX)/%/Makefile : $(libtessconfig) $(install_liblept) - export LIBS="-lz -lpng -ljpeg -ltiff" ; \ - export SDKROOT="$(sdk)" ; \ - export CFLAGS="-I$(TESSERACT_SRC)/$(PLATFORM_PREFIX)/$(arch_name)/ $(common_cflags) -fembed-bitcode" ; \ - export CPPFLAGS=$$CFLAGS ; \ - export CXXFLAGS="-I$(TESSERACT_SRC)/$(PLATFORM_PREFIX)/$*/ $(common_cflags) -Wno-deprecated-register"; \ - export LDFLAGS="-L$$SDKROOT/usr/lib/ -L$(LIB_FAT_DIR) -L$(LEPTON_SRC)/$(PLATFORM_PREFIX)/$*/src/.libs" ; \ - export LIBLEPT_HEADERSDIR=$(TESSERACT_SRC)/$(PLATFORM_PREFIX)/$*/ ; \ - export PKG_CONFIG_PATH=$(LEPTON_SRC)/$(PLATFORM_PREFIX)/$*/ ; \ - export CXX="$(TARGET_CXX) --target=$(arch_name)" ; \ - export CXX_FOR_BUILD="$(TARGET_CXX_FOR_BUILD) --target=$(arch_name)" ; \ - export CC="$(TARGET_CC) --target=$(arch_name)" ; \ - mkdir -p $(@D) ; \ - cd $(@D) ; \ - ln -s $(LEPTON_SRC)/src/ leptonica ; \ - ../../configure CXX="$(TARGET_CXX) --target=$(arch_name)" CC="$(TARGET_CC) --target=$(arch_name)" --host=$(host) --prefix=`pwd` --enable-shared=no --disable-graphics - -$(libtessconfig) : $(libtessautogen) - cd $(@D) && ./autogen.sh 2> /dev/null - -####################### -# LEPTONICA -####################### -$(install_liblept) : $(liblept) - mkdir -p $(LIB_FAT_DIR) - cp $(realpath $(addsuffix lib/$(@F), $(libleptfolder)) ) $@ - mkdir -p $(LEPT_INC_DIR) - cp -rvf $(firstword $(libleptfolder))include/leptonica/** $(LEPT_INC_DIR) - -$(liblept) : $(libleptmakefile) - cd $(abspath $(@D)/..) ; \ - $(MAKE) -sj8 && $(MAKE) install - -$(LEPTON_SRC)/$(PLATFORM_PREFIX)/%/Makefile : $(install_libtifffat) $(install_libpngfat) $(install_libjpegfat) $(libleptconfig) - export LIBS="-lz -lpng -ljpeg -ltiff" ; \ - export SDKROOT="$(sdk)" ; \ - export CFLAGS="-I$(INCLUDE_DIR) $(common_cflags) -fembed-bitcode" ; \ - export CPPFLAGS=$$CFLAGS ; \ - export CXXFLAGS="-I$(INCLUDE_DIR) $(common_cflags) -Wno-deprecated-register"; \ - export LDFLAGS="-L$$SDKROOT/usr/lib/ -L$(LIB_FAT_DIR)" ; \ - export PKG_CONFIG_PATH=$(PNG_SRC)/$(arch)/:$(JPEG_SRC)/$(arch)/:$(TIFF_SRC)/$(arch)/ ; \ - export CXX="$(TARGET_CXX) --target=$(arch_name)" ; \ - export CXX_FOR_BUILD="$(TARGET_CXX_FOR_BUILD) --target=$(arch_name)" ; \ - export CC="$(TARGET_CC) --target=$(arch_name)" ; \ - mkdir -p $(@D) ; \ - cd $(@D) ; \ - ../../configure CXX="$(TARGET_CXX) --target=$(arch_name)" CC="$(TARGET_CC) --target=$(arch_name)" --host=$(host) --prefix=`pwd` --enable-shared=no --disable-programs --with-zlib --with-libpng --with-jpeg --with-libtiff --without-giflib --without-libwebp --without-libwebpmux - -$(libleptconfig) : $(libleptautogen) - cd $(@D) && ./autogen.sh 2> /dev/null - -####################### -# Download dependencies -####################### -$(libtiffconfig) : - curl http://download.osgeo.org/libtiff/$(TIFF_NAME).tar.gz | tar -xpf- - -$(libjpegconfig) : - curl http://www.ijg.org/files/$(JPEG_SRC_NAME).tar.gz | tar -xpf- - -$(libpngconfig) : - curl -L https://downloads.sourceforge.net/project/libpng/libpng16/$(PNG_VERSION)/$(PNG_NAME).tar.gz | tar -xpf- - -$(libtessautogen) : - curl -LO https://github.com/tesseract-ocr/tesseract/archive/$(TESSERACT_VERSION).zip && unzip -a $(TESSERACT_VERSION).zip - -$(libleptautogen) : - curl http://leptonica.org/source/$(LEPTON_NAME).tar.gz | tar -xpf- ; \ - - -####################### -# Clean -####################### -.PHONY : clean -clean : cleanpng cleantiff cleanjpeg cleanlept cleantess - -.PHONY : distclean -distclean : distcleanimages distcleanlept distcleantess - -.PHONY : mostlyclean -mostlyclean : mostlycleanpng mostlycleantiff mostlycleanjpeg mostlycleanlept mostlycleantess - -.PHONY : cleanpng -cleanpng : - for folder in $(realpath $(libpngfolder) ); do \ - cd $$folder; \ - $(MAKE) clean; \ - done - -.PHONY : cleanjpeg -cleanjpeg : - for folder in $(realpath $(libjpegfolder) ); do \ - cd $$folder; \ - $(MAKE) clean; \ - done - -.PHONY : cleantiff -cleantiff : - for folder in $(realpath $(libtifffolder) ); do \ - cd $$folder; \ - $(MAKE) clean; \ - done - -.PHONY : cleanlept -cleanlept : - for folder in $(realpath $(libleptfolder) ); do \ - cd $$folder; \ - $(MAKE) clean; \ - done ; - -.PHONY : cleantess -cleantess : - for folder in $(realpath $(libtessfolder) ); do \ - cd $$folder; \ - $(MAKE) clean; \ - done ; - -.PHONY : mostlycleanlept -mostlycleanlept : - for folder in $(realpath $(libleptfolder) ); do \ - cd $$folder; \ - $(MAKE) mostlyclean; \ - done ; - -.PHONY : mostlycleantess -mostlycleantess : - for folder in $(realpath $(libtessfolder) ); do \ - cd $$folder; \ - $(MAKE) mostlyclean; \ - done ; - -.PHONY : mostlycleanpng -mostlycleanpng : - for folder in $(realpath $(libpngfolder) ); do \ - cd $$folder; \ - $(MAKE) mostlyclean; \ - done - -.PHONY : mostlycleantiff -mostlycleantiff : - for folder in $(realpath $(libtifffolder) ); do \ - cd $$folder; \ - $(MAKE) mostlyclean; \ - done - -.PHONY : mostlycleanjpeg -mostlycleanjpeg : - for folder in $(realpath $(libjpegfolder) ); do \ - cd $$folder; \ - $(MAKE) mostlyclean; \ - done - -.PHONY : distcleanimages -distcleanimages : - -rm -rf $(shell pwd)/*/include - -rm -rf $(PNG_SRC) - -rm -rf $(JPEG_SRC) - -rm -rf $(TIFF_SRC) - -PHONY : distcleanlept -distcleanlept : - -rm -rf $(LEPT_INC_DIR)/leptonica - -rm -rf $(install_liblept) - -rm -rf $(LEPTON_SRC) - -.PHONY : distcleantess -distcleantess : - -rm -rf $(TESS_INC_DIR)/tesseract - -rm -rf $(install_libtess) - -rm -rf $(TESSERACT_SRC) - -.PHONY : FORCE -FORCE : diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..9095ff0 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,646 @@ +version: '3' + +vars: + SRC_DIR: + sh: pwd + + PNG_VERSION: 1.6.36 + PNG_NAME: libpng-{{.PNG_VERSION}} + PNG_SRC: "{{.SRC_DIR}}/{{.PNG_NAME}}" + PNG_ARCHIVE: libpng.a + PNG_CONFIG: "{{.PNG_SRC}}/configure" + + JPEG_SRC_NAME: jpegsrc.v9c + JPEG_DIR_NAME: jpeg-9c # folder name after the JPEG_SRC_NAME archive has been unpacked + JPEG_SRC: "{{.SRC_DIR}}/{{.JPEG_DIR_NAME}}" + JPEG_ARCHIVE: libjpeg.a + JPEG_CONFIG: "{{.JPEG_SRC}}/configure" + + TIFF_NAME: tiff-4.0.10 + TIFF_SRC: "{{.SRC_DIR}}/{{.TIFF_NAME}}" + TIFF_ARCHIVE: libtiff.a + TIFF_CONFIG: "{{.TIFF_SRC}}/configure" + + TESSERACT_VERSION: 4.1.0 + TESSERACT_NAME: tesseract-{{.TESSERACT_VERSION}} + TESSERACT_SRC: "{{.SRC_DIR}}/{{.TESSERACT_NAME}}" + TESSERACT_ARCHIVE: libtesseract.a + TESSERACT_AUTOGEN: "{{.TESSERACT_SRC}}/autogen.sh" + TESSERACT_CONFIG: "{{.TESSERACT_SRC}}/configure" + + LEPTONICA_VERSION: 1.79.0 + LEPTONICA_NAME: leptonica-{{.LEPTONICA_VERSION}} + LEPTONICA_SRC: "{{.SRC_DIR}}/{{.LEPTONICA_NAME}}" + LEPTONICA_ARCHIVE: liblept.a + LEPTONICA_AUTOGEN: "{{.LEPTONICA_SRC}}/autogen.sh" + LEPTONICA_CONFIG: "{{.LEPTONICA_SRC}}/configure" + + LIBTESSERACT_PROJECT: libtesseract.xcodeproj + + IOS_VERSION_MIN: iphoneos-version-min=11.0 + IOS_ARCH_NAME: arm-apple-darwin64 + IOS_HOST: "{{.IOS_ARCH_NAME}}" + IOS_PLATFORM_PREFIX: ios + IOS_ARCH: arm64 + IOS_SDK: + sh: xcrun --sdk iphoneos --show-sdk-path + + IOS_FRAMEWORK: "{{.SRC_DIR}}/build/Release-iphoneos/libtesseract.framework" + + IOS_SIMULATOR_VERSION_MIN: ios-simulator-version-min=11.0 + IOS_SIMULATOR_PLATFORM_PREFIX: simulator + IOS_SIMULATOR_SDK: + sh: xcrun --sdk iphonesimulator --show-sdk-path + + IOS_SIMULATOR_ARM_ARCH_NAME: arm-apple-darwin64 + IOS_SIMULATOR_ARM_HOST: "{{.IOS_SIMULATOR_ARM_ARCH_NAME}}" + IOS_SIMULATOR_ARM_ARCH: arm64 + + IOS_SIMULATOR_X86_ARCH_NAME: x86_64-apple-darwin + IOS_SIMULATOR_X86_HOST: "{{.IOS_SIMULATOR_X86_ARCH_NAME}}" + IOS_SIMULATOR_X86_ARCH: x86_64 + + IOS_SIMULATOR_FRAMEWORK: "{{.SRC_DIR}}/build/Release-iphonesimulator/libtesseract.framework" + + MACOS_VERSION_MIN: macosx-version-min=10.13 + MACOS_PLATFORM_PREFIX: macos + MACOS_SDK: + sh: xcrun --sdk macosx --show-sdk-path + + MACOS_ARM_ARCH_NAME: arm-apple-darwin64 + MACOS_ARM_ARCH: arm64 + MACOS_ARM_HOST: "{{.MACOS_ARM_ARCH_NAME}}" + + MACOS_X86_ARCH_NAME: x86_64-apple-darwin + MACOS_X86_ARCH: x86_64 + MACOS_X86_HOST: "{{.MACOS_X86_ARCH_NAME}}" + + MACOS_FRAMEWORK: "{{.SRC_DIR}}/build/Release/libtesseract.framework" + + CATALYST_VERSION_MIN: iphoneos-version-min=13.0 + CATALYST_PLATFORM_PREFIX: catalyst + CATALYST_SDK: + sh: xcrun --sdk macosx --show-sdk-path + + CATALYST_ARM_ARCH_NAME: arm64-apple-ios-macabi + CATALYST_ARM_ARCH: arm64 + CATALYST_ARM_HOST: arm-apple-darwin64 + + CATALYST_X86_ARCH_NAME: x86_64-apple-ios-macabi + CATALYST_X86_ARCH: x86_64 + CATALYST_X86_HOST: x86_64-apple-darwin + + CATALYST_FRAMEWORK: "{{.SRC_DIR}}/build/Release-maccatalyst/libtesseract.framework" + +env: + TARGET_CXX: /usr/bin/clang++ + TARGET_CXX_FOR_BUILD: /usr/bin/clang++ + TARGET_CC: /usr/bin/clang + +tasks: + clean-build-folder: + cmds: + - rm -rf {{.SRC_DIR}}/build + + clean-artifacts: + cmds: + - rm -rf {{.SRC_DIR}}/include/*.h *.a + + clean-sources: + cmds: + - task: clean-artifacts + - rm -rf {{.PNG_SRC}} {{.TIFF_SRC}} {{.JPEG_SRC}} {{.LEPTONICA_SRC}} {{.TESSERACT_SRC}} + + build-tesseract-xcframework-zip: + cmds: + - task: build-tesseract-xcframework + - zip -r {{.SRC_DIR}}/libtesseract-{{.RELEASE_VERSION}}.xcframework.zip {{.SRC_DIR}}/build/libtesseract.xcframework + + build-tesseract-xcframework: + cmds: + - task: clean-build-folder + - task: clean-sources + - task: build-tesseract-catalyst-framework + - task: clean-sources + - task: build-tesseract-macos-framework + - task: clean-sources + - task: build-tesseract-ios-simulator-framework + - task: clean-sources + - task: build-tesseract-ios-framework + - task: clean-sources + - | + xcodebuild -create-xcframework \ + -framework {{.IOS_FRAMEWORK}} \ + -framework {{.IOS_SIMULATOR_FRAMEWORK}} \ + -framework {{.MACOS_FRAMEWORK}} \ + -framework {{.CATALYST_FRAMEWORK}} \ + -output {{.SRC_DIR}}/build/libtesseract.xcframework + status: + - test -f {{.SRC_DIR}}/build/libtesseract.xcframework + + build-tesseract-catalyst-framework: + cmds: + - task: build-tesseract-catalyst + - cp {{.SRC_DIR}}/{{.CATALYST_PLATFORM_PREFIX}}/combined.a . + - cp -r {{.SRC_DIR}}/{{.CATALYST_PLATFORM_PREFIX}}/include/*h {{.SRC_DIR}}/include + - sed -ie 's/.*fract1.*//' {{.SRC_DIR}}/include/allheaders.h + - | + xcodebuild -project {{.LIBTESSERACT_PROJECT}} \ + -scheme 'libtesseract iOS' \ + -sdk macosx \ + -destination 'platform=macOS,variant=Mac Catalyst' \ + -configuration 'Release' \ + SYMROOT=`pwd`/build \ + -derivedDataPath {{.SRC_DIR}}/DerivedData \ + BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ + build + status: + - test -f {{.CATALYST_FRAMEWORK}} + + build-tesseract-catalyst: + cmds: + - task: install-libtesseract + vars: + SDK: "{{.CATALYST_SDK}}" + PLATFORM_VERSION_MIN: "{{.CATALYST_VERSION_MIN}}" + HOST: "{{.CATALYST_ARM_HOST}}" + ARCH_NAME: "{{.CATALYST_ARM_ARCH_NAME}}" + ARCH: "{{.CATALYST_ARM_ARCH}}" + PLATFORM_PREFIX: "{{.CATALYST_PLATFORM_PREFIX}}" + - task: install-libtesseract + vars: + SDK: "{{.CATALYST_SDK}}" + PLATFORM_VERSION_MIN: "{{.CATALYST_VERSION_MIN}}" + HOST: "{{.CATALYST_X86_HOST}}" + ARCH_NAME: "{{.CATALYST_X86_ARCH_NAME}}" + ARCH: "{{.CATALYST_X86_ARCH}}" + PLATFORM_PREFIX: "{{.CATALYST_PLATFORM_PREFIX}}" + - | + xcrun lipo \ + {{.SRC_DIR}}/{{.CATALYST_PLATFORM_PREFIX}}/{{.CATALYST_ARM_ARCH_NAME}}/combined.a \ + {{.SRC_DIR}}/{{.CATALYST_PLATFORM_PREFIX}}/{{.CATALYST_X86_ARCH_NAME}}/combined.a \ + -create -output {{.SRC_DIR}}/{{.CATALYST_PLATFORM_PREFIX}}/combined.a + status: + - test -f {{.SRC_DIR}}/{{.CATALYST_PLATFORM_PREFIX}}/combined.a + + build-tesseract-macos-framework: + cmds: + - task: build-tesseract-macos + - cp {{.SRC_DIR}}/{{.MACOS_PLATFORM_PREFIX}}/combined.a . + - cp -r {{.SRC_DIR}}/{{.MACOS_PLATFORM_PREFIX}}/include/*h {{.SRC_DIR}}/include + - sed -ie 's/.*fract1.*//' {{.SRC_DIR}}/include/allheaders.h + - | + xcodebuild -project {{.LIBTESSERACT_PROJECT}} \ + -scheme 'libtesseract macOS' \ + -sdk macosx \ + -destination 'generic/platform=macOS' \ + -configuration 'Release' \ + SYMROOT=`pwd`/build \ + -derivedDataPath {{.SRC_DIR}}/DerivedData \ + BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ + build + status: + - test -f {{.MACOS_FRAMEWORK}} + + build-tesseract-macos: + cmds: + - task: install-libtesseract + vars: + SDK: "{{.MACOS_SDK}}" + PLATFORM_VERSION_MIN: "{{.MACOS_VERSION_MIN}}" + HOST: "{{.MACOS_ARM_HOST}}" + ARCH_NAME: "{{.MACOS_ARM_ARCH_NAME}}" + ARCH: "{{.MACOS_ARM_ARCH}}" + PLATFORM_PREFIX: "{{.MACOS_PLATFORM_PREFIX}}" + - task: install-libtesseract + vars: + SDK: "{{.MACOS_SDK}}" + PLATFORM_VERSION_MIN: "{{.MACOS_VERSION_MIN}}" + HOST: "{{.MACOS_X86_HOST}}" + ARCH_NAME: "{{.MACOS_X86_ARCH_NAME}}" + ARCH: "{{.MACOS_X86_ARCH}}" + PLATFORM_PREFIX: "{{.MACOS_PLATFORM_PREFIX}}" + - | + xcrun lipo \ + {{.SRC_DIR}}/{{.MACOS_PLATFORM_PREFIX}}/{{.MACOS_ARM_ARCH_NAME}}/combined.a \ + {{.SRC_DIR}}/{{.MACOS_PLATFORM_PREFIX}}/{{.MACOS_X86_ARCH_NAME}}/combined.a \ + -create -output {{.SRC_DIR}}/{{.MACOS_PLATFORM_PREFIX}}/combined.a + status: + - test -f {{.SRC_DIR}}/{{.MACOS_PLATFORM_PREFIX}}/combined.a + + build-tesseract-ios-simulator-framework: + cmds: + - task: build-tesseract-ios-simulator + - cp {{.SRC_DIR}}/{{.IOS_SIMULATOR_PLATFORM_PREFIX}}/combined.a . + - cp -r {{.SRC_DIR}}/{{.IOS_SIMULATOR_PLATFORM_PREFIX}}/include/*h {{.SRC_DIR}}/include + - | + xcodebuild -project {{.LIBTESSERACT_PROJECT}} \ + -scheme 'libtesseract iOS' \ + -sdk iphonesimulator \ + -destination 'generic/platform=iOS Simulator' \ + -configuration 'Release' \ + SYMROOT=`pwd`/build \ + -derivedDataPath {{.SRC_DIR}}/DerivedData \ + BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ + build + status: + - test -f {{.IOS_SIMULATOR_FRAMEWORK}} + + build-tesseract-ios-simulator: + cmds: + - task: install-libtesseract + vars: + SDK: "{{.IOS_SIMULATOR_SDK}}" + PLATFORM_VERSION_MIN: "{{.IOS_SIMULATOR_VERSION_MIN}}" + HOST: "{{.IOS_SIMULATOR_ARM_HOST}}" + ARCH_NAME: "{{.IOS_SIMULATOR_ARM_ARCH_NAME}}" + ARCH: "{{.IOS_SIMULATOR_ARM_ARCH}}" + PLATFORM_PREFIX: "{{.IOS_SIMULATOR_PLATFORM_PREFIX}}" + - task: install-libtesseract + vars: + SDK: "{{.IOS_SIMULATOR_SDK}}" + PLATFORM_VERSION_MIN: "{{.IOS_SIMULATOR_VERSION_MIN}}" + HOST: "{{.IOS_SIMULATOR_X86_HOST}}" + ARCH_NAME: "{{.IOS_SIMULATOR_X86_ARCH_NAME}}" + ARCH: "{{.IOS_SIMULATOR_X86_ARCH}}" + PLATFORM_PREFIX: "{{.IOS_SIMULATOR_PLATFORM_PREFIX}}" + - | + xcrun lipo \ + {{.SRC_DIR}}/{{.IOS_SIMULATOR_PLATFORM_PREFIX}}/{{.IOS_SIMULATOR_ARM_ARCH_NAME}}/combined.a \ + {{.SRC_DIR}}/{{.IOS_SIMULATOR_PLATFORM_PREFIX}}/{{.IOS_SIMULATOR_X86_ARCH_NAME}}/combined.a \ + -create -output {{.SRC_DIR}}/{{.IOS_SIMULATOR_PLATFORM_PREFIX}}/combined.a + status: + - test -f {{.SRC_DIR}}/{{.IOS_SIMULATOR_PLATFORM_PREFIX}}/combined.a + + build-tesseract-ios-framework: + cmds: + - task: build-tesseract-ios + - cp {{.SRC_DIR}}/{{.IOS_PLATFORM_PREFIX}}/combined.a . + - cp -r {{.SRC_DIR}}/{{.IOS_PLATFORM_PREFIX}}/include/*h {{.SRC_DIR}}/include + - | + xcodebuild -project {{.LIBTESSERACT_PROJECT}} \ + -scheme 'libtesseract iOS' \ + -sdk iphoneos \ + -destination 'generic/platform=iOS' \ + -configuration 'Release' \ + SYMROOT=`pwd`/build \ + -derivedDataPath {{.SRC_DIR}}/DerivedData \ + BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ + build + status: + - test -f {{.IOS_FRAMEWORK}} + + build-tesseract-ios: + cmds: + - task: install-libtesseract + vars: + SDK: "{{.IOS_SDK}}" + PLATFORM_VERSION_MIN: "{{.IOS_VERSION_MIN}}" + HOST: "{{.IOS_HOST}}" + ARCH_NAME: "{{.IOS_ARCH_NAME}}" + ARCH: "{{.IOS_ARCH}}" + PLATFORM_PREFIX: "{{.IOS_PLATFORM_PREFIX}}" + - cp {{.SRC_DIR}}/{{.IOS_PLATFORM_PREFIX}}/{{.IOS_ARCH_NAME}}/combined.a {{.SRC_DIR}}/{{.IOS_PLATFORM_PREFIX}} + status: + - test -f {{.SRC_DIR}}/{{.IOS_PLATFORM_PREFIX}}/combined.a + + install-libtesseract: + cmds: + - task: compile-libtesseract + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + - cp {{.TESSERACT_SRC}}/{{.ARCH_NAME}}/lib/{{.TESSERACT_ARCHIVE}} {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - cp -rvf {{.TESSERACT_SRC}}/{{.ARCH_NAME}}/include/tesseract/*.h {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + - | + libtool -static -o {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/combined.a \ + {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.JPEG_ARCHIVE}} \ + {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.LEPTONICA_ARCHIVE}} \ + {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.PNG_ARCHIVE}} \ + {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.TIFF_ARCHIVE}} \ + {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.TESSERACT_ARCHIVE}} + status: + - test -f {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/combined.a + + compile-libtesseract: + cmds: + - task: configure-libtesseract + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + - | + cd {{.TESSERACT_SRC}}/{{.ARCH_NAME}} + make -sj8 + make install + status: + - test -f {{.TESSERACT_SRC}}/{{.ARCH_NAME}}/lib/{{.TESSERACT_ARCHIVE}} + + configure-libtesseract: + deps: + - task: autogen-libtesseract + - task: install-liblept + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + cmds: + - | + export LIBS="-lz -lpng -ljpeg -ltiff" + export SDKROOT="{{.SDK}}" + export CFLAGS="-I{{.TESSERACT_SRC}}/{{.ARCH_NAME}}/ -arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -fembed-bitcode" + export CPPFLAGS=$CFLAGS + export CXXFLAGS="-I{{.TESSERACT_SRC}}/{{.ARCH_NAME}}/ -arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -Wno-deprecated-register" + export LDFLAGS="-L$SDKROOT/usr/lib/ -L{{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} -L{{.LEPTONICA_SRC}}/{{.ARCH_NAME}}/src/.libs" + export LIBLEPT_HEADERSDIR={{.TESSERACT_SRC}}/{{.ARCH_NAME}}/ + export PKG_CONFIG_PATH={{.LEPTONICA_SRC}}/{{.ARCH_NAME}}/ + export CXX="{{.TARGET_CXX}} --target={{.ARCH_NAME}}" + export CXX_FOR_BUILD="{{.TARGET_CXX_FOR_BUILD}} --target={{.ARCH_NAME}}" + export CC="{{.TARGET_CC}} --target={{.ARCH_NAME}}" + mkdir -p {{.TESSERACT_SRC}}/{{.ARCH_NAME}} + cd {{.TESSERACT_SRC}}/{{.ARCH_NAME}} + ln -s {{.LEPTONICA_SRC}}/src/ leptonica + ../configure --host={{.HOST}} --prefix=`pwd` --enable-shared=no --disable-graphics + status: + - test -f {{.TESSERACT_SRC}}/{{.ARCH_NAME}}/Makefile + + autogen-libtesseract: + deps: [download-libtesseract] + cmds: + - | + cd {{.TESSERACT_SRC}} + ./autogen.sh 2> /dev/null + status: + - test -f {{.TESSERACT_CONFIG}} + + download-libtesseract: + cmds: + - curl -LO https://github.com/tesseract-ocr/tesseract/archive/{{.TESSERACT_VERSION}}.zip + - unzip -a {{.TESSERACT_VERSION}}.zip + status: + - test -d {{.TESSERACT_SRC}} + + install-liblept: + cmds: + - task: compile-liblept + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + - cp {{.LEPTONICA_SRC}}/{{.ARCH_NAME}}/lib/{{.LEPTONICA_ARCHIVE}} {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - cp -rvf {{.LEPTONICA_SRC}}/{{.ARCH_NAME}}/include/leptonica/*.h {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + status: + - test -f {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.LEPTONICA_ARCHIVE}} + + compile-liblept: + cmds: + - task: configure-liblept + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + - | + cd {{.LEPTONICA_SRC}}/{{.ARCH_NAME}} + make -sj8 + make install + status: + - test -f {{.LEPTONICA_SRC}}/{{.ARCH_NAME}}/lib/{{.LEPTONICA_ARCHIVE}} + + configure-liblept: + deps: # These are set up as deps so they can be executed concurrently + - task: install-libpng + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + - task: install-libjpeg + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + cmds: + - task: install-libtiff + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH: "{{.ARCH}}" + ARCH_NAME: "{{.ARCH_NAME}}" + HOST: "{{.HOST}}" + PLATFORM_PREFIX: "{{.PLATFORM_PREFIX}}" + - task: autogen-liblept + - | + export SDKROOT={{.SDK}} + export CFLAGS="-I{{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include -arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -fembed-bitcode" + export CPPFLAGS=$CFLAGS + export CXXFLAGS="-I{{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include -arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -Wno-deprecated-register" + export LDFLAGS="-L$SDKROOT/usr/lib -L{{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}" + export PKG_CONFIG_PATH={{.PNG_SRC}}/{{.ARCH_NAME}}/:{{.JPEG_SRC}}/{{.ARCH_NAME}}/:{{.TIFF_SRC}}/{{.ARCH_NAME}}/ + export CXX="{{.TARGET_CXX}} --target={{.ARCH_NAME}}" + export CXX_FOR_BUILD="{{.TARGET_CXX_FOR_BUILD}} --target={{.ARCH_NAME}}" + export CC="{{.TARGET_CC}} --target={{.ARCH_NAME}}" + mkdir -p {{.LEPTONICA_SRC}}/{{.ARCH_NAME}} + cd {{.LEPTONICA_SRC}}/{{.ARCH_NAME}} + ../configure --host={{.HOST}} --prefix=`pwd` --enable-shared=no --disable-programs --with-zlib --with-libpng --with-jpeg --with-libtiff --without-giflib --without-libwebp --without-libwebpmux --without-libopenjpeg + status: + - test -f {{.LEPTONICA_SRC}}/{{.ARCH_NAME}}/Makefile + + autogen-liblept: + deps: [download-liblept] + cmds: + - | + cd {{.LEPTONICA_SRC}} + ./autogen.sh 2> /dev/null + status: + - test -f {{.LEPTONICA_CONFIG}} + + download-liblept: + cmds: + - curl http://leptonica.org/source/{{.LEPTONICA_NAME}}.tar.gz | tar -xpf- + status: + - test -d {{.LEPTONICA_SRC}} + + install-libpng: + cmds: + - task: compile-libpng + vars: + ARCH_NAME: "{{.ARCH_NAME}}" + ARCH: "{{.ARCH}}" + SDK: "{{.SDK}}" + HOST: "{{.HOST}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + - cp {{.PNG_SRC}}/{{.ARCH_NAME}}/lib/{{.PNG_ARCHIVE}} {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - cp -rvf {{.PNG_SRC}}/{{.ARCH_NAME}}/include/libpng16/*.h {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + status: + - test -f {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.PNG_ARCHIVE}} + + compile-libpng: + cmds: + - task: configure-libpng + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH_NAME: "{{.ARCH_NAME}}" + ARCH: "{{.ARCH}}" + HOST: "{{.HOST}}" + - | + cd {{.PNG_SRC}}/{{.ARCH_NAME}} + make -sj8 + make install + status: + - test -f {{.PNG_SRC}}/{{.ARCH_NAME}}/lib/{{.PNG_ARCHIVE}} + + configure-libpng: + deps: [download-libpng] + cmds: + - | + export SDKROOT={{.SDK}} + export CFLAGS="-arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -fembed-bitcode" + export CPPFLAGS=$CFLAGS + export CXXFLAGS="$CFLAGS -Wno-deprecated-register" + export LDFLAGS="-L$SDKROOT/usr/lib" + mkdir -p {{.PNG_SRC}}/{{.ARCH_NAME}} + cd {{.PNG_SRC}}/{{.ARCH_NAME}} + ../configure CXX="{{.TARGET_CXX}} --target={{.ARCH_NAME}}" CC="{{.TARGET_CC}} --target={{.ARCH_NAME}}" --host={{.HOST}} --enable-shared=no --prefix=`pwd` + status: + - test -f {{.PNG_SRC}}/{{.ARCH_NAME}}/Makefile + + download-libpng: + cmds: + - curl -L https://downloads.sourceforge.net/project/libpng/libpng16/{{.PNG_VERSION}}/{{.PNG_NAME}}.tar.gz | tar -xpf- + status: + - test -d {{.PNG_SRC}} + + install-libjpeg: + cmds: + - task: compile-libjpeg + vars: + ARCH_NAME: "{{.ARCH_NAME}}" + ARCH: "{{.ARCH}}" + SDK: "{{.SDK}}" + HOST: "{{.HOST}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + - cp {{.JPEG_SRC}}/{{.ARCH_NAME}}/lib/{{.JPEG_ARCHIVE}} {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - cp -rvf {{.JPEG_SRC}}/{{.ARCH_NAME}}/include/*.h {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + status: + - test -f {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.JPEG_ARCHIVE}} + + compile-libjpeg: + cmds: + - task: configure-libjpeg + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH_NAME: "{{.ARCH_NAME}}" + ARCH: "{{.ARCH}}" + HOST: "{{.HOST}}" + - | + cd {{.JPEG_SRC}}/{{.ARCH_NAME}} + make -sj8 + make install + status: + - test -f {{.JPEG_SRC}}/{{.ARCH_NAME}}/lib/{{.JPEG_ARCHIVE}} + + configure-libjpeg: + deps: [download-libjpeg] + cmds: + - | + export SDKROOT={{.SDK}} + export CFLAGS="-arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -fembed-bitcode" + export CPPFLAGS=$CFLAGS + export CXXFLAGS="$CFLAGS -Wno-deprecated-register" + export LDFLAGS="-L$SDKROOT/usr/lib" + mkdir -p {{.JPEG_SRC}}/{{.ARCH_NAME}} + cd {{.JPEG_SRC}}/{{.ARCH_NAME}} + ../configure CXX="{{.TARGET_CXX}} --target={{.ARCH_NAME}}" CC="{{.TARGET_CC}} --target={{.ARCH_NAME}}" --host={{.HOST}} --enable-shared=no --prefix=`pwd` + status: + - test -f {{.JPEG_SRC}}/{{.ARCH_NAME}}/Makefile + + download-libjpeg: + cmds: + - curl http://www.ijg.org/files/{{.JPEG_SRC_NAME}}.tar.gz | tar -xpf- + status: + - test -d {{.JPEG_SRC}} + + install-libtiff: + cmds: + - task: compile-libtiff + vars: + ARCH_NAME: "{{.ARCH_NAME}}" + ARCH: "{{.ARCH}}" + SDK: "{{.SDK}}" + HOST: "{{.HOST}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - mkdir -p {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + - cp {{.TIFF_SRC}}/{{.ARCH_NAME}}/lib/{{.TIFF_ARCHIVE}} {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}} + - cp -rvf {{.TIFF_SRC}}/{{.ARCH_NAME}}/include/*.h {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/include + status: + - test -f {{.SRC_DIR}}/{{.PLATFORM_PREFIX}}/{{.ARCH_NAME}}/{{.TIFF_ARCHIVE}} + + compile-libtiff: + cmds: + - task: configure-libtiff + vars: + SDK: "{{.SDK}}" + PLATFORM_VERSION_MIN: "{{.PLATFORM_VERSION_MIN}}" + ARCH_NAME: "{{.ARCH_NAME}}" + ARCH: "{{.ARCH}}" + HOST: "{{.HOST}}" + - | + cd {{.TIFF_SRC}}/{{.ARCH_NAME}} + make -sj8 + make install + status: + - test -f {{.TIFF_SRC}}/{{.ARCH_NAME}}/lib/{{.TIFF_ARCHIVE}} + + configure-libtiff: + deps: + - task: download-libtiff + cmds: + - | + export SDKROOT={{.SDK}} + export CFLAGS="-arch {{.ARCH}} -pipe -no-cpp-precomp -isysroot $SDKROOT -m{{.PLATFORM_VERSION_MIN}} -O2 -fembed-bitcode" + export CPPFLAGS=$CFLAGS + export CXXFLAGS="$CFLAGS -Wno-deprecated-register" + export LDFLAGS="-L$SDKROOT/usr/lib" + mkdir -p {{.TIFF_SRC}}/{{.ARCH_NAME}} + cd {{.TIFF_SRC}}/{{.ARCH_NAME}} + ../configure CXX="{{.TARGET_CXX}} --target={{.ARCH_NAME}}" CC="{{.TARGET_CC}} --target={{.ARCH_NAME}}" --host={{.HOST}} --enable-fast-install --enable-shared=no --prefix=`pwd` --without-x --with-jpeg-include-dir={{.JPEG_SRC}}/{{.ARCH_NAME}}/include --with-jpeg-lib-dir={{.JPEG_SRC}}/{{.ARCH_NAME}}/lib + status: + - test -f {{.TIFF_SRC}}/{{.ARCH_NAME}}/Makefile + + download-libtiff: + cmds: + - curl http://download.osgeo.org/libtiff/{{.TIFF_NAME}}.tar.gz | tar -xpf- + status: + - test -d {{.TIFF_SRC}} \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100644 index ec2fa1c..0000000 --- a/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -build() { - make platform=$1 - cp -r $1/include/*.h include - cp -r $1/include/*.a . - - libtool -static -o combined.a libjpeg.a liblept.a libpng.a libtiff.a libtesseract.a -} diff --git a/build_all.sh b/build_all.sh deleted file mode 100644 index 72ca4d7..0000000 --- a/build_all.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -set -e -source build.sh - -make distclean -rm -rf include/*.h *.a -build ios - -rm -rf build/ - -xcodebuild -project libtesseract.xcodeproj \ - -scheme 'libtesseract iOS' \ - -sdk iphoneos \ - -destination 'generic/platform=iOS' \ - -configuration 'Release' \ - SYMROOT=$(pwd)/build \ - -derivedDataPath ./DerivedData \ - BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ - build - -rm include/*.h *.a - -build simulator - -xcodebuild -project libtesseract.xcodeproj \ - -scheme 'libtesseract iOS' \ - -sdk iphonesimulator \ - -destination 'generic/platform=iOS Simulator' \ - -configuration 'Release' \ - SYMROOT=$(pwd)/build \ - -derivedDataPath ./DerivedData \ - BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ - build - -rm include/*.h combined.a - -make distclean -build catalyst - -# There is an issue with the macro expansion for fract1 on macOS that causes the xcframework to not be useable -sed -ie 's/.*fract1.*//' include/allheaders.h - -xcodebuild -project libtesseract.xcodeproj \ - -scheme 'libtesseract iOS' \ - -sdk macosx \ - -destination 'platform=macOS,variant=Mac Catalyst' \ - -configuration 'Release' \ - SYMROOT=$(pwd)/build \ - -derivedDataPath ./DerivedData \ - BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ - build - -rm include/*.h combined.a - -make distclean -build macos - -# There is an issue with the macro expansion for fract1 on macOS that causes the xcframework to not be useable -sed -ie 's/.*fract1.*//' include/allheaders.h - -xcodebuild -project libtesseract.xcodeproj \ - -scheme 'libtesseract macOS' \ - -sdk macosx \ - -destination 'platform=OS X,arch=x86_64' \ - -configuration 'Release' \ - SYMROOT=$(pwd)/build \ - -derivedDataPath ./DerivedData \ - BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ - build - -xcodebuild -create-xcframework \ - -framework 'build/Release-iphoneos/libtesseract.framework' \ - -framework 'build/Release-iphonesimulator/libtesseract.framework' \ - -framework 'build/Release-maccatalyst/libtesseract.framework' \ - -framework 'build/Release/libtesseract.framework' \ - -output 'build/libtesseract.xcframework' diff --git a/update_package_swift.py b/update_package_swift.py new file mode 100644 index 0000000..62d1ebd --- /dev/null +++ b/update_package_swift.py @@ -0,0 +1,39 @@ +import subprocess +import argparse + +def write_package_swift(version): + libtesseract_zip = f"libtesseract-{version}.xcframework.zip" + download_url = f"https://github.com/SwiftyTesseract/libtesseract/releases/download/{version}/{libtesseract_zip}" + checksum_result = subprocess.run(["swift", "package", "compute-checksum", libtesseract_zip], stdout=subprocess.PIPE) + checksum = checksum_result.stdout.decode("utf-8").strip("\n") + + with open("Package.swift", "w") as package_swift: + package_swift.write(f"""// swift-tools-version:5.3 + +import PackageDescription + +let package = Package( + name: "libtesseract", + products: [ + .library( + name: "libtesseract", + targets: ["libtesseract"] + ), + ], + dependencies: [], + targets: [ + .binaryTarget( + name: "libtesseract", + url: "{download_url}", + checksum: "{checksum}" + ) + ] +) + +""") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Update libtesseract Package.swift") + parser.add_argument("--version", required=True, help="The version to update Package.swift for") + args = parser.parse_args() + write_package_swift(args.version) \ No newline at end of file