You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2021/11/06 14:30:15 UTC

[couchdb-erlfdb] 01/03: Upgrade to rebar3, add Windows support

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

kocolosk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git

commit 68211f31c26d4a42d27e59827a6507be7cbc2dc9
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Tue Nov 2 16:34:37 2021 -0400

    Upgrade to rebar3, add Windows support
    
    This patch updates erlfdb to build using rebar3. It relies on rebar3's
    `pc` plugin to build the NIF instead of the compiled copy of davisp's
    erlang-native-compiler, which does essentially the same thing. I left
    the rebar_gdb_plugin code in the repo, although I did not update that
    plugin to make it compatible with rebar3 yet.
    
    With rebar3 in place, I also made the changes necessary to support
    Windows. One gotcha is that the unit tests will fail unless you set
    the erlfdb test_cluster_file environment variable to point to a running
    fdb.cluster file. I didn't get through all the hoops to make the
    approach of spinning up an embedded fdbserver work in a x-platform way.
    Apparently Windows doesn't let you supply a Python script for the
    spawn_executable argument of erlang:open_port/2. I added a rebar3
    profile to help here. The following command will cause the test suite
    to connect to an FDB server that is managing its configuration in the
    default location on Windows:
    
      rebar3 as win32_external_fdbserver eunit
---
 .gitignore                      |   8 ++++----
 Makefile                        |   7 ++++---
 enc                             | Bin 26053 -> 0 bytes
 rebar.config                    |  33 +++++++++++++++++++++++++++------
 rebar.lock                      |   1 +
 src/erlfdb_util.erl             |   3 ++-
 win32_external_fdbserver.config |   5 +++++
 7 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6782584..a928261 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,12 @@
-
+# Unit testing
+.erlfdb/
 .eunit/
-.rebar/
 
 compile_commands.json
 erln8.config
 
+# Build artifacts
 c_src/*.d
 c_src/*.o
-ebin/
-
 priv/erlfdb_nif.*
+_build/
diff --git a/Makefile b/Makefile
index b6752bc..5f9396e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
 all: check
 
 build:
-	rebar compile
+	@rebar3 compile
 
 check: build
-	rebar eunit
+	@rebar3 eunit
 
 clean:
-	rebar clean
+	@rebar3 clean
+	@rm -rf _build
diff --git a/enc b/enc
deleted file mode 100755
index 5338498..0000000
Binary files a/enc and /dev/null differ
diff --git a/rebar.config b/rebar.config
index fb60112..617594c 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,22 +1,43 @@
+{plugins, [
+    pc
+]}.
+
+{provider_hooks, [
+    {pre, [
+        {compile, {pc, compile}},
+        {clean, {pc, clean}}
+    ]}
+]}.
+
 {port_specs, [
     {"priv/erlfdb_nif.so", ["c_src/*.c"]}
 ]}.
 
-{plugins, [rebar_gdb_plugin]}.
-
 {port_env, [
     {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
         "CFLAGS", "$CFLAGS -I/usr/local/include -Ic_src/ -g -Wall -Werror"},
     {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
         "CXXFLAGS", "$CXXFLAGS -I/usr/local/include -Ic_src/ -g -Wall -Werror"},
+    {"win32",
+        "CFLAGS", "$CFLAGS /I\"c:/Program Files/foundationdb/include\" /O2 /DNDEBUG"},
+    {"win32",
+        "CXXFLAGS", "$CXXFLAGS /I\"c:/Program Files/foundationdb/include\" /O2 /DNDEBUG"},
 
     {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
-        "LDFLAGS", "$LDFLAGS -L/usr/local/lib -lfdb_c"}
+        "LDFLAGS", "$LDFLAGS -L/usr/local/lib -lfdb_c"},
+    {"win32",
+        "LDFLAGS", "$LDFLAGS /LIBPATH:\"c:/Program Files/foundationdb/lib/foundationdb\" fdb_c.lib"}
+]}.
+
+{profiles, [
+    {win32_external_fdbserver, [
+        {eunit_opts, [
+            {sys_config, "win32_external_fdbserver.config"}
+        ]}
+    ]}
 ]}.
 
 {eunit_opts, [
+    debug_info,
     verbose
 ]}.
-
-{pre_hooks, [{"", compile, "escript enc compile"}]}.
-{post_hooks, [{"", clean, "escript enc clean"}]}.
diff --git a/rebar.lock b/rebar.lock
new file mode 100644
index 0000000..57afcca
--- /dev/null
+++ b/rebar.lock
@@ -0,0 +1 @@
+[].
diff --git a/src/erlfdb_util.erl b/src/erlfdb_util.erl
index 58fa12d..30c427a 100644
--- a/src/erlfdb_util.erl
+++ b/src/erlfdb_util.erl
@@ -215,9 +215,10 @@ init_fdb_db(ClusterFile, Options) ->
     DefaultFDBCli = os:find_executable("fdbcli"),
     FDBCli = case ?MODULE:get(Options, fdbcli_bin, DefaultFDBCli) of
         false -> erlang:error(fdbcli_not_found);
+        DefaultFDBCli -> "fdbcli";
         FDBCli0 -> FDBCli0
     end,
-    Fmt = "~s -C ~s --exec 'configure new single ssd'",
+    Fmt = "~s -C ~s --exec \"configure new single ssd\"",
     Cmd = lists:flatten(io_lib:format(Fmt, [FDBCli, ClusterFile])),
     case os:cmd(Cmd) of
         "Database created" ++ _ -> ok;
diff --git a/win32_external_fdbserver.config b/win32_external_fdbserver.config
new file mode 100644
index 0000000..3ca1c6f
--- /dev/null
+++ b/win32_external_fdbserver.config
@@ -0,0 +1,5 @@
+[
+    {erlfdb, [
+        {test_cluster_file, <<"c:/ProgramData/foundationdb/fdb.cluster">>}
+    ]}
+].