docs: Add macos build documentation 98/20998/10
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Wed, 31 Jul 2019 15:57:58 +0000 (17:57 +0200)
committerDave Wallace <dwallacelf@gmail.com>
Wed, 9 Oct 2019 13:18:47 +0000 (13:18 +0000)
Type: docs

Change-Id: Iee03aacab2cfcb4e87190302dc641e8273b7f096
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
.gitignore
docs/gettingstarted/developers/cross_compile_macos.rst [new file with mode: 0644]
docs/gettingstarted/developers/index.rst
extras/scripts/cross_compile_macos.sh [new file with mode: 0755]
extras/scripts/patches/macos_build_externals.patch [new file with mode: 0644]

index 8535007..64a579e 100644 (file)
@@ -106,3 +106,6 @@ GTAGS
 # No core files
 **/core
 
+# extra scripts config
+/extras/scripts/.config/
+
diff --git a/docs/gettingstarted/developers/cross_compile_macos.rst b/docs/gettingstarted/developers/cross_compile_macos.rst
new file mode 100644 (file)
index 0000000..932f865
--- /dev/null
@@ -0,0 +1,57 @@
+.. _cross_compile_macos :
+
+Cross compilation on MacOS
+==========================
+
+This is a first attempt to support Cross compilation of VPP on MacOS for development (linting, completion, compile_commands.json)
+
+
+**Prerequisites**
+
+* You'll need to install the following packages
+
+.. code-block:: bash
+
+  pip3 install ply
+  brew install diffutils gnu-sed pkg-config ninja crosstool-ng
+
+* You'll also need to install ``gnu-ident 2.2.11`` to be able to ``make checkstyle``. You can get it from `GNU <https://www.gnu.org/prep/ftp.html>`_
+* You should link the binaries to make them available in your path with their original names e.g. :
+
+.. code-block:: bash
+
+  ln -s $(which gsed) /usr/local/bin/sed
+  ln -s $(which gindent) /usr/local/bin/indent
+  ln -s /usr/local/Cellar/diffutils/3.7/bin/diff /usr/local/bin/diff
+
+
+**Setup**
+
+* Create a `cross compile toolchain <https://crosstool-ng.github.io/>`_
+* Create a case sensitive volume and mount the toolchain in it e.g. in ``/Volumes/xchain``
+* Create a xchain.toolchain file with ``$VPP_DIR/extras/scripts/cross_compile_macos.sh conf /Volumes/xchan``
+
+For now we don't support e-build so dpdk, rdma, quicly won't be compiled as part of ``make build``
+
+To build with the toolchain do:
+
+.. code-block:: bash
+
+  $VPP_DIR/extras/scripts/cross_compile_macos.sh build
+
+
+To get the compile_commands.json do
+
+.. code-block:: bash
+
+  $VPP_DIR/extras/scripts/cross_compile_macos.sh cc
+  # >> ./build-root/build-vpp[_debug]-native/vpp/compile_commands.json
+
+
+
+This should build vpp on MacOS
+
+
+Good luck :)
+
+
index 2d27da9..93f4e33 100644 (file)
@@ -40,3 +40,4 @@ The Developers section covers the following areas:
    buildwireshark
    punt
    quic_plugin
+   cross_compile_macos.rst
diff --git a/extras/scripts/cross_compile_macos.sh b/extras/scripts/cross_compile_macos.sh
new file mode 100755 (executable)
index 0000000..998d914
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+VPP_DIR=$(dirname ${BASH_SOURCE[0]})/../..
+VPP_TOOLCHAIN_FILE=$VPP_DIR/extras/scripts/.config/macos.toolchain
+BUILD_PATCH=$VPP_DIR/extras/scripts/patches/macos_build_externals.patch
+VPP_EXPORT_CC=""
+
+function help() {
+cat << __EOF__
+Usage: $0 [COMMAND]
+conf <dir>        create the configuration file
+                  with the give cross-toolchain directory
+build             run Macos <make build>
+build-release     run Macos <make build-release>
+compile_commands  Generate compile_commands.json
+__EOF__
+}
+
+function create_toolchain_file () {
+    if [ x$1 = x ]; then
+        echo "Please specify the cross toolchain directory"
+        exit 1
+    fi
+    XCHAIN=$1
+    if [ ! -e  ]; then
+      mkdir -p $VPP_DIR/extras/scripts/.config
+      echo "
+SET(CMAKE_SYSTEM_NAME Linux)
+SET(CMAKE_SYSTEM_VERSION 1)
+
+# specify the cross compiler
+SET(CMAKE_C_COMPILER   $XCHAIN/x86_64-ubuntu16.04-linux-gnu/bin/x86_64-ubuntu16.04-linux-gnu-gcc)
+SET(CMAKE_CXX_COMPILER $XCHAIN/x86_64-ubuntu16.04-linux-gnu/bin/x86_64-ubuntu16.04-linux-gnu-g++)
+
+# where is the target environment
+SET(CMAKE_FIND_ROOT_PATH  $XCHAIN/x86_64-ubuntu16.04-linux-gnu $XCHAIN/x86_64-ubuntu16.04-linux-gnu/x86_64-ubuntu16.04-linux-gnu/sysroot/)
+
+SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+SET(CMAKE_SYSTEM_PROCESSOR x86_64)
+# This is needed to build vpp-papi
+SET(PYTHON_EXECUTABLE /usr/local/bin/python)" | tee $VPP_TOOLCHAIN_FILE > /dev/null
+      echo "Configration file created"
+      echo "please edit $VPP_TOOLCHAIN_FILE"
+    else
+      echo "configuration file already exists"
+      echo "please edit $VPP_TOOLCHAIN_FILE"
+    fi
+}
+
+function vpp_make () {
+  cd $VPP_DIR ; git apply $BUILD_PATCH
+  trap "cd $VPP_DIR ; git apply -R $BUILD_PATCH" EXIT
+  export VPP_EXTRA_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${VPP_TOOLCHAIN_FILE} -DCMAKE_EXPORT_COMPILE_COMMANDS=${VPP_EXPORT_CC}" ; make -C $VPP_DIR $1
+}
+
+case $1 in
+    conf)
+        create_toolchain_file $2
+        ;;
+    build)
+        vpp_make build
+        ;;
+    build-release)
+        vpp_make build-release
+        ;;
+    compile_commands)
+        VPP_EXPORT_CC=ON vpp_make build
+        echo "compile_commands.json should be generated"
+        echo "check $VPP_DIR/build-root/build-vpp_debug-native/vpp/compile_commands.json"
+        ;;
+    *)
+        help
+        ;;
+esac
\ No newline at end of file
diff --git a/extras/scripts/patches/macos_build_externals.patch b/extras/scripts/patches/macos_build_externals.patch
new file mode 100644 (file)
index 0000000..ec1aeb3
--- /dev/null
@@ -0,0 +1,17 @@
+diff --git a/build/external/Makefile b/build/external/Makefile
+index e5dff3c43..ffd0a6476 100644
+--- a/build/external/Makefile
++++ b/build/external/Makefile
+@@ -45,10 +45,10 @@ clean:
+       @rm -rf $(B) $(I)
+ .PHONY: install
+-install: dpdk-install rdma-core-install quicly-install
++install:
+ .PHONY: config
+-config: dpdk-config rdma-core-config
++config:
+ ##############################################################################
+ # .deb packaging