-
Notifications
You must be signed in to change notification settings - Fork 51
Add Linux support to .NET language extension #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MarkpageBxl
wants to merge
16
commits into
microsoft:main
Choose a base branch
from
MarkpageBxl:dotnet-linux
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1dbb48f
Make Logger and nativecsharpextension compile on Linux.
MarkpageBxl 704e592
Make DotnetEnvironment compile on Linux.
MarkpageBxl 2dd039b
Add build script for Linux.
MarkpageBxl 222d4f3
Add archive script for Linux.
MarkpageBxl ba10c7d
Add static nethost library from .NET 8.0 Linux runtime.
MarkpageBxl 774d4dc
Use nethost to lookup hostfxr on Linux.
MarkpageBxl d4afec8
Add debug compiler flag when building in debug.
MarkpageBxl f7456f2
Fix Linux/Windows portability issues.
MarkpageBxl 8ab5025
Add documentation about C# on Linux.
MarkpageBxl 7a99b8a
Fix _WIN32 preprocessor symbol typo.
MarkpageBxl 86d15ea
Cleanup argument loop in Linux scripts.
MarkpageBxl dd2f532
Fix doc links.
MarkpageBxl ca1d83a
Rationalize defines.
MarkpageBxl c47d3f3
Handle DOTNET_ROOT DotnetEnvironment on Linux.
MarkpageBxl ce93292
Linux support improvements on top of PR #64
SicongLiu2000 1cd3d8a
Merge branch ''main'' into dotnet-linux
SicongLiu2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
language-extensions/dotnet-core-CSharp/build/linux/build-dotnet-core-CSharp-extension.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Set root and working directories | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| ENL_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)" | ||
| DOTNET_EXTENSION_HOME="$ENL_ROOT/language-extensions/dotnet-core-CSharp" | ||
| DOTNET_EXTENSION_WORKING_DIR="$ENL_ROOT/build-output/dotnet-core-CSharp-extension/linux" | ||
|
|
||
| # Clean and create working directory | ||
| rm -rf "$DOTNET_EXTENSION_WORKING_DIR" | ||
| mkdir -p "$DOTNET_EXTENSION_WORKING_DIR" | ||
|
|
||
| # Default to release if no arguments provided | ||
| if [ $# -eq 0 ]; then | ||
| set -- "release" | ||
| fi | ||
|
|
||
| # Process each build configuration | ||
| for BUILD_CONFIGURATION in "$@"; do | ||
| BUILD_CONFIGURATION="$(echo "$BUILD_CONFIGURATION" | tr '[:upper:]' '[:lower:]')" | ||
|
|
||
| # Default to release if not debug | ||
| if [ "$BUILD_CONFIGURATION" != "debug" ]; then | ||
| BUILD_CONFIGURATION="release" | ||
| fi | ||
|
|
||
| echo "[Info] Building dotnet-core-CSharp-extension libnativecsharpextension.so..." | ||
|
|
||
| # Set build output directory | ||
| BUILD_OUTPUT="$DOTNET_EXTENSION_WORKING_DIR/$BUILD_CONFIGURATION" | ||
| rm -rf "$BUILD_OUTPUT" | ||
| mkdir -p "$BUILD_OUTPUT" | ||
| pushd "$BUILD_OUTPUT" > /dev/null | ||
|
|
||
| # Set source and include paths | ||
| DOTNET_NATIVE_SRC="$DOTNET_EXTENSION_HOME/src/native" | ||
| DOTNET_NATIVE_INCLUDE="$DOTNET_EXTENSION_HOME/include" | ||
| EXTENSION_HOST_INCLUDE="$ENL_ROOT/extension-host/include" | ||
| DOTNET_NATIVE_LIB="$DOTNET_EXTENSION_HOME/lib" | ||
|
|
||
| # Determine C++ compiler | ||
| CXX="${CXX:-c++}" | ||
|
|
||
| # Build compiler arguments | ||
| CC_ARGS=( | ||
| -shared | ||
| -fPIC | ||
| -fshort-wchar | ||
| -std=c++17 | ||
| -o libnativecsharpextension.so | ||
| "-I$DOTNET_NATIVE_INCLUDE" | ||
| "-I$EXTENSION_HOST_INCLUDE" | ||
| ) | ||
|
|
||
| if [ "$BUILD_CONFIGURATION" = "debug" ]; then | ||
| CC_ARGS+=(-DDEBUG -g) | ||
| fi | ||
|
|
||
| # Add all .cpp source files | ||
| for src in "$DOTNET_NATIVE_SRC"/*.cpp; do | ||
| CC_ARGS+=("$src") | ||
| done | ||
|
|
||
| # Link with static nethost library (must run restore-packages.sh first) | ||
| if [ ! -f "$DOTNET_NATIVE_LIB/libnethost.a" ]; then | ||
| echo "Error: libnethost.a not found at $DOTNET_NATIVE_LIB/libnethost.a" >&2 | ||
| echo " Run restore-packages.sh first to install the .NET SDK and copy libnethost.a." >&2 | ||
| exit 1 | ||
| fi | ||
| CC_ARGS+=("$DOTNET_NATIVE_LIB/libnethost.a") | ||
| # Link with libdl for dlopen/dlsym | ||
| CC_ARGS+=(-ldl) | ||
|
|
||
| echo "[Info] Compiling with: $CXX ${CC_ARGS[*]}" | ||
| "$CXX" "${CC_ARGS[@]}" | ||
|
|
||
| popd > /dev/null | ||
|
|
||
| # Build managed code | ||
| echo "[Info] Building Microsoft.SqlServer.CSharpExtension dll..." | ||
| DOTNET_MANAGED_SRC="$DOTNET_EXTENSION_HOME/src/managed" | ||
| dotnet build \ | ||
| "$DOTNET_MANAGED_SRC/Microsoft.SqlServer.CSharpExtension.csproj" \ | ||
| -m \ | ||
| -c "$BUILD_CONFIGURATION" \ | ||
| -o "$BUILD_OUTPUT" \ | ||
| --no-restore \ | ||
| --no-dependencies | ||
|
|
||
| echo "Success: Built dotnet-core-CSharp-extension for $BUILD_CONFIGURATION configuration." | ||
| done | ||
|
|
||
| exit 0 |
61 changes: 61 additions & 0 deletions
61
...uage-extensions/dotnet-core-CSharp/build/linux/create-dotnet-core-CSharp-extension-tar.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| ENL_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)" | ||
| DOTNET_EXTENSION_WORKING_DIR="$ENL_ROOT/build-output/dotnet-core-CSharp-extension/linux" | ||
|
|
||
| check_error() { | ||
| local error_level=$1 | ||
| local error_message=$2 | ||
| if [ "$error_level" -ne 0 ]; then | ||
| echo "Error: $error_message" >&2 | ||
| exit "$error_level" | ||
| fi | ||
| } | ||
|
|
||
| # Default to release if no arguments provided | ||
| if [ $# -eq 0 ]; then | ||
| set -- "release" | ||
| fi | ||
|
|
||
| # Process each build configuration | ||
| for BUILD_CONFIGURATION in "$@"; do | ||
| BUILD_CONFIGURATION="$(echo "$BUILD_CONFIGURATION" | tr '[:upper:]' '[:lower:]')" | ||
|
|
||
| # Default to release if not debug | ||
| if [ "$BUILD_CONFIGURATION" != "debug" ]; then | ||
| BUILD_CONFIGURATION="release" | ||
| fi | ||
|
|
||
| BUILD_OUTPUT="$DOTNET_EXTENSION_WORKING_DIR/$BUILD_CONFIGURATION" | ||
| mkdir -p "$BUILD_OUTPUT/packages" | ||
|
|
||
| # Delete the ref folder so that the tarball can be loaded by the SPEES | ||
| rm -rf "$BUILD_OUTPUT/ref" | ||
|
|
||
| # Collect files to compress | ||
| FILES_TO_COMPRESS=() | ||
| FILES_TO_COMPRESS+=("Microsoft.SqlServer.CSharpExtension.runtimeconfig.json") | ||
| FILES_TO_COMPRESS+=("Microsoft.SqlServer.CSharpExtension.deps.json") | ||
|
|
||
| # Add all .dll and .so files | ||
| for f in "$BUILD_OUTPUT"/*.dll "$BUILD_OUTPUT"/*.so; do | ||
| [ -e "$f" ] && FILES_TO_COMPRESS+=("$(basename "$f")") | ||
| done | ||
|
|
||
| # Include .pdb files for debug builds | ||
| if [ "$BUILD_CONFIGURATION" = "debug" ]; then | ||
| for f in "$BUILD_OUTPUT"/*.pdb; do | ||
| [ -e "$f" ] && FILES_TO_COMPRESS+=("$(basename "$f")") | ||
| done | ||
| fi | ||
|
|
||
| # Package the binaries | ||
| pushd "$BUILD_OUTPUT" > /dev/null | ||
| tar -czvf "$BUILD_OUTPUT/packages/dotnet-core-CSharp-lang-extension.tar.gz" "${FILES_TO_COMPRESS[@]}" | ||
| check_error $? "Failed to create tarball for dotnet-core-CSharp-extension for configuration=$BUILD_CONFIGURATION" | ||
| popd > /dev/null | ||
|
|
||
| echo "Success: Compressed dotnet-core-CSharp-extension for $BUILD_CONFIGURATION configuration." | ||
| done |
84 changes: 84 additions & 0 deletions
84
language-extensions/dotnet-core-CSharp/build/linux/restore-packages.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env bash | ||
| # Note: errexit (-e) is intentionally NOT set. Each significant command is | ||
| # followed by check_exit_code, which prints a descriptive message and exits | ||
| # with the failing command's status. Enabling -e would abort before those | ||
| # messages could be emitted, making failures harder to diagnose. | ||
| set -uo pipefail | ||
|
|
||
| check_exit_code() { | ||
|
SicongLiu2000 marked this conversation as resolved.
|
||
| local exit_code=$? | ||
| if [ ${exit_code} -eq 0 ]; then | ||
| echo "$1" | ||
| else | ||
| echo "$2" | ||
| exit ${exit_code} | ||
| fi | ||
| } | ||
|
|
||
| # Install .NET SDK 8.0 for building the C# extension managed code | ||
| # and for obtaining libnethost.a (used by the native host to discover hostfxr). | ||
| # | ||
|
|
||
| # Check if dotnet is already installed and is version 8.x | ||
| if command -v dotnet &>/dev/null && dotnet --version 2>/dev/null | grep -q "^8\."; then | ||
| echo "Info: .NET SDK 8.x already installed ($(dotnet --version))" | ||
| else | ||
| echo "Info: Installing .NET SDK 8.0..." | ||
| apt-get update | ||
| apt-get install -y --no-install-recommends wget apt-transport-https | ||
| wget https://dot.net/v1/dotnet-install.sh -O /tmp/dotnet-install.sh | ||
| chmod +x /tmp/dotnet-install.sh | ||
| /tmp/dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet | ||
| ln -sf /usr/share/dotnet/dotnet /usr/bin/dotnet | ||
| check_exit_code "Success: Installed .NET SDK 8.0" "Error: Failed to install .NET SDK 8.0" | ||
| fi | ||
|
|
||
| # Copy libnethost.a from the .NET SDK runtime packs into the extension's lib directory. | ||
| # The SDK ships this as part of the AppHost pack. | ||
| # | ||
| SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" | ||
| ENL_ROOT=${SCRIPTDIR}/../../../.. | ||
| DOTNET_EXTENSION_HOME=${ENL_ROOT}/language-extensions/dotnet-core-CSharp | ||
|
|
||
| NETHOST_DIR=$(find /usr/share/dotnet -path "*/runtimes/linux-x64/native/libnethost.a" -print -quit 2>/dev/null) | ||
| if [ -z "$NETHOST_DIR" ]; then | ||
| echo "Error: libnethost.a not found in .NET SDK. Ensure .NET SDK 8.0 is installed." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Info: Found libnethost.a at: $NETHOST_DIR" | ||
| mkdir -p "${DOTNET_EXTENSION_HOME}/lib" | ||
| cp "$NETHOST_DIR" "${DOTNET_EXTENSION_HOME}/lib/libnethost.a" | ||
| check_exit_code "Success: Copied libnethost.a to extension lib directory" "Error: Failed to copy libnethost.a" | ||
|
|
||
| # Pre-restore NuGet packages while network is still available. | ||
| # OneBranch enables network isolation after package-restore phases, | ||
| # so dotnet restore must happen here rather than during the build step. | ||
| # | ||
| # Use the parent repo's NuGet.Config which points to the ADO artifact feed | ||
| # (with nuget.org as upstream) rather than the submodule's NuGet.Config | ||
| # which points directly to nuget.org (unreachable from OneBranch containers). | ||
| # | ||
| MANAGED_PROJ="${DOTNET_EXTENSION_HOME}/src/managed/Microsoft.SqlServer.CSharpExtension.csproj" | ||
| MANAGED_TEST_PROJ="${DOTNET_EXTENSION_HOME}/test/src/managed/Microsoft.SqlServer.CSharpExtensionTest.csproj" | ||
| PARENT_NUGET_CONFIG="${ENL_ROOT}/../NuGet.Config" | ||
|
|
||
| echo "Info: Restoring NuGet packages for Microsoft.SqlServer.CSharpExtension..." | ||
| if [ -f "$PARENT_NUGET_CONFIG" ]; then | ||
| echo "Info: Using NuGet.Config from parent repo: $PARENT_NUGET_CONFIG" | ||
| dotnet restore "$MANAGED_PROJ" --configfile "$PARENT_NUGET_CONFIG" | ||
| check_exit_code "Success: NuGet packages restored (extension)" "Error: Failed to restore NuGet packages (extension)" | ||
|
|
||
| echo "Info: Restoring NuGet packages for Microsoft.SqlServer.CSharpExtensionTest..." | ||
| dotnet restore "$MANAGED_TEST_PROJ" --configfile "$PARENT_NUGET_CONFIG" | ||
| check_exit_code "Success: NuGet packages restored (test)" "Error: Failed to restore NuGet packages (test)" | ||
| else | ||
| echo "Info: Parent NuGet.Config not found, using default" | ||
| dotnet restore "$MANAGED_PROJ" | ||
| check_exit_code "Success: NuGet packages restored (extension)" "Error: Failed to restore NuGet packages (extension)" | ||
|
|
||
| dotnet restore "$MANAGED_TEST_PROJ" | ||
| check_exit_code "Success: NuGet packages restored (test)" "Error: Failed to restore NuGet packages (test)" | ||
| fi | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.