diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..81095055 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,184 @@ +name: build + +on: + push: + branches: [ main ] + paths-ignore: + - '*.adoc' + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-18.04, ubuntu-latest, windows-latest, macos-latest ] + ruby-version: [ '2.7' ] + include: + - os: windows-latest + ruby-version: '3.1' + steps: + - uses: actions/checkout@v3 + + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ${{ matrix.ruby-version }} + +# https://github.com/microsoft/vcpkg/issues/15931 +# no good solution :( + - name: Workaround for vcpkg + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install gperf + + - run: bundle exec rake + + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-18.04 + platform: any + ruby-version: '2.7' + - os: ubuntu-18.04 + platform: x86_64-linux + ruby-version: '2.7' + - os: windows-latest + platform: x64-mingw32 + ruby-version: '2.7' + - os: windows-latest + platform: x64-mingw-ucrt + ruby-version: '3.1' + - os: macos-latest + platform: x86_64-darwin + ruby-version: '2.7' + steps: + - uses: actions/checkout@v3 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - name: Workaround for vcpkg + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install gperf + + - run: bundle exec rake gem:native:${{ matrix.platform }} + + - uses: actions/upload-artifact@v2 + with: + name: pkg + path: pkg/*.gem + + - name: Install gem + run: gem install -b pkg/emf2svg-*.gem + + - name: Test conversion + run: | + ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')" + + test-build: + needs: build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + platform: any + ruby-version: '2.7' + - os: windows-latest + platform: any + ruby-version: '2.7' + - os: macos-latest + platform: any + ruby-version: '2.7' + - os: ubuntu-18.04 + platform: x86_64-linux + ruby-version: '2.7' + - os: ubuntu-latest + platform: x86_64-linux + ruby-version: '2.7' + - os: windows-latest + platform: x64-mingw32 + ruby-version: '2.7' + - os: windows-latest + platform: x64-mingw-ucrt + ruby-version: '3.1' + - os: macos-latest + platform: x86_64-darwin + ruby-version: '2.7' + + steps: + - uses: actions/checkout@v2 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + + - uses: actions/download-artifact@v2 + with: + name: pkg + path: pkg + + - name: Workaround for vcpkg + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install gperf + + - name: Install native gem + if: matrix.platform == 'any' + run: gem install -b pkg/emf2svg-$(ruby -I lib -r emf2svg/version -e "puts Emf2svg::VERSION").gem + + - name: Install binary gem + if: matrix.platform != 'any' + run: gem install -b pkg/emf2svg-*-${{ matrix.platform }}.gem + + - name: Test conversion + run: | + ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')" + + cross: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + platform: aarch64-linux + ruby-version: '2.7' + - os: macos-latest + platform: arm64-darwin + ruby-version: '2.7' + steps: + - uses: actions/checkout@v3 + + - name: Install packages + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu gperf + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - run: bundle exec rake gem:native:${{ matrix.platform }} + + - uses: actions/upload-artifact@v2 + with: + name: pkg + path: pkg/*.gem + + - name: Install gem + run: gem install -b pkg/emf2svg-*.gem diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index d798b223..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,167 +0,0 @@ -name: main - -on: - push: - branches: [ main ] - pull_request: - workflow_dispatch: - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - max-parallel: 4 - fail-fast: false - matrix: - os: [ ubuntu-18.04, ubuntu-latest, windows-latest, macos-latest ] - ruby-version: [ '2.7' ] - include: - - os: windows-latest - ruby-version: '3.1' - steps: - - uses: actions/checkout@v2 - - - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - ruby-version: ${{ matrix.ruby-version }} - - - run: bundle exec rake - - build: - runs-on: ${{ matrix.os }} - strategy: - max-parallel: 4 - fail-fast: false - matrix: - include: - - os: ubuntu-18.04 - platform: any - ruby-version: '2.7' - - os: ubuntu-18.04 - platform: x86_64-linux - ruby-version: '2.7' - - os: windows-latest - platform: x64-mingw32 - ruby-version: '2.7' - - os: windows-latest - platform: x64-mingw-ucrt - ruby-version: '3.1' - - os: macos-latest - platform: x86_64-darwin - ruby-version: '2.7' - steps: - - uses: actions/checkout@v2 - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - - run: bundle exec rake gem:native:${{ matrix.platform }} - - - uses: actions/upload-artifact@v2 - with: - name: pkg - path: pkg/*.gem - - - name: Install gem - run: gem install -b pkg/emf2svg-*.gem - - - name: Test conversion - run: | - ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')" - - test-build: - needs: build - runs-on: ${{ matrix.os }} - strategy: - max-parallel: 4 - fail-fast: false - matrix: - include: - - os: ubuntu-latest - platform: any - ruby-version: '2.7' - - os: windows-latest - platform: any - ruby-version: '2.7' - - os: macos-latest - platform: any - ruby-version: '2.7' - - os: ubuntu-18.04 - platform: x86_64-linux - ruby-version: '2.7' - - os: ubuntu-latest - platform: x86_64-linux - ruby-version: '2.7' - - os: windows-latest - platform: x64-mingw32 - ruby-version: '2.7' - - os: windows-latest - platform: x64-mingw-ucrt - ruby-version: '3.1' - - os: macos-latest - platform: x86_64-darwin - ruby-version: '2.7' - - steps: - - uses: actions/checkout@v2 - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - - - uses: actions/download-artifact@v2 - with: - name: pkg - path: pkg - - - name: Install native gem - if: matrix.platform == 'any' - run: gem install -b pkg/emf2svg-$(ruby -I lib -r emf2svg/version -e "puts Emf2svg::VERSION").gem - - - name: Install binary gem - if: matrix.platform != 'any' - run: gem install -b pkg/emf2svg-*-${{ matrix.platform }}.gem - - - name: Test conversion - run: | - ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')" - - cross: - runs-on: ${{ matrix.os }} - strategy: - max-parallel: 4 - fail-fast: false - matrix: - include: - - os: ubuntu-latest - platform: aarch64-linux - ruby-version: '2.7' - - os: macos-latest - platform: arm64-darwin - ruby-version: '2.7' - steps: - - uses: actions/checkout@v2 - - - name: Install packages - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu gperf - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - - run: bundle exec rake gem:native:${{ matrix.platform }} - - - uses: actions/upload-artifact@v2 - with: - name: pkg - path: pkg/*.gem - - - name: Install gem - run: gem install -b pkg/emf2svg-*.gem diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d98663f..b77f563a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,6 @@ jobs: build: runs-on: ${{ matrix.os }} strategy: - max-parallel: 3 fail-fast: false matrix: include: @@ -29,31 +28,38 @@ jobs: platform: x86_64-darwin ruby-version: '2.7' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true - - run: bundle exec rake gem:native:${{ matrix.platform }} +# https://github.com/microsoft/vcpkg/issues/15931 +# no good solution :( + - name: Workaround for vcpkg + if: startsWith(matrix.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install gperf - - uses: actions/upload-artifact@v2 - with: - name: pkg - path: pkg/*.gem + - run: bundle exec rake gem:native:${{ matrix.platform }} - - name: Install gem - run: gem install -b pkg/emf2svg-*.gem + - uses: actions/upload-artifact@v3 + with: + name: pkg + path: pkg/*.gem - - name: Test conversion - run: | - ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')" + - name: Install gem + run: gem install -b pkg/emf2svg-*.gem + + - name: Test conversion + run: | + ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')" cross: runs-on: ${{ matrix.os }} strategy: - max-parallel: 3 fail-fast: false matrix: include: @@ -64,56 +70,55 @@ jobs: platform: arm64-darwin ruby-version: '2.7' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + + - name: Install packages + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu gperf - - name: Install packages - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu gperf - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true - - run: bundle exec rake gem:native:${{ matrix.platform }} + - run: bundle exec rake gem:native:${{ matrix.platform }} - - uses: actions/upload-artifact@v2 - with: - name: pkg - path: pkg/*.gem + - uses: actions/upload-artifact@v2 + with: + name: pkg + path: pkg/*.gem - - name: Install gem - run: gem install -b pkg/emf2svg-*.gem + - name: Install gem + run: gem install -b pkg/emf2svg-*.gem publish: needs: [ build, cross ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.7' - bundler-cache: true - - - uses: actions/download-artifact@v2 - with: - name: pkg - path: pkg - - - name: Publish to rubygems.org - env: - RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}} - run: | - mkdir -p ~/.gem - touch ~/.gem/credentials - cat > ~/.gem/credentials << EOF - --- - :rubygems_api_key: ${RUBYGEMS_API_KEY} - EOF - chmod 0600 ~/.gem/credentials - gem signin - ls -l pkg/ - for gem in pkg/*.gem; do gem push -V $gem; done + - uses: actions/checkout@v2 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + + - uses: actions/download-artifact@v2 + with: + name: pkg + path: pkg + + - name: Publish to rubygems.org + env: + RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}} + run: | + mkdir -p ~/.gem + touch ~/.gem/credentials + cat > ~/.gem/credentials << EOF + --- + :rubygems_api_key: ${RUBYGEMS_API_KEY} + EOF + chmod 0600 ~/.gem/credentials + gem signin + for gem in pkg/*.gem; do gem push -V $gem; done diff --git a/.rubocop.yml b/.rubocop.yml index 9d7845fb..680e3e92 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_from: - 'https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml' AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.6 SuggestExtensions: false Gemspec/RequireMFA: diff --git a/README.adoc b/README.adoc index b510aa71..3ed9fc25 100644 --- a/README.adoc +++ b/README.adoc @@ -1,13 +1,18 @@ -= emf2svg +image:https://github.com/metanorma/emf2svg-ruby/actions/workflows/build.yml/badge.svg["Build", link="https://github.com/metanorma/emf2svg-ruby/actions/workflows/build.yml"] +image:https://badge.fury.io/rb/emf2svg.svg["Gem Version", link="https://badge.fury.io/rb/emf2svg"] + -== Purpose += emf2svg -Provides Ruby access to https://github.com/kakwa/libemf2svg (temporarily using +== Overview +emf2svg-ruby provides Ruby front-end to emf to svg converter https://github.com/kakwa/libemf2svg (temporarily using the https://github.com/metanorma/libemf2svg[Metanorma fork] until upstreaming is complete). -== Installation +== Requirements: +Ruby >= 2.6 +== Installation Install the gem directly: [source,sh] @@ -22,19 +27,28 @@ Or add it to your `Gemfile`: gem 'emf2svg' ---- -=== Dependencies +=== Packaging +We distribute pre-compiled libraries for a set of machine architecture. On supported platforms, this removes the need +for compiling the C extension and installation of system dependencies. This results in much faster and more reliable installation. + +==== Native extensions +* x86_64-linux (GNU and musl flavors) +* aarch64-linux (GNU and musl flavors) +* x86_64-darwin +* arm64-darwin +* x64-mingw32 +* x64-mingw-ucrt -* libiconv -* libpng -* libfontconfig -* libfreetype +=== Building GEM from source +emf2svg build script maintaince and installs all required libraries and other dependencies using vcpkg package manager +You still need to install appropriate build system (like gcc, clang or Visual Studio) and cmake +On Debian systems there is vcpkg bug [https://github.com/microsoft/vcpkg/issues/15931] that needs to be addressed by installing gperf package: ==== Windows On Windows all necessary libraries are precompiled but you'll need Visual Studio 2019 with C++ Build Tools, which can be downloaded -https://visualstudio.microsoft.com/downloads/[here], or installed with -Chocolatey: +https://visualstudio.microsoft.com/downloads/[here], or installed with Chocolatey: [source,sh] ---- @@ -55,22 +69,16 @@ brew install cmake [source,sh] ---- # compiler -apt-get install gcc g++ +apt-get install gcc g++ gperf cmake pkg-config # or -apt-get install clang - -# build deps -apt-get install cmake pkg-config - -# library deps with their headers -apt-get install libpng-dev libc6-dev libfontconfig1-dev libfreetype6-dev zlib1g-dev +apt-get install clang gperf cmake pkg-config ---- ===== Fedora [source,sh] ---- -yum install cmake libpng-devel freetype-devel fontconfig-devel gcc-c++ gcc +yum install cmake gcc-c++ gcc ---- == Usage diff --git a/emf2svg.gemspec b/emf2svg.gemspec index adb68b0f..91a1529b 100644 --- a/emf2svg.gemspec +++ b/emf2svg.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.summary = "Ruby interface to libemf2svg." spec.homepage = "https://github.com/metanorma/emf2svg-ruby" spec.license = "BSD-2-Clause" - spec.required_ruby_version = ">= 2.5.0" + spec.required_ruby_version = ">= 2.6.0" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/metanorma/emf2svg-ruby" diff --git a/lib/emf2svg/recipe.rb b/lib/emf2svg/recipe.rb index 880b9cdf..6bee328e 100644 --- a/lib/emf2svg/recipe.rb +++ b/lib/emf2svg/recipe.rb @@ -8,11 +8,11 @@ class Recipe < MiniPortileCMake ROOT = Pathname.new(File.expand_path("../..", __dir__)) def initialize - super("libemf2svg", "1.6.0") + super("libemf2svg", "1.7.0") @files << { - url: "https://github.com/metanorma/libemf2svg/releases/download/v1.6.0/libemf2svg.tar.gz", - sha256: "0f186f40b98c06acdec1278a314cEc1f093e7504d34f7a15b697ebfe6c4d3097", # rubocop:disable Layout/LineLength + url: "https://github.com/metanorma/libemf2svg/releases/download/v1.7.0/libemf2svg.tar.gz", + sha256: "a87a02510f87ed4510a3426fa8636b340e26d96f25edf63c3ba465e7e9d7e2eb", # rubocop:disable Layout/LineLength } @target = ROOT.join(@target).to_s @@ -25,7 +25,6 @@ def cook_if_not def cook super - FileUtils.touch(checkpoint) end @@ -36,14 +35,10 @@ def host_platform case @host when /\Ax86_64.*mingw32/ "x64-mingw32" - when /\Ai[3-6]86.*mingw32/ - "x86-mingw32" when /\Ax86_64.*linux/ "x86_64-linux" when /\A(arm64|aarch64).*linux/ "arm64-linux" - when /\Ai[3-6]86.*linux/ - "x86-linux" when /\Ax86_64.*(darwin|macos|osx)/ "x86_64-darwin" when /\A(arm64|aarch64).*(darwin|macos|osx)/ @@ -58,10 +53,10 @@ def target_platform case ENV["target_platform"] when /\A(arm64|aarch64).*(darwin|macos|osx)/ "arm64-darwin" - when /\Ac86_64.*(darwin|macos|osx)/ + when /\Ax86_64.*(darwin|macos|osx)/ "x86_64-darwin" when /\A(arm64|aarch64).*linux/ - "arm64-linux" + "aarch64-linux" else ENV["target_platform"] || host_platform end @@ -73,17 +68,24 @@ def target_triplet when "arm64-darwin" "arm64-osx" when "x86_64-darwin" - "x86_64-osx" - else - target_platform + "x64-osx" + when "aarch64-linux" + "arm64-linux" + when "x86_64-linux" + "x64-linux" + when /\Ax64-mingw(32|-ucrt)/ + "x64-mingw-static" end end - # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength - def cross_compiling? - not host_platform.eql? target_platform + def windows_native? + MiniPortile.windows? && target_triplet.eql?("x64-mingw-static") + end + + def drop_target_triplet? + windows_native? || host_platform.eql?(target_platform) end def checkpoint @@ -94,15 +96,13 @@ def configure_defaults opts = [] opts << "-DCMAKE_BUILD_TYPE=Release" + opts << "-DLONLY=ON" - if MiniPortile.windows? || cross_compiling? - opts << "-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake" + unless target_triplet.nil? || drop_target_triplet? + opts << " -DVCPKG_TARGET_TRIPLET=#{target_triplet}" end - if cross_compiling? && (not MiniPortile.windows?) - message("Cross-compiling on #{host_platform} for #{target_platform}\n") - opts << "-DVCPKG_TARGET_TRIPLET=#{target_triplet}" - end + opts << "-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake" opts end @@ -116,6 +116,7 @@ def make_cmd end def install + message("Called install\n") libs = if MiniPortile.windows? Dir.glob(File.join(work_path, "Release", "*.dll")) else diff --git a/lib/emf2svg/version.rb b/lib/emf2svg/version.rb index b654eb6e..55313a7c 100644 --- a/lib/emf2svg/version.rb +++ b/lib/emf2svg/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Emf2svg - VERSION = "1.3.1" + VERSION = "1.4.0" end