NaCl build and test scripts
authorElijah Taylor <elijahtaylor@google.com>
Mon, 20 Dec 2010 18:55:00 +0000 (10:55 -0800)
committerElijah Taylor <elijahtaylor@google.com>
Mon, 20 Dec 2010 18:55:00 +0000 (10:55 -0800)
14 files changed:
nacl/README [new file with mode: 0644]
nacl/common.sh [new file with mode: 0644]
nacl/config-nacl-runtime.cache [new file with mode: 0644]
nacl/config-nacl-runtime64.cache [new file with mode: 0644]
nacl/nacl-common.sh [new file with mode: 0644]
nacl/nacl-mono-config-cache [new file with mode: 0644]
nacl/nacl-mono.sh [new file with mode: 0755]
nacl/nacl-runtime-mono.sh [new file with mode: 0755]
nacl/nacl64-mono-config-cache [new file with mode: 0644]
nacl/nacl64-mono.sh [new file with mode: 0755]
nacl/normal-mono.sh [new file with mode: 0755]
nacl/test/hw.cs [new file with mode: 0644]
nacl/test/my.c [new file with mode: 0644]
nacl/test/nacl [new file with mode: 0755]

diff --git a/nacl/README b/nacl/README
new file mode 100644 (file)
index 0000000..191fec6
--- /dev/null
@@ -0,0 +1,92 @@
+Quick guide
+===========
+
+Prerequistites (see end of file for gclient & svn paths)
+--------------
+1. Naclports from SVN
+   - needed for nacl toolchain (nacl-gcc, etc.)
+   - needed for packages (zlib for nacl, etc.)
+2. Native Client repo from SVN
+   - currently needed for sel_ldr
+3. Mono with NaCl support (you have it if you're reading this file)
+
+4. Directory conventions used in this document
+(your directories may differ...)
+  ~/naclports  Naclports repo from SVN
+  ~/nacl       Native Client repo from SVN
+  ~/mono       Mono for NaCl
+
+5. Setting your environment:
+  export NACL_SDK_PATH=/home/username/naclports
+  export NACL_PATH=/home/username/nacl
+5a. Make sure you have a dbg sel_ldr available
+  /home/username/nacl/
+    native_client/scons-out/dbg-${OS_SUBDIR}-x86-${BITSIZE}/staging
+5b. If it is not available, scons build it (substitute
+   linux with mac or win as needed)
+      cd /home/username/nacl/native_client
+      ./scons MODE=dbg-linux,nacl [platform=x86-64]
+
+6. Build naclports libraries
+     cd /home/username/naclports/src/packages
+     ./nacl-install-all.sh
+
+7. Build NaCl Mono Runtime ('libmono.a' for NaCl, 5 minutes):
+  cd /home/username/mono/trunk/nacl
+  ./nacl-runtime-mono.sh [TARGET_BITSIZE=32/64 for cross-compiling runtime]
+
+8. (optional for AOT) Build NaCl Mono Compiler: ('nacl[64]-mono' AOT cross compiler for NaCl, 5 minutes):
+  cd /home/username/mono/trunk/nacl
+  ./nacl-mono.sh (32-bit cross-compiler)
+  ./nacl64-mono.sh (64-bit cross-compiler)
+
+Native Client Mono Install locations:
+  /home/username/mono/trunk/nacl/runtime
+  /home/username/mono/trunk/nacl/compiler
+
+Normal (not-Native-Client) Mono Install location:
+  /home/username/mono/trunk/nacl/normal-mono
+
+Simple Test (requires sel_ldr to run)
+  cd  /home/username/mono/trunk/nacl/test
+  ./nacl [normal,aot,regression] (defaults to nacl,jit,simple test)
+
+
+SVN Repos
+=========
+
+1. Getting Naclports repo
+  cd ~
+  mkdir naclports
+  cd naclports
+  gclient config https://naclports.googlecode.com/svn/trunk/src
+  gclient sync
+
+2. Getting Native Client repo
+
+  cd ~
+  mkdir nacl
+  cd nacl
+  vim .gclient
+--------add text below-------
+solutions = [
+  { "name"        : "native_client",
+    "url"         : "svn://svn.chromium.org/native_client/trunk/src/native_client",
+  },
+  { "name"        : "supplement.DEPS",
+    "url"         : "svn://svn.chromium.org/native_client/trunk/deps/supplement.DEPS",
+  },
+]
+---------end text------------
+  gclient sync
+  gclient runhooks --force
+
+
+3. Getting Mono repo
+
+  cd ~
+  mkdir mono
+  cd mono
+  // see http://mono-project.com/Compiling_Mono_From_Git
+
+
diff --git a/nacl/common.sh b/nacl/common.sh
new file mode 100644 (file)
index 0000000..bbf8b29
--- /dev/null
@@ -0,0 +1,204 @@
+# Copyright (c) 2009 The Native Client Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that be
+# found in the LICENSE file.
+#
+
+set -o nounset
+set -o errexit
+
+# scripts that source this file must be run from within packages tree
+readonly SAVE_PWD=$(pwd)
+
+# Pick platform directory for compiler.
+readonly OS_NAME=$(uname -s)
+if [ $OS_NAME = "Darwin" ]; then
+  readonly OS_SUBDIR="mac"
+  readonly OS_SUBDIR_SHORT="mac"
+elif [ $OS_NAME = "Linux" ]; then
+  readonly OS_SUBDIR="linux"
+  readonly OS_SUBDIR_SHORT="linux"
+else
+  readonly OS_SUBDIR="windows"
+  readonly OS_SUBDIR_SHORT="win"
+fi
+
+readonly MACHINE=$(uname -m)
+if [ $MACHINE = "x86_64" ]; then
+  readonly TARGET_BITSIZE=${TARGET_BITSIZE:-"64"}
+  readonly HOST_BITSIZE=${HOST_BITSIZE:-"64"}
+else
+  # uname -m reports i686 on Linux and i386 on Mac
+  readonly TARGET_BITSIZE=${TARGET_BITSIZE:-"32"}
+  readonly HOST_BITSIZE=${HOST_BITSIZE:-"32"}
+fi
+
+NACL_SDK_BASE=/usr/local/google/elijahtaylor/nacl_svn/native_client/tools/sdk/nacl-sdk
+#NACL_SDK_BASE=/usr/local/google/elijahtaylor/nacl_svn/native_client/toolchain/linux_x86
+
+if [ $TARGET_BITSIZE == "64" ]; then
+  readonly TARGET_BIT_PREFIX="64"
+else
+  readonly TARGET_BIT_PREFIX=""
+fi
+# we might want to override the detected host platform (e.g. on OSX 10.6)
+if [ $HOST_BITSIZE == "64" ]; then
+  readonly HOST_BIT_PREFIX="64"
+else
+  readonly HOST_BIT_PREFIX=""
+fi
+
+# locate default nacl_sdk toolchain
+# TODO: no arm support
+readonly NACL_SDK=${NACL_SDK_PATH:-/usr/local/google/elijahtaylor/naclports_svn}
+readonly NACL_DEV=${NACL_PATH:-/usr/local/google/elijahtaylor/nacl_svn}
+readonly NACL_NATIVE_CLIENT=${NACL_SDK}/src
+readonly NACL_SDK_BASE=${NACL_SDK_BASE:-\
+${NACL_NATIVE_CLIENT}/toolchain/${OS_SUBDIR_SHORT}_x86}
+
+readonly NACL_BIN_PATH=${NACL_SDK_BASE}/bin
+readonly NACLCC=${NACL_SDK_BASE}/bin/nacl${TARGET_BIT_PREFIX}-gcc
+readonly NACLCXX=${NACL_SDK_BASE}/bin/nacl${TARGET_BIT_PREFIX}-g++
+readonly NACLAR=${NACL_SDK_BASE}/bin/nacl${TARGET_BIT_PREFIX}-ar
+readonly NACLRANLIB=${NACL_SDK_BASE}/bin/nacl${TARGET_BIT_PREFIX}-ranlib
+readonly NACLLD=${NACL_SDK_BASE}/bin/nacl${TARGET_BIT_PREFIX}-ld
+readonly NACLAS=${NACL_SDK_BASE}/bin/nacl${TARGET_BIT_PREFIX}-as
+
+# NACL_SDK_GCC_SPECS_PATH is where nacl-gcc 'specs' file will be installed
+readonly NACL_SDK_GCC_SPECS_PATH=${NACL_SDK_BASE}/lib/gcc/nacl64/4.4.3
+
+# NACL_SDK_USR is where the headers, libraries, etc. will be installed
+readonly NACL_SDK_USR=${NACL_SDK_BASE}/nacl/usr
+readonly NACL_SDK_USR_INCLUDE=${NACL_SDK_USR}/include
+readonly NACL_SDK_USR_LIB=${NACL_SDK_USR}/lib
+
+
+######################################################################
+# Helper functions
+######################################################################
+
+Banner() {
+  echo "######################################################################"
+  echo $*
+  echo "######################################################################"
+}
+
+
+VerifyPath() {
+  # make sure path isn't all slashes (possibly from an unset variable)
+  local PATH=$1
+  local TRIM=${PATH##/}
+  if [ ${#TRIM} -ne 0 ]; then
+    return 0
+  else
+    return 1
+  fi
+}
+
+
+ChangeDir() {
+  local NAME=$1
+  if VerifyPath ${NAME}; then
+    cd ${NAME}
+  else
+    echo "ChangeDir called with bad path."
+    exit -1
+  fi
+}
+
+
+Remove() {
+  local NAME=$1
+  if VerifyPath ${NAME}; then
+    rm -rf ${NAME}
+  else
+    echo "Remove called with bad path."
+    exit -1
+  fi
+}
+
+
+MakeDir() {
+  local NAME=$1
+  if VerifyPath ${NAME}; then
+    mkdir -p ${NAME}
+  else
+    echo "MakeDir called with bad path."
+    exit -1
+  fi
+}
+
+
+PatchSpecFile() {
+  # fix up spaces so gcc sees entire path
+  local SED_SAFE_SPACES_USR_INCLUDE=${NACL_SDK_USR_INCLUDE/ /\ /}
+  local SED_SAFE_SPACES_USR_LIB=${NACL_SDK_USR_LIB/ /\ /}
+  # have nacl-gcc dump specs file & add include & lib search paths
+  ${NACL_SDK_BASE}/bin/nacl-gcc -dumpspecs |\
+    sed "/*cpp:/{
+      N
+      s|$| -I${SED_SAFE_SPACES_USR_INCLUDE}|
+    }" |\
+    sed "/*link_libgcc:/{
+      N
+      s|$| -L${SED_SAFE_SPACES_USR_LIB}|
+    }" >${NACL_SDK_GCC_SPECS_PATH}/specs
+}
+
+
+DefaultConfigureStep() {
+  Banner "Configuring ${PACKAGE_NAME}"
+  # export the nacl tools
+  export CC=${NACLCC}
+  export CXX=${NACLCXX}
+  export AR=${NACLAR}
+  export RANLIB=${NACLRANLIB}
+  export PKG_CONFIG_PATH=${NACL_SDK_USR_LIB}/pkgconfig
+  export PKG_CONFIG_LIBDIR=${NACL_SDK_USR_LIB}
+  export PATH=${NACL_BIN_PATH}:${PATH};
+  ChangeDir ${NACL_PACKAGES_REPOSITORY}/${PACKAGE_NAME}
+  Remove ${PACKAGE_NAME}-build
+  MakeDir ${PACKAGE_NAME}-build
+  cd ${PACKAGE_NAME}-build
+  ../configure \
+    --host=nacl \
+    --disable-shared \
+    --prefix=${NACL_SDK_USR} \
+    --exec-prefix=${NACL_SDK_USR} \
+    --libdir=${NACL_SDK_USR_LIB} \
+    --oldincludedir=${NACL_SDK_USR_INCLUDE} \
+    --with-http=off \
+    --with-html=off \
+    --with-ftp=off \
+    --with-x=no
+}
+
+
+DefaultBuildStep() {
+  # assumes pwd has makefile
+  make clean
+  make -j4
+}
+
+
+DefaultInstallStep() {
+  # assumes pwd has makefile
+  make install
+}
+
+
+DefaultCleanUpStep() {
+  PatchSpecFile
+  ChangeDir ${SAVE_PWD}
+}
+
+
+DefaultPackageInstall() {
+  DefaultPreInstallStep
+  DefaultDownloadStep
+  DefaultExtractStep
+  DefaultPatchStep
+  DefaultConfigureStep
+  DefaultBuildStep
+  DefaultInstallStep
+  DefaultCleanUpStep
+}
diff --git a/nacl/config-nacl-runtime.cache b/nacl/config-nacl-runtime.cache
new file mode 100644 (file)
index 0000000..13a1412
--- /dev/null
@@ -0,0 +1,16 @@
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+ac_cv_func_mmap=${ac_cv_func_mmap=no}
+ac_cv_var_timezone=${ac_cv_var_timezone=yes}
+
diff --git a/nacl/config-nacl-runtime64.cache b/nacl/config-nacl-runtime64.cache
new file mode 100644 (file)
index 0000000..13a1412
--- /dev/null
@@ -0,0 +1,16 @@
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+ac_cv_func_mmap=${ac_cv_func_mmap=no}
+ac_cv_var_timezone=${ac_cv_var_timezone=yes}
+
diff --git a/nacl/nacl-common.sh b/nacl/nacl-common.sh
new file mode 100644 (file)
index 0000000..b63b7eb
--- /dev/null
@@ -0,0 +1,19 @@
+
+CopyNormalMonoLibs() {
+  NORMAL_MSCORLIB_DLL=$MONO_TRUNK_NACL/normal-mono/lib/mono/2.0/mscorlib.dll
+  if [ ! -f ${NORMAL_MSCORLIB_DLL} ]
+  then
+    Banner "Normal mscorlib.dll not found, building normal mono"
+    cd ${MONO_TRUNK_NACL}
+    ./normal-mono.sh
+  fi
+  if [ ! -f ${NORMAL_MSCORLIB_DLL} ]
+  then
+    Banner "Normal mscorlib.dll not found after normal mono build, exiting..."
+    exit -1
+  fi
+  Banner "Copying normal-mono libs to install dir"
+  mkdir -p ${INSTALL_PATH}/lib/mono
+  cp -R ${MONO_TRUNK_NACL}/normal-mono/lib/mono/* ${INSTALL_PATH}/lib/mono/
+}
+
diff --git a/nacl/nacl-mono-config-cache b/nacl/nacl-mono-config-cache
new file mode 100644 (file)
index 0000000..830854b
--- /dev/null
@@ -0,0 +1,16 @@
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+mono_cv_uscore=${mono_cv_uscore=no}
+ac_cv_target=${ac_cv_target=i686-pc-nacl}
+
diff --git a/nacl/nacl-mono.sh b/nacl/nacl-mono.sh
new file mode 100755 (executable)
index 0000000..a409db6
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# nacl-mono.sh
+#
+# usage:  nacl-mono.sh
+#
+# this script builds a compiler for 32-bit NaCl code
+# (installed in ./compiler folder)
+#
+
+readonly MONO_TRUNK_NACL=$(pwd)
+
+readonly PACKAGE_NAME=nacl-mono-build
+
+readonly INSTALL_PATH=${MONO_TRUNK_NACL}/compiler
+
+source common.sh
+source nacl-common.sh
+
+
+CustomConfigureStep() {
+  Banner "Configuring ${PACKAGE_NAME}"
+  set +e
+  cd ${PACKAGE_NAME}
+  make distclean
+  cd ${MONO_TRUNK_NACL}
+  set -e
+  Remove ${PACKAGE_NAME}
+  MakeDir ${PACKAGE_NAME}
+  cd ${PACKAGE_NAME}
+  cp ../nacl-mono-config-cache ../nacl-mono-config-cache.temp
+  if [ $HOST_BITSIZE = "64" ]; then
+    ../../configure \
+      CC='cc -m32' CXX='g++ -m32' \
+      --host=i386-pc-linux \
+      --build=amd64-pc-linux \
+      --target=nacl \
+      --prefix=${INSTALL_PATH} \
+      --with-tls=pthread \
+      --enable-nacl-codegen \
+      --disable-mono-debugger \
+      --disable-mcs-build \
+      --with-sigaltstack=no \
+      --cache-file=../nacl-mono-config-cache.temp
+  else
+    ../../configure \
+      --target=nacl \
+      --prefix=${INSTALL_PATH} \
+      --with-tls=pthread \
+      --enable-nacl-codegen \
+      --disable-mono-debugger \
+      --disable-mcs-build \
+      --with-sigaltstack=no \
+      --cache-file=../nacl-mono-config-cache.temp
+  fi
+  
+
+  rm ../nacl-mono-config-cache.temp
+}
+
+CustomBuildStep() {
+  MONO_NACL_ALIGN_MASK_OFF=1 make -j4
+}
+
+CustomInstallStep() {
+  MONO_NACL_ALIGN_MASK_OFF=1 make install
+}
+
+CustomPackageInstall() {
+  CustomConfigureStep
+  #CustomBuildStep
+  #CustomInstallStep
+  DefaultBuildStep
+  DefaultInstallStep
+}
+
+
+CustomPackageInstall
+exit 0
diff --git a/nacl/nacl-runtime-mono.sh b/nacl/nacl-runtime-mono.sh
new file mode 100755 (executable)
index 0000000..51e0944
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/bash
+# Copyright (c) 2009 The Native Client Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that be
+# found in the LICENSE file.
+#
+
+# nacl-runtime-mono.sh
+#
+# usage:  nacl-runtime-mono.sh
+#
+# this script builds mono runtime for Native Client 
+#
+
+readonly MONO_TRUNK_NACL=$(pwd)
+
+source common.sh
+source nacl-common.sh
+
+readonly PACKAGE_NAME=runtime${TARGET_BIT_PREFIX}-build
+readonly INSTALL_PATH=${MONO_TRUNK_NACL}/runtime${TARGET_BIT_PREFIX}
+
+
+CustomConfigureStep() {
+  Banner "Configuring ${PACKAGE_NAME}"
+  # export the nacl tools
+  set +e
+  if [ -f ${PACKAGE_NAME}/Makefile ]
+  then
+    cd ${PACKAGE_NAME}
+  fi
+  make distclean
+  cd ${MONO_TRUNK_NACL}
+  set -e
+  cp config-nacl-runtime.cache config-nacl-runtime.cache.temp
+  Remove ${PACKAGE_NAME}
+  MakeDir ${PACKAGE_NAME}
+  cd ${PACKAGE_NAME}
+  # TODO: remove this once libintl.h becomes available to nacl
+  CC=${NACLCC} CXX=${NACLCXX} AR=${NACLAR} RANLIB=${NACLRANLIB} PKG_CONFIG_PATH=${NACL_SDK_USR_LIB}/pkgconfig \
+  PKG_CONFIG_LIBDIR=${NACL_SDK_USR_LIB} PATH=${NACL_BIN_PATH}:${PATH} LIBS="-lnosys -lg" \
+  CFLAGS="-g -D_POSIX_PATH_MAX=256 -DPATH_MAX=256" ../../configure \
+    --host=nacl${TARGET_BIT_PREFIX} \
+    --disable-shared \
+    --exec-prefix=${INSTALL_PATH} \
+    --libdir=${INSTALL_PATH}/lib \
+    --prefix=${INSTALL_PATH} \
+    --oldincludedir=${MONO_TRUNK_NACL}/runtime/include \
+    --disable-mcs-build \
+    --with-glib=embedded \
+    --with-tls=pthread \
+    --enable-threads=posix \
+    --without-sigaltstack \
+    --without-mmap \
+    --with-gc=included \
+    --enable-nacl-gc \
+    --enable-nacl-codegen \
+    --cache-file=../config-nacl-runtime.cache.temp
+  echo "// --- Native Client runtime below" >> config.h
+  echo "#define pthread_cleanup_push(x, y)" >> config.h
+  echo "#define pthread_cleanup_pop(x)" >> config.h
+  echo "#define DISABLE_SOCKETS 1" >> config.h
+  echo "#undef HAVE_EPOLL" >> config.h
+  echo "#undef HAVE_WORKING_SIGALTSTACK" >> config.h
+  echo "extern long int timezone;" >> config.h
+  echo "extern int daylight;" >> config.h
+  echo "#define sem_trywait(x) sem_wait(x)" >> config.h
+  echo "#define sem_timedwait(x,y) sem_wait(x)" >> config.h
+  echo "#define getdtablesize() (32768)" >> config.h
+  echo "// --- Native Client runtime below" >> eglib/src/eglib-config.h
+  echo "#undef G_BREAKPOINT" >> eglib/src/eglib-config.h
+  echo "#define G_BREAKPOINT() G_STMT_START { __asm__ (\"hlt\"); } G_STMT_END" >> eglib/src/eglib-config.h
+  rm ../config-nacl-runtime.cache.temp
+}
+
+CustomInstallStep() {
+  make install
+  CopyNormalMonoLibs
+}
+
+CustomPackageInstall() {
+  CustomConfigureStep
+  DefaultBuildStep
+  CustomInstallStep
+}
+
+
+CustomPackageInstall
+exit 0
diff --git a/nacl/nacl64-mono-config-cache b/nacl/nacl64-mono-config-cache
new file mode 100644 (file)
index 0000000..6e2d042
--- /dev/null
@@ -0,0 +1,16 @@
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+mono_cv_uscore=${mono_cv_uscore=no}
+ac_cv_target=${ac_cv_target=x86_64-pc-nacl}
+
diff --git a/nacl/nacl64-mono.sh b/nacl/nacl64-mono.sh
new file mode 100755 (executable)
index 0000000..dd2ba53
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# nacl64-mono.sh
+#
+# usage:  nacl64-mono.sh
+#
+# this script builds a compiler for 64-bit NaCl code
+# (installed in ./compiler folder)
+#
+
+readonly MONO_TRUNK_NACL=$(pwd)
+
+readonly PACKAGE_NAME=nacl64-mono-build
+
+readonly INSTALL_PATH=${MONO_TRUNK_NACL}/compiler
+
+source common.sh
+source nacl-common.sh
+
+
+CustomConfigureStep() {
+  Banner "Configuring ${PACKAGE_NAME}"
+  set +e
+  cd ${PACKAGE_NAME}
+  make distclean
+  cd ${MONO_TRUNK_NACL}
+  set -e
+  Remove ${PACKAGE_NAME}
+  MakeDir ${PACKAGE_NAME}
+  cd ${PACKAGE_NAME}
+  cp ../nacl64-mono-config-cache ../nacl64-mono-config-cache.temp
+  if [ $HOST_BITSIZE = "64" ]; then
+    ../../configure \
+      CFLAGS="-O0" CXXFLAGS="-O0" CC='cc -m32' CXX='g++ -m32' \
+      --host=i386-pc-linux \
+      --build=amd64-pc-linux \
+      --target=nacl64 \
+      --prefix=${INSTALL_PATH} \
+      --with-tls=pthread \
+      --enable-nacl-codegen \
+      --disable-mono-debugger \
+      --disable-mcs-build \
+      --with-sigaltstack=no \
+      --cache-file=../nacl-mono-config-cache.temp
+  else
+    ../../configure \
+      --target=nacl64 \
+      --prefix=${INSTALL_PATH} \
+      --with-tls=pthread \
+      --enable-nacl-codegen \
+      --disable-mono-debugger \
+      --disable-mcs-build \
+      --with-sigaltstack=no \
+      --cache-file=../nacl-mono-config-cache.temp
+  fi
+  
+
+  rm ../nacl-mono-config-cache.temp
+}
+
+CustomBuildStep() {
+  MONO_NACL_ALIGN_MASK_OFF=1 make -j4
+}
+
+CustomInstallStep() {
+  MONO_NACL_ALIGN_MASK_OFF=1 make install
+}
+
+CustomPackageInstall() {
+  CustomConfigureStep
+  #CustomBuildStep
+  #CustomInstallStep
+  DefaultBuildStep
+  DefaultInstallStep
+}
+
+
+CustomPackageInstall
+exit 0
diff --git a/nacl/normal-mono.sh b/nacl/normal-mono.sh
new file mode 100755 (executable)
index 0000000..88ebe68
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+# Copyright (c) 2009 The Native Client Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that be
+# found in the LICENSE file.
+#
+
+# normal-mono.sh
+#
+# usage:  normal-mono.sh
+#
+# this script builds normal x86 mono
+# (installed in ./normal folder)
+#
+
+readonly MONO_TRUNK_NACL=$(pwd)
+
+readonly PACKAGE_NAME=mono-normal-build
+
+source common.sh
+
+
+CustomConfigureStep() {
+  Banner "Configuring ${PACKAGE_NAME}"
+  set +e
+  if [ -f ${PACKAGE_NAME}/Makefile ]
+  then
+    cd ${PACKAGE_NAME}
+    make distclean
+  fi
+  cd ${MONO_TRUNK_NACL}
+  set -e
+  Remove ${PACKAGE_NAME}
+  MakeDir ${PACKAGE_NAME}
+  cd ${PACKAGE_NAME}
+  ../../configure \
+    --prefix=${MONO_TRUNK_NACL}/normal-mono \
+    --disable-parallel-mark \
+    --with-tls=pthread 
+}
+
+CustomPackageInstall() {
+  CustomConfigureStep
+  DefaultBuildStep
+  DefaultInstallStep
+}
+
+
+CustomPackageInstall
+exit 0
diff --git a/nacl/test/hw.cs b/nacl/test/hw.cs
new file mode 100644 (file)
index 0000000..f82c33e
--- /dev/null
@@ -0,0 +1,60 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Collections;
+using System.Text;
+using System.Threading;
+
+namespace Test {
+
+       public class c_code {
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               public extern static void my_c_func(int x, string s, double d);
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               public extern static void my_c_pass(int x);
+       }
+
+       public class HelloWorld
+       {
+               static public void Main ()
+               {
+               }
+
+               static public void Foobar (int x, string s)
+               {
+                       // first line is a simple test
+                       // 1. call back into c code 2. use mscorlib Math.Sqrt()
+                       c_code.my_c_func(x, s, Math.Sqrt(3.1415 * 3.1415));
+
+                       // second part of this test:
+                       // attempt a try/catch, generate exception w/ throw
+                       try {
+                               c_code.my_c_pass(0);
+                               // attempt an invalid cast
+                               throw new InvalidCastException();
+                               c_code.my_c_pass(1);
+                       }
+                       catch (InvalidCastException e) {
+                               c_code.my_c_pass(2);
+                       }
+                       c_code.my_c_pass(3);
+
+                       // third part of this test:
+                       // attempt an invalid cast again, this time generating
+                       // exception instead of using explicit throw.
+                       try {
+                               c_code.my_c_pass(0);
+                               StringBuilder reference1 = new StringBuilder();
+                               object reference2 = reference1;
+                               // attempt invalid cast
+                               int reference3 = (int)reference2;
+                               c_code.my_c_pass(4);
+                       }
+                       catch (InvalidCastException e) {
+                               c_code.my_c_pass(5);
+                       }
+                       c_code.my_c_pass(3);
+               }
+       } 
+}
diff --git a/nacl/test/my.c b/nacl/test/my.c
new file mode 100644 (file)
index 0000000..218cec4
--- /dev/null
@@ -0,0 +1,139 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include <mono/metadata/appdomain.h>
+#include <mono/metadata/assembly.h>
+#include <mono/metadata/debug-helpers.h>
+
+extern void* mono_aot_module_mscorlib_info;
+
+extern void* mono_aot_module_hw_info;
+
+extern void mono_set_corlib_data(void *data, size_t size);
+extern void mono_aot_register_module(void *aot_info);
+extern void mono_aot_init(void);
+extern void mono_jit_set_aot_only(int aot_only);
+extern MonoDomain * mini_init (const char *filename, const char *runtime_version);
+
+#if !defined(TRUE)
+#define TRUE 1
+#endif
+#if !defined(FALSE)
+#define FALSE 0
+#endif
+
+void my_c_func(int arg, const char *str, double d) {
+  /* str from c# is immutable */
+  printf("*** my_c_func(%d, '%s', %1.4f) received\n", arg, str, (float)d);
+}
+
+
+void my_c_pass(int x) {
+  char *msg = "undefined";
+  switch(x) {
+    case 0:  msg = "about to throw an exception...";  break;
+    case 1:  msg = "thrown invalid cast exception was not caught!"; break;
+    case 2:  msg = "thrown invalid cast exception was safely caught!"; break;
+    case 3:  msg = "...leaving exeception test."; break;
+    case 4:  msg = "generated invalid cast exception was not caught!"; break;
+    case 5:  msg = "generated invalid cast exception was safely caught!"; break;
+  }
+  printf("*** my_c_pass(%d): %s\n", x, msg);
+}
+
+
+
+void try_mono() {
+  MonoDomain *domain;
+  MonoAssembly *ma;
+  MonoImage *mi;
+  MonoClass *mc;
+  MonoMethodDesc *mmd;
+  MonoMethod *mm;
+  MonoObject *mo;
+  FILE *mscorlib;
+  char *corlib_data = NULL;
+  void *args [2];
+  static int x = 123000;
+  args [0] = &x;
+  args [1] = "hello world";
+
+#if defined(__native_client__)
+  mscorlib = fopen("mscorlib.dll", "r");
+  if (NULL != mscorlib) {
+    size_t size;
+    struct stat st;
+    if (0 == stat("mscorlib.dll", &st)) {
+      size = st.st_size;
+      printf("reading mscorlib.dll, size %ld\n", size);
+      corlib_data = malloc(size);
+      if (corlib_data != NULL) {
+        while (fread(corlib_data, 1, size, mscorlib) != 0) ;
+        if (!ferror(mscorlib)) {
+          mono_set_corlib_data(corlib_data, size);
+        } else {
+          perror("error reading mscorlib.dll");
+          free(corlib_data);
+          corlib_data = NULL;
+        }
+      } else {
+        perror("Could not allocate memory");
+      }
+    } else {
+      perror("stat error");
+    }
+    fclose(mscorlib);
+  }
+#endif
+
+#ifdef AOT_VERSION
+  printf("address of mono_aot_module_mscorlib_info:  %p\n", mono_aot_module_mscorlib_info);
+  printf("address of mono_aot_module_hw_info:  %p\n", mono_aot_module_hw_info);
+
+  // mono_jit_set_aot_only(TRUE) should be enabled now.
+  // if not enabled, I suspect we're still jitting...
+  mono_jit_set_aot_only(TRUE);
+
+  mono_aot_register_module(mono_aot_module_mscorlib_info);
+  mono_aot_register_module(mono_aot_module_hw_info);
+#endif
+
+  domain = mini_init("hw.exe", "v2.0.50727");
+  printf("mono domain: %p\n", domain);
+
+  ma = mono_domain_assembly_open(domain, "hw.exe");
+  printf("mono assembly: %p\n", ma);
+
+  mi = mono_assembly_get_image(ma);
+  printf("mono image: %p\n", mi);
+
+  mc = mono_class_from_name(mi, "Test", "HelloWorld");
+  printf("mono class: %p\n", mc);
+
+  mmd = mono_method_desc_new("Test.HelloWorld:Foobar(int,string)", TRUE);
+  printf("mono desc method: %p\n", mmd);
+
+  mm = mono_method_desc_search_in_image(mmd, mi);
+  printf("mono method: %p\n", mm);
+
+  // add c functions for mono test code to invoke
+  mono_add_internal_call("Test.c_code::my_c_func", (void *) my_c_func);
+  mono_add_internal_call("Test.c_code::my_c_pass", (void *) my_c_pass);
+
+  mo = mono_runtime_invoke(mm, NULL, args, NULL);
+  printf("mono object: %p\n", mo);
+  if (NULL != corlib_data) free(corlib_data);
+}
+
+
+int main() {
+  int i;
+  printf("address of main(): %p\n", main);
+  printf("address of stack : %p\n", &i);
+  printf("\nProgram a.out output:\n");
+  printf("==========================\n");
+  try_mono();
+  printf("==========================\n\n");
+  return 0;
+}
diff --git a/nacl/test/nacl b/nacl/test/nacl
new file mode 100755 (executable)
index 0000000..d5d0098
--- /dev/null
@@ -0,0 +1,155 @@
+#!/bin/bash
+
+set -o nounset
+set -o errexit
+set -o verbose
+
+source ../common.sh
+
+MONO_RUNTIME_BASE=../runtime
+MONO_BASE=../compiler
+MONO="${MONO_BASE}/bin/nacl${TARGET_BIT_PREFIX}-mono"
+CC=$NACLCC
+AS=$NACLAS
+MODE=nacl
+COMPILE_AOT=0
+AOT_OBJS=
+CC_DEFINES=
+MONO_SNAPSHOT=mono-normal-build
+RELOCATE_RODATA="-Wl,--section-start=.rodata=0x2000000"
+export NACL_ALLOW_DYNCODE_REPLACEMENT=1
+
+if [ $# -gt 0 ]; then
+  while [ -n "$*" ]
+  do
+    if [ $1 == "normal" ]; then
+      MONO_RUNTIME_BASE=../normal-mono
+      MONO_BASE=../normal-mono
+      MONO=${MONO_BASE}/bin/mono
+      CC=gcc
+      AS=as
+      MODE=normal
+    elif [ $1 == "aot" ]; then
+      COMPILE_AOT=1
+      CC_DEFINES=-DAOT_VERSION
+      RELOCATE_RODATA=
+    elif [ $1 == "regression" ]; then
+      MODE=regression
+    else
+      echo "Unrecognized option '$1'"
+      exit -1
+    fi
+    shift
+  done
+fi
+
+readonly MONO_NORMAL_BASE=../normal-mono
+readonly NCVAL=ncval
+
+# add nacl-gcc to path (from NaCl SDK)
+export PATH=${NACL_BIN_PATH}:$PATH
+
+# add sel_ldr to path (from NaCl dev tree)
+export PATH=${NACL_DEV}/native_client/scons-out/dbg-${OS_SUBDIR}-x86-${TARGET_BITSIZE}/staging:$PATH
+
+# add nacl-mono to path
+export PATH=../normal-mono/bin:$PATH
+
+# echo version of nacl-gcc
+$CC --version
+
+echo $PATH
+which sel_ldr
+
+# echo version of gmcs 
+which gmcs
+../normal-mono/bin/gmcs --version
+
+# echo version of nacl-mono
+${MONO} --version
+
+# add MONO_PATH so mono can crank on local directory
+export MONO_PATH=$(pwd)
+echo ${MONO_PATH}
+
+#-----
+# enable the appropriate set of AOT options below.
+
+readonly AOT_OPTIONS=full,static,nodebug
+#-----
+
+# make a temp copy of mscorlib.dll in this directory
+cp ${MONO_NORMAL_BASE}/lib/mono/2.0/mscorlib.dll .
+
+# compile c-sharp file with gmcs
+MONO_PATH=. ../normal-mono/bin/gmcs -lib:. -warn:0 hw.cs
+
+# convert .exe to .exe.o assembly files
+# convert mscorlib to a .dll.o file
+if [ $COMPILE_AOT = "1" ]; then
+  MONO_PATH=. ${MONO} --aot=${AOT_OPTIONS} mscorlib.dll
+  MONO_PATH=. ${MONO} --aot=${AOT_OPTIONS} hw.exe
+  AOT_OBJS="hw.exe.o mscorlib.dll.o"
+fi
+
+# compile c and assembly into a.out, all statically linked
+# different options for normal and nacl-mono
+if [ $MODE = "normal" ]; then
+  $CC -g -static my.c ${CC_DEFINES} ${AOT_OBJS} -o hw-test -lmono-2.0 -lpthread -lm -ldl -lrt -I${MONO_RUNTIME_BASE}/include -I${MONO_RUNTIME_BASE}/include/mono-2.0 -L${MONO_RUNTIME_BASE}/lib
+elif [ $MODE = "nacl" ]; then
+  $CC -static my.c ${CC_DEFINES} ${AOT_OBJS} -o hw-test.nexe -lmono-2.0 -lpthread -lm -lnosys -I${MONO_RUNTIME_BASE}/include -I${MONO_RUNTIME_BASE}/include/mono-2.0 -L${MONO_RUNTIME_BASE}/lib ${RELOCATE_RODATA}
+fi
+
+readonly fsatests="basic.exe basic-float.exe basic-long.exe basic-calls.exe objects.exe arrays.exe basic-math.exe exceptions.exe devirtualization.exe basic-simd.exe gc-stress.exe imt_big_iface_test.exe generics.exe iltests.exe nacl.exe"
+if [ $MODE = "regression" ]; then
+  #rm -rf fsa-tmp
+  mkdir -p fsa-tmp
+  DIR=$(pwd)
+  cd ../${MONO_SNAPSHOT}/mono/mini/
+   make $fsatests generics-variant-types.dll TestDriver.dll
+   cp $fsatests generics-variant-types.dll TestDriver.dll $DIR/fsa-tmp
+  cd -
+  CLASS=${MONO_NORMAL_BASE}/lib/mono/2.0
+  cp $CLASS/System.Core.dll $CLASS/System.dll $CLASS/Mono.Posix.dll $CLASS/System.Configuration.dll $CLASS/System.Security.dll $CLASS/System.Xml.dll $CLASS/Mono.Security.dll $CLASS/Mono.Simd.dll fsa-tmp
+  cp mscorlib.dll fsa-tmp
+
+  AOT_OBJS=""
+  if [ $COMPILE_AOT = "1" ]; then
+    for t in $fsatests; do
+      MONO_PATH=fsa-tmp ${MONO} --aot=${AOT_OPTIONS} fsa-tmp/$t
+      AOT_OBJS="${AOT_OBJS} fsa-tmp/$t.o" 
+    done
+    for d in fsa-tmp/*.dll; do
+      MONO_PATH=fsa-tmp ${MONO} --aot=${AOT_OPTIONS} $d
+      AOT_OBJS="${AOT_OBJS} $d.o" 
+    done  
+  fi
+
+  $CC -o fsa-tmp/fsacheck.nexe -g -static ../../mono/mini/fsacheck.c ${CC_DEFINES} ${AOT_OBJS} -lmono-2.0 -lpthread -lm -lnosys -L${MONO_RUNTIME_BASE}/lib -I${MONO_RUNTIME_BASE}/include/mono-2.0  -I${MONO_RUNTIME_BASE}/include ${RELOCATE_RODATA}
+fi
+
+# only actually run the tests if we are on the target platform
+if [ $TARGET_BITSIZE = $HOST_BITSIZE ]; then
+  if [ $MODE = "regression" ]; then
+    cd fsa-tmp
+    ${NCVAL} -readwrite_sfi fsacheck.nexe 2> validator_out || echo "fsacheck.nexe invalid: continuing anyway"
+    nacl-objdump -d fsacheck.nexe > fsacheck.disasm
+    for t in $fsatests; do
+      sel_ldr -a -c fsacheck.nexe $t || true
+    done
+  else
+    export MONO_PATH=$(pwd)
+    # run generated test(select one or more below)
+    if [ $MODE = "normal" ]; then
+      ./hw-test
+    else
+      ${NCVAL} -readwrite_sfi hw-test.nexe 2> validator_out || echo "hw-test.nexe invalid: continuing anyway"
+      nacl-objdump -d hw-test.nexe > hw-test.disasm
+      sel_ldr -a -c hw-test.nexe
+    fi
+  fi
+fi
+
+exit 0
+