Repository navigation
feat(build): add release debuginfo profile #333
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dbca4e9
feat(build): add release debuginfo profile
vikrantpuppala 5354ce4
fix(ci): read macOS source from DWARF DIE
vikrantpuppala 8cf3ad8
fix(c-abi): use pointer-first Windows function cast
vikrantpuppala 84511e5
fix(ci): parse uncolored Windows linker args
vikrantpuppala ae7cb5c
fix(ci): avoid PowerShell profile shadowing
vikrantpuppala 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # Copyright (c) 2026 Databricks, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| function Invoke-Checked { | ||
| param( | ||
| [Parameter(Mandatory = $true)][string]$FilePath, | ||
| [Parameter(Mandatory = $false)][AllowEmptyCollection()][string[]]$Arguments = @() | ||
| ) | ||
|
|
||
| & $FilePath @Arguments | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "command failed with exit code ${LASTEXITCODE}: $FilePath $($Arguments -join ' ')" | ||
| } | ||
| } | ||
|
|
||
| function Find-AsciiMatch { | ||
| param( | ||
| [Parameter(Mandatory = $true)][string]$Path, | ||
| [Parameter(Mandatory = $true)][regex]$Pattern | ||
| ) | ||
|
|
||
| $buffer = [byte[]]::new(65536) | ||
| $tail = "" | ||
| $stream = [System.IO.File]::OpenRead($Path) | ||
| try { | ||
| while (($bytesRead = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { | ||
| $chunk = $tail + [System.Text.Encoding]::ASCII.GetString($buffer, 0, $bytesRead) | ||
| $match = $Pattern.Match($chunk) | ||
| if ($match.Success) { | ||
| return $match.Value | ||
| } | ||
| $tailLength = [Math]::Min(1024, $chunk.Length) | ||
| $tail = $chunk.Substring($chunk.Length - $tailLength) | ||
| } | ||
| } finally { | ||
| $stream.Dispose() | ||
| } | ||
| return $null | ||
| } | ||
|
|
||
| $profileName = "release-with-debuginfo" | ||
| $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "../..")).Path | ||
| $targetRoot = if ($env:CARGO_TARGET_DIR) { | ||
| [System.IO.Path]::GetFullPath($env:CARGO_TARGET_DIR, $repoRoot) | ||
| } else { | ||
| Join-Path $repoRoot "target" | ||
| } | ||
| $profileDir = Join-Path $targetRoot $profileName | ||
| $source = Join-Path $repoRoot "tests/symbols/staticlib_consumer.c" | ||
| $includeDir = Join-Path $repoRoot "include" | ||
| $archive = Join-Path $profileDir "databricks_sql_kernel.lib" | ||
| $object = Join-Path $profileDir "staticlib_consumer.obj" | ||
| $executable = Join-Path $profileDir "kernel-symbol-smoke.exe" | ||
| $pdb = Join-Path $profileDir "kernel-symbol-smoke.pdb" | ||
|
|
||
| New-Item -ItemType Directory -Force -Path $profileDir | Out-Null | ||
| Push-Location $repoRoot | ||
| try { | ||
| # Build the exact static archive under test and capture the MSVC system | ||
| # libraries that rustc says its final native linker must receive. | ||
| # The toolchain action enables color globally; disable it here so ANSI reset | ||
| # bytes cannot become part of the parsed final library argument. | ||
| $env:CARGO_TERM_COLOR = "never" | ||
| $buildLines = @(& cargo rustc --locked --profile $profileName --lib -- --print=native-static-libs 2>&1) | ||
| $buildExit = $LASTEXITCODE | ||
| $buildLines | ForEach-Object { Write-Host $_ } | ||
| if ($buildExit -ne 0) { | ||
| throw "cargo rustc failed with exit code $buildExit" | ||
| } | ||
| if (-not (Test-Path -LiteralPath $archive -PathType Leaf)) { | ||
| throw "Cargo did not produce $archive" | ||
| } | ||
|
|
||
| $nativeLine = $buildLines | | ||
| ForEach-Object { "$_" } | | ||
| Where-Object { $_ -match "native-static-libs:\s*(.+)$" } | | ||
| Select-Object -Last 1 | ||
| if (-not $nativeLine) { | ||
| throw "rustc did not report native-static-libs" | ||
| } | ||
| $nativeText = ([regex]::Match($nativeLine, "native-static-libs:\s*(.+)$")).Groups[1].Value.Trim() | ||
| $nativeLinkArgs = @($nativeText -split "\s+" | Where-Object { $_ }) | ||
|
|
||
| Invoke-Checked "cl.exe" @( | ||
| "/nologo", "/c", "/O2", "/MD", "/Z7", "/I$includeDir", $source, "/Fo$object" | ||
| ) | ||
| $linkArgs = @( | ||
| "/NOLOGO", "/DEBUG:FULL", "/OPT:REF", "/OPT:ICF", "/INCREMENTAL:NO", | ||
| "/PDB:$pdb", "/PDBALTPATH:%_PDB%", "/OUT:$executable", | ||
| $object, $archive | ||
| ) + $nativeLinkArgs | ||
| Invoke-Checked "link.exe" $linkArgs | ||
| if (-not (Test-Path -LiteralPath $pdb -PathType Leaf)) { | ||
| throw "link.exe did not produce $pdb" | ||
| } | ||
| Invoke-Checked $executable @() | ||
|
|
||
| if (-not (Get-Command "dumpbin.exe" -ErrorAction SilentlyContinue)) { | ||
| throw "dumpbin.exe is required to validate the executable/PDB CodeView identity" | ||
| } | ||
|
|
||
| $functionPattern = [regex]::new("kernel_get_last_error") | ||
| $sourcePattern = [regex]::new("(?i)src[\\/]c_abi[\\/]error\.rs") | ||
| if (-not (Find-AsciiMatch $pdb $functionPattern)) { | ||
| throw "PDB does not describe kernel_get_last_error" | ||
| } | ||
| if (-not (Find-AsciiMatch $pdb $sourcePattern)) { | ||
| throw "PDB does not name src/c_abi/error.rs" | ||
| } | ||
|
|
||
| # The PE carries only the CodeView locator/identity; source and function | ||
| # records stay in the separately published PDB. In an isolated directory, | ||
| # dumpbin reports the adjacent PDB only when its GUID and age match the PE. | ||
| $checkDir = Join-Path ([System.IO.Path]::GetTempPath()) ("kernel-pdb-check-" + [guid]::NewGuid().ToString("N")) | ||
| New-Item -ItemType Directory -Path $checkDir | Out-Null | ||
| try { | ||
| $checkExe = Join-Path $checkDir (Split-Path -Leaf $executable) | ||
| $checkPdb = Join-Path $checkDir (Split-Path -Leaf $pdb) | ||
| Copy-Item -LiteralPath $executable -Destination $checkExe | ||
| Copy-Item -LiteralPath $pdb -Destination $checkPdb | ||
|
|
||
| $lookup = @(& dumpbin.exe /NOLOGO /PDBPATH $checkExe 2>&1) | ||
| $lookupExit = $LASTEXITCODE | ||
| $lookupText = $lookup | Out-String | ||
| Write-Host $lookupText | ||
| if ($lookupExit -ne 0) { | ||
| throw "dumpbin /PDBPATH failed with exit code $lookupExit" | ||
| } | ||
| if ($lookupText -notmatch [regex]::Escape($checkPdb)) { | ||
| throw "dumpbin did not resolve the supplied PDB; its GUID/age may not match the executable" | ||
| } | ||
| } finally { | ||
| Remove-Item -LiteralPath $checkDir -Recurse -Force -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| Write-Host "ok: Windows PDB contains kernel Rust source/function info" | ||
| Write-Host "ok: dumpbin validated the executable/PDB CodeView GUID and age" | ||
| } finally { | ||
| Pop-Location | ||
| } | ||
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,164 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright (c) 2026 Databricks, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| readonly PROFILE="release-with-debuginfo" | ||
| readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| readonly REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" | ||
| readonly TARGET_ROOT="${CARGO_TARGET_DIR:-${REPO_ROOT}/target}" | ||
| readonly PROFILE_DIR="${TARGET_ROOT}/${PROFILE}" | ||
| readonly CONSUMER_SOURCE="${REPO_ROOT}/tests/symbols/staticlib_consumer.c" | ||
| readonly ARCHIVE="${PROFILE_DIR}/libdatabricks_sql_kernel.a" | ||
| readonly CONSUMER="${PROFILE_DIR}/kernel-symbol-smoke" | ||
|
|
||
| for command in cargo cc; do | ||
| if ! command -v "${command}" >/dev/null 2>&1; then | ||
| echo "FAIL: required command not found: ${command}" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| mkdir -p "${PROFILE_DIR}" | ||
| build_log="$(mktemp)" | ||
| trap 'rm -f "${build_log}"' EXIT | ||
|
|
||
| # Cargo prints the platform libraries a C/C++ final linker must add when it | ||
| # consumes this staticlib. Capture that list while building the exact archive | ||
| # under test. | ||
| CARGO_TERM_COLOR=never cargo rustc --locked --profile "${PROFILE}" --lib -- \ | ||
| --print=native-static-libs 2>&1 | tee "${build_log}" | ||
|
|
||
| if [[ ! -f "${ARCHIVE}" ]]; then | ||
| echo "FAIL: Cargo did not produce ${ARCHIVE}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| native_link_line="$(sed -n 's/^note: native-static-libs: //p' "${build_log}" | tail -n 1)" | ||
| if [[ -z "${native_link_line}" ]]; then | ||
| echo "FAIL: rustc did not report native-static-libs" >&2 | ||
| exit 1 | ||
| fi | ||
| read -r -a native_link_args <<<"${native_link_line}" | ||
|
|
||
| case "$(uname -s)" in | ||
| Linux) | ||
| for command in objcopy readelf; do | ||
| if ! command -v "${command}" >/dev/null 2>&1; then | ||
| echo "FAIL: required command not found: ${command}" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| debug_file="${CONSUMER}.debug" | ||
| cc -O2 -I "${REPO_ROOT}/include" "${CONSUMER_SOURCE}" "${ARCHIVE}" \ | ||
| "${native_link_args[@]}" -Wl,--build-id=sha1 -o "${CONSUMER}" | ||
| "${CONSUMER}" | ||
|
|
||
| # This mirrors consumer packaging: retain full DWARF in the private symbol | ||
| # artifact, strip it from the customer executable, and leave only the GNU | ||
| # debug-link locator/checksum in the shipped file. | ||
| objcopy --only-keep-debug "${CONSUMER}" "${debug_file}" | ||
| objcopy --strip-debug "${CONSUMER}" | ||
| objcopy --add-gnu-debuglink="${debug_file}" "${CONSUMER}" | ||
|
|
||
| if readelf --sections "${CONSUMER}" | \ | ||
| grep -E '\.debug_(abbrev|info|line|str)' >/dev/null; then | ||
| echo "FAIL: customer executable still contains DWARF sections" >&2 | ||
| exit 1 | ||
| fi | ||
| if ! readelf --sections "${CONSUMER}" | grep -F '.gnu_debuglink' >/dev/null; then | ||
| echo "FAIL: customer executable has no .gnu_debuglink" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| dwarf_dump="${PROFILE_DIR}/kernel-symbol-smoke.dwarf.txt" | ||
| line_dump="${PROFILE_DIR}/kernel-symbol-smoke.lines.txt" | ||
| readelf --debug-dump=info "${debug_file}" >"${dwarf_dump}" | ||
| readelf --debug-dump=decodedline "${debug_file}" >"${line_dump}" | ||
| if ! grep -Fq 'kernel_get_last_error' "${dwarf_dump}"; then | ||
| echo "FAIL: split DWARF does not describe kernel_get_last_error" >&2 | ||
| exit 1 | ||
| fi | ||
| if ! grep -Fq 'src/c_abi/error.rs' "${line_dump}"; then | ||
| echo "FAIL: split DWARF does not name src/c_abi/error.rs" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| binary_notes="$(readelf --notes "${CONSUMER}")" | ||
| debug_notes="$(readelf --notes "${debug_file}")" | ||
| binary_id="$(sed -n 's/.*Build ID: //p' <<<"${binary_notes}")" | ||
| debug_id="$(sed -n 's/.*Build ID: //p' <<<"${debug_notes}")" | ||
| if [[ -z "${binary_id}" || "${binary_id}" != "${debug_id}" ]]; then | ||
| echo "FAIL: executable and split DWARF build IDs do not match" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "ok: Linux split DWARF contains kernel Rust source/function info" | ||
| echo "ok: executable and .debug share build ID ${binary_id}" | ||
| ;; | ||
| Darwin) | ||
| for command in dsymutil otool strip xcrun; do | ||
| if ! command -v "${command}" >/dev/null 2>&1; then | ||
| echo "FAIL: required command not found: ${command}" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| dsym="${CONSUMER}.dSYM" | ||
| cc -O2 -I "${REPO_ROOT}/include" "${CONSUMER_SOURCE}" "${ARCHIVE}" \ | ||
| "${native_link_args[@]}" -o "${CONSUMER}" | ||
| "${CONSUMER}" | ||
| dsymutil "${CONSUMER}" -o "${dsym}" | ||
| strip -S "${CONSUMER}" | ||
|
|
||
| if otool -l "${CONSUMER}" | grep -F '__DWARF' >/dev/null; then | ||
| echo "FAIL: customer executable still contains a __DWARF segment" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| dwarf_dump="${PROFILE_DIR}/kernel-symbol-smoke.dwarf.txt" | ||
| dwarf_file="${dsym}/Contents/Resources/DWARF/$(basename "${CONSUMER}")" | ||
| if [[ ! -f "${dwarf_file}" ]]; then | ||
| echo "FAIL: dsymutil did not produce ${dwarf_file}" >&2 | ||
| exit 1 | ||
| fi | ||
| xcrun dwarfdump --name kernel_get_last_error "${dsym}" >"${dwarf_dump}" | ||
| if ! grep -Fq 'kernel_get_last_error' "${dwarf_dump}"; then | ||
| echo "FAIL: dSYM does not describe kernel_get_last_error" >&2 | ||
| exit 1 | ||
| fi | ||
| if ! grep -Eq 'DW_AT_decl_file.*error\.rs' "${dwarf_dump}"; then | ||
| echo "FAIL: kernel_get_last_error has no error.rs source record in the dSYM" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| binary_uuid_dump="$(xcrun dwarfdump --uuid "${CONSUMER}")" | ||
| dsym_uuid_dump="$(xcrun dwarfdump --uuid "${dsym}")" | ||
| binary_uuid="$(awk 'NR == 1 { print $2 }' <<<"${binary_uuid_dump}")" | ||
| dsym_uuid="$(awk 'NR == 1 { print $2 }' <<<"${dsym_uuid_dump}")" | ||
| if [[ -z "${binary_uuid}" || "${binary_uuid}" != "${dsym_uuid}" ]]; then | ||
| echo "FAIL: executable and dSYM UUIDs do not match" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "ok: macOS dSYM contains kernel Rust source/function info" | ||
| echo "ok: executable and dSYM share UUID ${binary_uuid}" | ||
| ;; | ||
| *) | ||
| echo "FAIL: unsupported platform for this check: $(uname -s)" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac |
Oops, something went wrong.
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.