Skip to content

Commit

Permalink
Fix linux build dependency of glibc
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Jul 3, 2024
1 parent 2b897d0 commit cb6b38d
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 102 deletions.
161 changes: 86 additions & 75 deletions .github/workflows/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,89 @@
---
name: Install Dependencies
description: Ensures an action has the appropiate non .NET dependencies installed

inputs:
rust:
description: 'Install rust toolchain ("true" or "false")'
required: false
default: "false"
azure:
description: 'Install azure functions tool chain ("true" or "false")'
required: false
default: "false"
tc-cloud:
description: 'Bootstrap TestContainers Cloud (TOKEN or "false")'
required: false
default: "false"

runs:
using: "composite"
steps:
# RUST
- name: Rustup
if: "${{ inputs.rust == 'true' }}"
shell: bash
run: rustup default 1.69.0

# - name: Cargo make
# if: "${{ inputs.rust == 'true' }}"
# shell: bash
# run: cargo install --force cargo-make

- name: Install cargo-make using cache
if: "${{ inputs.rust == 'true' }}"
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-make
version: "^0.36.8"

- uses: Swatinem/rust-cache@v2
if: "${{ inputs.rust == 'true' }}"
with:
cache-targets: "false"
cache-all-crates: "true"

name: Install Dependencies
description: Ensures an action has the appropiate non .NET dependencies installed

inputs:
rust:
description: 'Install rust toolchain ("true" or "false")'
required: false
default: "false"
azure:
description: 'Install azure functions tool chain ("true" or "false")'
required: false
default: "false"
tc-cloud:
description: 'Bootstrap TestContainers Cloud (TOKEN or "false")'
required: false
default: "false"

# AZURE
- name: 'Linux: Azure functions core tools'
if: "${{ inputs.azure == 'true' && runner.os == 'Linux' }}"
shell: bash
run: |
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
runs:
using: "composite"
steps:
# ZIG
- name: Zig
if: "${{ inputs.rust == 'true' && runner.os == 'Linux' }}"
shell: bash
run: sudo snap install zig --beta --classic

# RUST
- name: Rustup
if: "${{ inputs.rust == 'true' }}"
shell: bash
run: rustup default 1.79.0

# - name: Cargo make
# if: "${{ inputs.rust == 'true' }}"
# shell: bash
# run: cargo install --force cargo-make

- name: Install cargo-make using cache
if: "${{ inputs.rust == 'true' }}"
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-make
version: "^0.36.8"

- name: Install cargo zigbuild
if: "${{ inputs.rust == 'true' && runner.os == 'Linux' }}"
shell: bash
run: cargo install --force cargo-zigbuild

- uses: Swatinem/rust-cache@v2
if: "${{ inputs.rust == 'true' }}"
with:
cache-targets: "false"
cache-all-crates: "true"

# AZURE
- name: 'Linux: Azure functions core tools'
if: "${{ inputs.azure == 'true' && runner.os == 'Linux' }}"
shell: bash
run: |
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
- name: 'Windows: Azure functions core tools'
if: "${{ inputs.azure == 'true' && runner.os == 'Windows' }}"
shell: cmd
run: choco install azure-functions-core-tools -y --no-progress -r --version 4.0.4829

- name: 'Windows: Azure functions core tools'
if: "${{ inputs.azure == 'true' && runner.os == 'Windows' }}"
shell: cmd
run: choco install azure-functions-core-tools -y --no-progress -r --version 4.0.4829

# TEST CONTAINERS CLOUD
# If no PR event or if a PR event that's caused by a non-fork and non dependabot actor
- name: Setup TestContainers Cloud Client
if: |
inputs.tc-cloud != 'false'
&& (github.event_name != 'pull_request'
|| (github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.fork == false
&& github.actor != 'dependabot[bot]'
)
)
uses: atomicjar/testcontainers-cloud-setup-action@c335bdbb570ec7c48f72c7d450c077f0a002293e # v1.3.0
with:
token: ${{ inputs.tc-cloud }}



# TEST CONTAINERS CLOUD
# If no PR event or if a PR event that's caused by a non-fork and non dependabot actor
- name: Setup TestContainers Cloud Client
if: |
inputs.tc-cloud != 'false'
&& (github.event_name != 'pull_request'
|| (github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.fork == false
&& github.actor != 'dependabot[bot]'
)
)
uses: atomicjar/testcontainers-cloud-setup-action@c335bdbb570ec7c48f72c7d450c077f0a002293e # v1.3.0
with:
token: ${{ inputs.tc-cloud }}




12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ feedback and ideas are always welcome.
### .NET source

In order to build the .NET source code, you'll need
* [.NET 6.0 or later](https://dotnet.microsoft.com/download/dotnet/6.0)
* [.NET 8.0 or later](https://dotnet.microsoft.com/download/dotnet/8.0)
* **If** you're running on Windows **and** also wish to build projects that target .NET Framework,
you'll need a minimum of .NET Framework 4.6.1 installed.
you'll need a minimum of .NET Framework 4.6.2 installed.

You can use any IDE that supports .NET development, and you can use any OS that is supported by .NET.

### Rust source

In order to build the CLR profiler source code, you'll need
* [Rust 1.54 or later](https://www.rust-lang.org/tools/install)
In order to build the CLR profiler source code, you'll need:
* [Rust 1.79 or later](https://www.rust-lang.org/tools/install)
* [Cargo make](https://github.com/sagiegurari/cargo-make#installation)

On Linux, you will also require:
* [Cargo zigbuild](https://github.com/rust-cross/cargo-zigbuild)
* [Zig](https://github.com/ziglang/zig)

You can use any IDE that supports Rust development; we typically use [CLion](https://www.jetbrains.com/clion/)
with the [Rust plugin](https://plugins.jetbrains.com/plugin/8182-rust/docs),
or [VS Code](https://code.visualstudio.com/)
Expand Down
10 changes: 9 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ description = "Builds CLR Profiler for release"
# loader assembly is embedded in the profiler
dependencies = ["build-loader"]

[tasks.build-release-linux]
description = "Builds CLR Profiler for release against a known version of glibc"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
args = ["zigbuild", "--release", "--target", "x86_64-unknown-linux-gnu.2.14", "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )"]
# loader assembly is embedded in the profiler
dependencies = ["build-loader"]

[tasks.build-integrations]
description = "Builds Managed Profiler .NET integrations"
command = "dotnet"
Expand Down Expand Up @@ -83,7 +91,7 @@ cargo expand --manifest-path src/profiler/elastic_apm_profiler/Cargo.toml --colo

[tasks.set-profiler-env]
private = true
env = { "CORECLR_PROFILER_PATH" = "${CARGO_MAKE_WORKING_DIRECTORY}/target/release/libelastic_apm_profiler.so" }
env = { "CORECLR_PROFILER_PATH" = "${CARGO_MAKE_WORKING_DIRECTORY}/target/x86_64-unknown-linux-gnu/release/libelastic_apm_profiler.so" }

[tasks.set-profiler-env.mac]
env = { "CORECLR_PROFILER_PATH" = "${CARGO_MAKE_WORKING_DIRECTORY}/target/release/libelastic_apm_profiler.dylib" }
Expand Down
37 changes: 19 additions & 18 deletions build/scripts/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,20 @@ module Build =
@ ["--"; "RunConfiguration.CollectSourceInformation=true"]

DotNet.ExecWithTimeout command (TimeSpan.FromMinutes 30)



/// Builds the CLR profiler and supporting .NET managed assemblies
let BuildProfiler () =
dotnet "build" (Paths.ProfilerProjFile "Elastic.Apm.Profiler.Managed")
Cargo.Exec [ "make"; "build-release"; "--disable-check-for-update"]

if isWindows then Cargo.Exec [ "make"; "build-release"; "--disable-check-for-update"]
else Cargo.Exec [ "make"; "build-release-linux"; "--disable-check-for-update"]

/// Publishes all projects with framework versions
let Publish targets =
let Publish targets =
let projs =
match targets with
| Some t -> t
| None -> allSrcProjects

projs
|> Seq.map getAllTargetFrameworks
|> Seq.iter (fun (proj, frameworks) ->
Expand Down Expand Up @@ -290,7 +290,6 @@ module Build =
// include version in the zip file name
ZipFile.CreateFromDirectory(agentDir.FullName, Paths.BuildOutput versionedName + ".zip")


let ProfilerIntegrations () =
DotNet.Exec ["run"; "--project"; Paths.ProfilerProjFile "Elastic.Apm.Profiler.IntegrationsGenerator"; "--"
"-i"; Paths.SrcProfiler "Elastic.Apm.Profiler.Managed/bin/Release/netstandard2.0/Elastic.Apm.Profiler.Managed.dll"
Expand All @@ -299,20 +298,25 @@ module Build =
/// Creates versioned elastic_apm_profiler.zip file containing all components needed for profiler auto-instrumentation
let ProfilerZip () =
let name = "elastic_apm_profiler"
let directory = Paths.BuildOutput name

if Directory.Exists(directory) then
Directory.Delete(directory, true)

let currentAssemblyVersion = Versioning.CurrentVersion.FileVersion
let versionedName =
let os =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then "win-x64"
else "linux-x64"
else "linux-x64"
sprintf "%s_%s-%s" name (currentAssemblyVersion.ToString()) os

let profilerDir = Paths.BuildOutput name |> DirectoryInfo
let profilerDir = directory |> DirectoryInfo
profilerDir.Create()

seq {
Paths.SrcProfiler "Elastic.Apm.Profiler.Managed/integrations.yml"
"target/release/elastic_apm_profiler.dll"
"target/release/libelastic_apm_profiler.so"
"target/x86_64-unknown-linux-gnu/release/libelastic_apm_profiler.so"
Paths.SrcProfiler "elastic_apm_profiler/NOTICE"
Paths.SrcProfiler "elastic_apm_profiler/README"
"LICENSE"
Expand All @@ -321,12 +325,13 @@ module Build =
|> Seq.filter (fun file -> file.Exists)
|> Seq.iter (fun file ->
let destination = Path.combine profilerDir.FullName file.Name
let newFile = file.CopyTo(destination, true)
let newFile = file.CopyTo(destination, true)
if newFile.Name = "README" then
File.applyReplace (fun s -> s.Replace("${VERSION}", sprintf "%i.%i" currentAssemblyVersion.Major currentAssemblyVersion.Minor)) newFile.FullName
)

Directory.GetDirectories((Paths.BuildOutput "Elastic.Apm.Profiler.Managed"), "*", SearchOption.TopDirectoryOnly)
|> Array.filter (fun dir -> isWindows || not (dir.EndsWith("net462")))
|> Seq.map DirectoryInfo
|> Seq.iter (fun sourceDir -> copyDllsAndPdbs (profilerDir.CreateSubdirectory(sourceDir.Name)) sourceDir)

Expand All @@ -335,8 +340,4 @@ module Build =
if File.exists zip then
printf $"%s{zip} already exists on disk"
File.delete zip
ZipFile.CreateFromDirectory(profilerDir.FullName, zip)




ZipFile.CreateFromDirectory(profilerDir.FullName, zip)
8 changes: 6 additions & 2 deletions docs/setup-auto-instrumentation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This approach works with the following

|===
| 2.+^|**Operating system**
|**Architecture** |**Windows** |**Linux**
|**Architecture** |**Windows** |**Linux** **

|x64

Expand All @@ -33,7 +33,11 @@ This approach works with the following

_* Due to binding issues introduced by Microsoft, we recommend at least .NET Framework 4.7.2 for best compatibility._

NOTE: The Profiler based agent only supports 64-bit applications. 32-bit applications aren't supported.
_** Minimum GLIBC version 2.14._

NOTE: The profiler-based agent only supports 64-bit applications. 32-bit applications aren't supported.

NOTE: The profiler-based agent does not currently support ARM.

It instruments the following assemblies:

Expand Down
2 changes: 1 addition & 1 deletion src/profiler/elastic_apm_profiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ c_vec = "2.0.0"
com = { version = "0.6.0", features = ["production"] }
hex = "0.4.3"
log = "0.4.14"
log4rs = { version = "1.0.0", default_features = false, features = ["console_appender", "rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] }
log4rs = { version = "1.0.0", default-features = false, features = ["console_appender", "rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] }
num-derive = "0.3"
num-traits = "0.2"
once_cell = "1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ protected ProfiledApplication(string projectName, params string[] folders)
else
profilerFile = "libelastic_apm_profiler.dylib";

_profilerPath = Path.Combine(SolutionPaths.Root, "target", "release", profilerFile);
_profilerPath = TestEnvironment.IsLinux ?
Path.Combine(SolutionPaths.Root, "target", "x86_64-unknown-linux-gnu/release", "release", profilerFile) :
Path.Combine(SolutionPaths.Root, "target", "release", profilerFile);

if (!File.Exists(_profilerPath))
{
Expand Down

0 comments on commit cb6b38d

Please sign in to comment.