Skip to content

Commit

Permalink
add support on osx (#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotibou authored Apr 21, 2022
1 parent a5656c4 commit 39c5773
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ tracer/src/Datadog.Trace.ClrProfiler.Native/Makefile
tracer/src/Datadog.Trace.ClrProfiler.Native/CMakeCache.txt
tracer/src/Datadog.Trace.ClrProfiler.Native/cmake_install.cmake
!tracer/src/Datadog.Trace.ClrProfiler.Native/lib/**
tracer/src/Datadog.AutoInstrumentation.NativeLoader/build/
tracer/src/Datadog.AutoInstrumentation.NativeLoader/deps/
tracer/src/Datadog.AutoInstrumentation.NativeLoader/CMakeFiles/
tracer/src/Datadog.AutoInstrumentation.NativeLoader/tmp.*
tracer/src/Datadog.AutoInstrumentation.NativeLoader/Makefile
tracer/src/Datadog.AutoInstrumentation.NativeLoader/CMakeCache.txt
tracer/src/Datadog.AutoInstrumentation.NativeLoader/cmake_install.cmake
tracer/src/Datadog.AutoInstrumentation.NativeLoader/cmake-build-debug/
!tracer/src/Datadog.AutoInstrumentation.NativeLoader/lib/**
profiler/_build/

.ionide/
Expand Down
5 changes: 4 additions & 1 deletion tracer/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ You can use Rider and CLion to develop on macOS. Building and testing can be don
.\build.sh PackageTracerHome

# Build and run integration tests. Requires BuildTracerHome to have previously been run
.\build.sh BuildAndRunIntegrationTests
.\build.sh BuildAndRunLinuxIntegrationTests

# Build and run integration tests filtering on one framework, one set of tests and a sample app.
.\build.sh BuildAndRunLinuxIntegrationTests --framework "net6.0" --filter "rabbit" --SampleName "Samples.Rabbit"
```

## Additional Technical Documentation
Expand Down
36 changes: 34 additions & 2 deletions tracer/build/_build/Build.Shared.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ partial class Build
.Unlisted()
.Description("Compiles the native loader")
.DependsOn(CompileNativeLoaderWindows)
.DependsOn(CompileNativeLoaderLinux);
.DependsOn(CompileNativeLoaderLinux)
.DependsOn(CompileNativeLoaderOsx);

Target CompileNativeLoaderWindows => _ => _
.Unlisted()
Expand Down Expand Up @@ -53,10 +54,22 @@ partial class Build
Make.Value(workingDirectory: buildDirectory);
});

Target CompileNativeLoaderOsx => _ => _
.Unlisted()
.After(CompileProfilerManagedSrc)
.OnlyWhenStatic(() => IsOsx)
.Executes(() =>
{
var buildDirectory = NativeLoaderProject.Directory;
CMake.Value(arguments: ".", workingDirectory: buildDirectory);
Make.Value(workingDirectory: buildDirectory);
});

Target PublishNativeLoader => _ => _
.Unlisted()
.DependsOn(PublishNativeLoaderWindows)
.DependsOn(PublishNativeLoaderLinux);
.DependsOn(PublishNativeLoaderLinux)
.DependsOn(PublishNativeLoaderOsx);

Target PublishNativeLoaderWindows => _ => _
.Unlisted()
Expand Down Expand Up @@ -113,4 +126,23 @@ partial class Build
CopyFileToDirectory(source, dest, FileExistsPolicy.Overwrite);
});

Target PublishNativeLoaderOsx=> _ => _
.Unlisted()
.OnlyWhenStatic(() => IsOsx)
.After(CompileNativeLoader)
.Executes(() =>
{
// Copy native loader assets
var source = NativeLoaderProject.Directory / "bin" / "loader.conf";
var dest = MonitoringHomeDirectory;
Logger.Info($"Copying '{source}' to '{dest}'");
CopyFileToDirectory(source, dest, FileExistsPolicy.Overwrite);
source = NativeLoaderProject.Directory / "bin" /
$"{NativeLoaderProject.Name}.dylib";
dest = MonitoringHomeDirectory;
Logger.Info($"Copying file '{source}' to 'file {dest}'");
CopyFileToDirectory(source, dest, FileExistsPolicy.Overwrite);
});

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ add_library("Datadog.AutoInstrumentation.NativeLoader" SHARED
dllmain.cpp
dynamic_dispatcher.cpp
dynamic_instance.cpp
runtimeid_store.cpp
${DOTNET_TRACER_REPO_ROOT_PATH}/shared/src/native-src/miniutf.cpp
${DOTNET_TRACER_REPO_ROOT_PATH}/shared/src/native-lib/coreclr/src/pal/prebuilt/idl/corprof_i.cpp
${DOTNET_TRACER_REPO_ROOT_PATH}/shared/src/native-src/string.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,14 +643,14 @@ namespace datadog::shared::nativeloader
RunInAllProfilers(ExceptionSearchCatcherFound(functionId));
}

HRESULT STDMETHODCALLTYPE CorProfiler::ExceptionOSHandlerEnter(UINT_PTR __unused)
HRESULT STDMETHODCALLTYPE CorProfiler::ExceptionOSHandlerEnter(UINT_PTR unused_variable)
{
RunInAllProfilers(ExceptionOSHandlerEnter(__unused));
RunInAllProfilers(ExceptionOSHandlerEnter(unused_variable));
}

HRESULT STDMETHODCALLTYPE CorProfiler::ExceptionOSHandlerLeave(UINT_PTR __unused)
HRESULT STDMETHODCALLTYPE CorProfiler::ExceptionOSHandlerLeave(UINT_PTR unused_variable)
{
RunInAllProfilers(ExceptionOSHandlerLeave(__unused));
RunInAllProfilers(ExceptionOSHandlerLeave(unused_variable));
}

HRESULT STDMETHODCALLTYPE CorProfiler::ExceptionUnwindFunctionEnter(FunctionID functionId)
Expand Down
2 changes: 1 addition & 1 deletion tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static string GetNativeLoaderPath()
("win", "X86") => "Datadog.AutoInstrumentation.NativeLoader.x86.dll",
("linux", "X64") => "Datadog.AutoInstrumentation.NativeLoader.so",
("linux", "Arm64") => "Datadog.AutoInstrumentation.NativeLoader.so",
("osx", _) => throw new PlatformNotSupportedException("The Native Loader is not yet supported on osx"),
("osx", _) => "Datadog.AutoInstrumentation.NativeLoader.dylib",
_ => throw new PlatformNotSupportedException()
};

Expand Down

0 comments on commit 39c5773

Please sign in to comment.