Samples/HelloWorld/build_dotnetcore.sh
#!/bin/bash
set -euo pipefail

echo "Starting Build"

# Set defaults if these environment vars aren't present:
FMWK="${AMBROSIA_DOTNET_FRAMEWORK:-netcoreapp3.1}"
FMWK20="${AMBROSIA_DOTNET_FRAMEWORK:-netstandard2.0}"
CONF="${AMBROSIA_DOTNET_CONF:-Release}"

if ! which AmbrosiaCS 2>/dev/null; then
    echo "ERROR: AmbrosiaCS not on PATH"
    exit 1
fi
RSRC=$(dirname `which AmbrosiaCS`)
if ! [ -d "$RSRC" ]; then
    echo "Error: directory does not exist: $RSRC"
    echo "Expected to find resource/ directory which is part of the AMBROSIA binary distribution."
    exit 1
fi

echo
echo "(STEP 1) Build enough so that we have compiled versions of our RPC interfaces"
BUILDIT="dotnet publish -o publish -c $CONF -f $FMWK "
BUILDIT20="dotnet publish -o publish -c $CONF -f $FMWK20 "
set -x
$BUILDIT20 IClient1/IClient1.csproj
$BUILDIT20 IClient2/IClient2.csproj
$BUILDIT20 IClient3/IClient3.csproj
$BUILDIT20 ServerAPI/IServer.csproj
set +x

echo
echo "(STEP 2) Use those DLL's to generate proxy code for RPC calls"

CG="AmbrosiaCS CodeGen -f netcoreapp3.1 -f net461"
set -x
$CG -o ServerInterfaces  -a publish/IServer.dll -p ServerAPI/IServer.csproj
$CG -o Client1Interfaces -a publish/IServer.dll  -a publish/IClient1.dll -p ServerAPI/IServer.csproj -p IClient1/IClient1.csproj
$CG -o Client2Interfaces -a publish/IServer.dll -a publish/IClient2.dll -p ServerAPI/IServer.csproj -p IClient2/IClient2.csproj
$CG -o Client3Interfaces -a publish/IServer.dll -a publish/IClient3.dll -p ServerAPI/IServer.csproj -p IClient3/IClient3.csproj
set +x

echo
echo "(STEP 3) Now the entire solution can be built."
set -x
$BUILDIT GeneratedSourceFiles/Client1Interfaces/latest/Client1Interfaces.csproj
$BUILDIT GeneratedSourceFiles/Client2Interfaces/latest/Client2Interfaces.csproj
$BUILDIT GeneratedSourceFiles/Client3Interfaces/latest/Client3Interfaces.csproj
$BUILDIT GeneratedSourceFiles/ServerInterfaces/latest/ServerInterfaces.csproj
#$BUILDIT Server/Server.csproj
$BUILDIT Client1/Client1.csproj
$BUILDIT Client2/Client2.csproj
$BUILDIT Client3/Client3.csproj
set +x
#$BUILDIT HelloWorld.sln
echo
echo "Hello world built."
