You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/05/16 00:23:22 UTC

[arrow] branch master updated: ARROW-5329: [MATLAB] Add support for building MATLAB interface to Feather directly within MATLAB

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

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 70cbe37  ARROW-5329: [MATLAB] Add support for building MATLAB interface to Feather directly within MATLAB
70cbe37 is described below

commit 70cbe37695197fbe8b5ec30fa95e00ab3185d1be
Author: Mark Cafaro <ma...@mathworks.com>
AuthorDate: Wed May 15 19:23:14 2019 -0500

    ARROW-5329: [MATLAB] Add support for building MATLAB interface to Feather directly within MATLAB
    
    The MATLAB interface to Feather currently uses CMake to build MEX files. It would be convenient to be able to build the MEX file used by the MATLAB interface to Feather directly using normal MATLAB commands.
    
    This will also provide a workaround for MEX compilation issues when using older CMake versions with newer versions of MATLAB (R2018b and beyond).
    
    The commits in the pull request add a new `build_support` folder to the MATLAB subfolder in the Arrow repository. This `build_support` folder contains two functions called `compile` and `test` that use the `ARROW_HOME` environment variable and the `mex` command to build the necessary MEX files.
    
    For example:
    
    ``` matlab
    >> cd build_support
    >> compile
    ...lots of output...
    >> test
    ...successfully passed all tests...
    ```
    
    Thanks to Mark (@mcafaro) for implementing this and working through the initial review in https://github.com/mathworks/arrow/pull/13
    
    Author: Mark Cafaro <ma...@mathworks.com>
    Author: rdmello <ry...@mathworks.com>
    Author: Mark Cafaro <34...@users.noreply.github.com>
    
    Closes #4321 from rdmello/ARROW-5329 and squashes the following commits:
    
    1a14d83b3 <rdmello> Updating README.md with instructions for building directly using MATLAB
    a685bce91 <Mark Cafaro> Switched from MATLAB char arrays to strings
    39e8e2a2b <Mark Cafaro> Changed MATLAB MEX compilation to use RPATH only on UNIX systems
    a90af5a3d <Mark Cafaro> Changed MATLAB variable names to be more clear
    f9e1aeed7 <Mark Cafaro> Fixed MATLAB variable name
    03729828d <Mark Cafaro> Added functions for MATLAB build support
---
 matlab/README.md                   | 31 ++++++++++++++++++++++++++--
 matlab/build_support/common_vars.m | 24 ++++++++++++++++++++++
 matlab/build_support/compile.m     | 41 ++++++++++++++++++++++++++++++++++++++
 matlab/build_support/test.m        | 28 ++++++++++++++++++++++++++
 4 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/matlab/README.md b/matlab/README.md
index 663bd20..5edf08b 100644
--- a/matlab/README.md
+++ b/matlab/README.md
@@ -31,7 +31,7 @@ The current code only supports reading numeric types from Feather files.
 
 See: [Arrow CPP README](../cpp/README.md)
 
-### Build MATLAB interface to Apache Arrow using MATLAB R2018a or later:
+### Build MATLAB interface to Apache Arrow using MATLAB R2018a:
 
     cd arrow/matlab
     mkdir build
@@ -39,7 +39,7 @@ See: [Arrow CPP README](../cpp/README.md)
     cmake ..
     make
 
-### Non-standard MATLAB and Arrow installations
+#### Non-standard MATLAB and Arrow installations
 
 To specify a non-standard MATLAB install location, use the Matlab_ROOT_DIR CMake flag:
 
@@ -49,6 +49,33 @@ To specify a non-standard Arrow install location, use the ARROW_HOME CMake flag:
 
     cmake .. -DARROW_HOME=/<PATH_TO_ARROW_INSTALL>
 
+### Build MATLAB interface to Arrow using MATLAB R2018b or later:
+
+This may be preferred if you are using MATLAB R2018b or later and have encountered [linker errors](https://gitlab.kitware.com/cmake/cmake/issues/18391) when using CMake.
+
+Prerequisite: Ensure that the Arrow C++ library is already installed and the `ARROW_HOME` environment variable is set to the installation root.
+
+To verify this, you can run:
+
+``` matlab
+>> getenv ARROW_HOME
+```
+
+This should print a path that contains `include` and `lib` directories with Arrow C++ headers and libraries.
+
+Navigate to the `build_support` subfolder and run the `compile` function to build the necessary MEX files:
+
+``` matlab
+>> cd build_support
+>> compile
+```
+
+Run the `test` function to execute the unit tests:
+
+``` matlab
+>> test
+```
+
 ## Try it out
 
 ### Add the src and build directories to your MATLAB path
diff --git a/matlab/build_support/common_vars.m b/matlab/build_support/common_vars.m
new file mode 100644
index 0000000..a7c9d6a
--- /dev/null
+++ b/matlab/build_support/common_vars.m
@@ -0,0 +1,24 @@
+function vars = common_vars()
+% 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.
+
+fileDir = fileparts(mfilename("fullpath"));
+
+vars.srcDir = fullfile(fileDir, "..", "src");
+vars.testDir = fullfile(fileDir, "..", "test");
+vars.buildDir = fullfile(fileDir, "..", "build");
+end
\ No newline at end of file
diff --git a/matlab/build_support/compile.m b/matlab/build_support/compile.m
new file mode 100644
index 0000000..d436dad
--- /dev/null
+++ b/matlab/build_support/compile.m
@@ -0,0 +1,41 @@
+function compile()
+% 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.
+
+vars = common_vars();
+
+mkdir(vars.buildDir);
+
+ldflags = string.empty;
+if isunix
+    arrowHome = getenv("ARROW_HOME");
+    if isempty(arrowHome)
+        error("The ARROW_HOME environment variable must be set.");
+    end
+    ldflags(end+1) = "-Wl";
+    ldflags(end+1) = "-rpath '" + fullfile(arrowHome, "lib") + "'";
+end
+
+mex(fullfile(vars.srcDir, "featherreadmex.cc"), ...
+    fullfile(vars.srcDir, "feather_reader.cc"), ...
+    fullfile(vars.srcDir, "util", "handle_status.cc"), ...
+    "-L" + fullfile(arrowHome, "lib"), "-larrow", ...
+    "-I" + fullfile(arrowHome, "include"), ...
+    "LDFLAGS=""\$LDFLAGS " + strjoin(ldflags, ",") + """", ...
+    "-outdir", vars.buildDir, ...
+    "-R2018a", "-v");
+end
diff --git a/matlab/build_support/test.m b/matlab/build_support/test.m
new file mode 100644
index 0000000..990549e
--- /dev/null
+++ b/matlab/build_support/test.m
@@ -0,0 +1,28 @@
+function test()
+% 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.
+
+vars = common_vars();
+
+compile();
+
+originalPath = addpath(vars.srcDir, vars.buildDir);
+restoreOriginalPath = onCleanup(@()path(originalPath));
+
+results = runtests(vars.testDir, "IncludeSubfolders", true, "OutputDetail", 3);
+assert(all(~[results.Failed]));
+end