This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/arrow-flight-sql-postgresql.git


The following commit(s) were added to refs/heads/main by this push:
     new d17e837  Add a CI job on macOS (#91)
d17e837 is described below

commit d17e837142d37afb08cd308c4e2d6e1ea1ce660e
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Sep 5 15:33:42 2023 +0900

    Add a CI job on macOS (#91)
    
    Closes GH-89
---
 .github/workflows/test.yaml | 85 ++++++++++++++++++++++++++++++---------------
 Brewfile                    | 22 ++++++++++++
 doc/source/install.md       |  2 +-
 meson.build                 | 14 +++++---
 test/helper/sandbox.rb      | 53 +++++++++++-----------------
 5 files changed, 111 insertions(+), 65 deletions(-)

diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 877f02f..eebb05d 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -29,52 +29,81 @@ permissions:
   contents: read
 
 jobs:
-  ubuntu:
-    name: Ubuntu - PostgreSQL ${{ matrix.postgresql-version }}
-    runs-on: ubuntu-latest
-    timeout-minutes: 10
+  test:
+    name: ${{ matrix.os }} - PostgreSQL ${{ matrix.postgresql-version }}
+    runs-on: ${{ matrix.os }}-latest
+    timeout-minutes: 15
     strategy:
       fail-fast: false
       matrix:
+        os:
+          - macos
+          - ubuntu
         postgresql-version:
           - "15"
     steps:
       - uses: actions/checkout@v4
-      - name: Install Apache Arrow
+      - name: Install dependencies on Ubuntu
+        if: matrix.os == 'ubuntu'
         run: |
           sudo apt update
-          sudo apt install -y -V ca-certificates lsb-release wget
-          apt_source_deb=apache-arrow-apt-source-latest-$(lsb_release 
--codename --short).deb
-          wget https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id 
--short | tr 'A-Z' 'a-z')/${apt_source_deb}
+          sudo apt install -y -V \
+            ca-certificates \
+            gpg \
+            lsb-release \
+            wget
+          os=$(lsb_release --id --short | tr 'A-Z' 'a-z')
+          code_name=$(lsb_release --codename --short)
+
+          apt_source_deb=apache-arrow-apt-source-latest-${code_name}.deb
+          wget 
https://apache.jfrog.io/artifactory/arrow/${os}/${apt_source_deb}
           sudo apt install -y -V ./${apt_source_deb}
+
+          wget -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
+            sudo gpg --no-default-keyring --keyring 
/usr/share/keyrings/pgdg.gpg --import -
+          (echo "Types: deb"; \
+           echo "URIs: http://apt.postgresql.org/pub/repos/apt";; \
+           echo "Suites: ${code_name}-pgdg"; \
+           echo "Components: main"; \
+           echo "Signed-By: /usr/share/keyrings/pgdg.gpg") | \
+            sudo tee /etc/apt/sources.list.d/pgdg.sources
+
           sudo apt update
+          sudo apt -y -V purge '^postgresql'
           sudo apt install -y -V \
             libarrow-flight-sql-glib-dev \
-            meson \
-            ninja-build
-      - name: Install PostgreSQL
-        run: |
-          sudo apt -y -V purge '^postgresql'
-          suite=$(lsb_release --codename --short)-pgdg
-          sudo tee /etc/apt/sources.list.d/pgdg.list <<APT_SOURCE
-          deb http://apt.postgresql.org/pub/repos/apt ${suite} main
-          APT_SOURCE
-          wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc 
| sudo apt-key add -
-          sudo apt update
-          sudo apt -y -V -t ${suite} install \
             libkrb5-dev \
+            meson \
+            ninja-build \
             postgresql-${{ matrix.postgresql-version }} \
             postgresql-server-dev-${{ matrix.postgresql-version }}
+      - name: Install dependencies on macOS
+        if: matrix.os == 'macos'
+        run: |
+          sed \
+            -i '' \
+            -e 's/postgresql@[0-9]*/postgresql@${{ matrix.postgresql-version 
}}/g' \
+            Brewfile
+          brew update
+          brew bundle
+          echo "$(brew --prefix postgresql@${{ matrix.postgresql-version 
}})/bin" >> $GITHUB_PATH
       - name: Install Apache Arrow Flight SQL adapter
         run: |
-          meson \
-            setup \
-            --prefix=/tmp/local \
-            -Dbenchmark=true \
-            -Dpostgresql_dir=$(pg_config --binddir)/.. \
-            build
-          ninja -C build
-          sudo ninja -C build install
+          setup_args=(
+            "--prefix=/tmp/local"
+            "-Dbenchmark=true"
+            "-Dpostgresql_dir=$(pg_config --bindir)/.."
+          )
+          if [ ${{ matrix.os }} = "macos" ]; then
+            setup_args+=("--pkg-config-path=$(brew --prefix 
libpq)/lib/pkgconfig")
+          fi
+          meson setup "${setup_args[@]}" build
+          meson compile -C build
+          if [ ${{ matrix.os }} = "ubuntu" ]; then
+            sudo meson install -C build
+          else
+            meson install -C build
+          fi
       - uses: ruby/setup-ruby@v1
         with:
           ruby-version: ruby
diff --git a/Brewfile b/Brewfile
new file mode 100644
index 0000000..160a39d
--- /dev/null
+++ b/Brewfile
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+brew "apache-arrow-glib"
+brew "libpq"
+brew "meson"
+brew "gobject-introspection"
+brew "postgresql@15"
diff --git a/doc/source/install.md b/doc/source/install.md
index b716a7b..08b827a 100644
--- a/doc/source/install.md
+++ b/doc/source/install.md
@@ -63,7 +63,7 @@ See {doc}`configuration` how to configure Apache Arrow Flight 
SQL adapter for Po
 You need to install the followings before you build Apache Arrow
 Flight SQL adapter for PostgreSQL:
 
-- PostgreSQL: https://www.postgresql.org/download/
+- PostgreSQL 15 or later: https://www.postgresql.org/download/
 - Apache Arrow C++ with Flight SQL support: https://arrow.apache.org/install/
 - Meson: https://mesonbuild.com/
 - Ninja: https://ninja-build.org/
diff --git a/meson.build b/meson.build
index 5110ad8..7adefd2 100644
--- a/meson.build
+++ b/meson.build
@@ -36,7 +36,7 @@ if postgresql_dir != ''
   pg_config_names += [postgresql_dir / 'bin' / 'pg_config']
 endif
 pg_config_names += ['pg_config']
-pg_config = find_program(pg_config_names)
+pg_config = find_program(pg_config_names, version: '>= 15')
 
 arrow_flight_sql = dependency(
   'ArrowFlightSql',
@@ -59,9 +59,14 @@ postgresql = declare_dependency(
   compile_args: run_command(pg_config,
                             '--cflags_sl',
                             check: true).stdout().strip(),
-  include_directories: run_command(pg_config,
-                                   '--includedir-server',
-                                   check: true).stdout().strip(),
+  include_directories: [
+    include_directories(
+      run_command(pg_config,
+                  '--includedir-server',
+                  check: true).stdout().strip(),
+      is_system: true
+    ),
+  ]
 )
 install_dir = run_command(pg_config, '--pkglibdir', check: 
true).stdout().strip()
 afs = shared_module(
@@ -69,6 +74,7 @@ afs = shared_module(
   'src/afs.cc',
   dependencies: [arrow_flight_sql, postgresql],
   name_prefix: '',
+  name_suffix: 'so',
   install: true,
   install_dir: install_dir,
 )
diff --git a/test/helper/sandbox.rb b/test/helper/sandbox.rb
index c11b2da..09c5898 100644
--- a/test/helper/sandbox.rb
+++ b/test/helper/sandbox.rb
@@ -128,7 +128,6 @@ module Helper
                flight_sql_port: 35432)
       @dir = File.join(@base_dir, db_path)
       @log_path = File.join(@dir, "log", @log_base_name)
-      socket_dir = File.join(@dir, "socket")
       @port = port
       @pgpass = Tempfile.new("arrow-flight-sql-test-pgpass")
       @pgpass.puts("#{@address}:#{@port}:*:#{@user}:#{@password}")
@@ -150,14 +149,11 @@ module Helper
                     "-D", @dir)
       end
       prepare_tls if use_tls?
-      FileUtils.mkdir_p(socket_dir)
       postgresql_conf = File.join(@dir, "postgresql.conf")
       File.open(postgresql_conf, "a") do |conf|
         conf.puts("listen_addresses = '#{@address}'")
         conf.puts("port = #{@port}")
-        unless windows?
-          conf.puts("unix_socket_directories = '#{socket_dir}'")
-        end
+        conf.puts("unix_socket_directories = ''")
         if use_tls?
           conf.puts("ssl = on")
           conf.puts("ssl_ca_file = 'root.crt'")
@@ -296,16 +292,12 @@ module Helper
       def included(base)
         base.module_eval do
           setup :setup_tmp_dir
-          teardown :teardown_tmp_dir
 
           setup :setup_db
-          teardown :teardown_db
 
           setup :setup_postgres
-          teardown :teardown_postgres
 
           setup :setup_test_db
-          teardown :teardown_test_db
         end
       end
     end
@@ -329,21 +321,21 @@ module Helper
     def setup_tmp_dir
       memory_fs = "/dev/shm"
       if File.exist?(memory_fs)
-        @tmp_dir = File.join(memory_fs, "arrow-flight-sql")
+        tmp_dir = memory_fs
       else
-        @tmp_dir = File.join(__dir__, "tmp")
+        tmp_dir = nil
       end
-      FileUtils.rm_rf(@tmp_dir)
-      FileUtils.mkdir_p(@tmp_dir)
-    end
-
-    def teardown_tmp_dir
-      debug_dir = ENV["AFS_TEST_DEBUG_DIR"]
-      if debug_dir and File.exist?(@tmp_dir)
-        FileUtils.rm_rf(debug_dir)
-        FileUtils.mv(@tmp_dir, debug_dir)
-      else
-        FileUtils.rm_rf(@tmp_dir)
+      Dir.mktmpdir("arrow-flight-sql-", tmp_dir) do |dir|
+        @tmp_dir = dir
+        begin
+          yield
+        ensure
+          debug_dir = ENV["AFS_TEST_DEBUG_DIR"]
+          if debug_dir and File.exist?(@tmp_dir)
+            FileUtils.rm_rf(debug_dir)
+            FileUtils.mv(@tmp_dir, debug_dir)
+          end
+        end
       end
     end
 
@@ -353,15 +345,13 @@ module Helper
         shared_preload_libraries: shared_preload_libraries,
       }
       @postgresql.initdb(**options)
+      yield
     end
 
     def shared_preload_libraries
       ["arrow_flight_sql"]
     end
 
-    def teardown_db
-    end
-
     def start_postgres
       @postgresql.start
     end
@@ -372,10 +362,11 @@ module Helper
 
     def setup_postgres
       start_postgres
-    end
-
-    def teardown_postgres
-      stop_postgres if @postgresql
+      begin
+        yield
+      ensure
+        stop_postgres if @postgresql
+      end
     end
 
     def create_db(postgresql, db_name)
@@ -390,9 +381,7 @@ module Helper
                         "WHERE datname = current_database()")
       oid = result.lines[3].strip
       @test_db_dir = File.join(@postgresql.dir, "base", oid)
-    end
-
-    def teardown_test_db
+      yield
     end
   end
 end

Reply via email to