Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions intel/libipt/v2.0.1/libipt_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import (
"os"
"path/filepath"
"slices"
"strings"
)

const consumerSource = `#include <intel-pt.h>

int main() {
pt_config cfg;
pt_config_init(&cfg);
return 0;
}
`

id "intel/libipt"

fromVer "v2.0.1"

defaults {
"shared": "OFF",
"fPIC": "ON",
}

filter => {
for name, values in target.options {
if name != "shared" && name != "fPIC" {
return false
}
for value in values {
if value != "ON" && value != "OFF" {
return false
}
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir
shared := slices.contains(target.options["shared"], "ON")
fPIC := slices.contains(target.options["fPIC"], "ON")

c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_INSTALL_LIBDIR", "lib"
c.defineBool "BUILD_SHARED_LIBS", shared
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.configure
c.build
c.install

licenseDir := filepath.join(installDir, "licenses")
os.mkdirAll(licenseDir, 0o755)!
os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0o644)!

metadata := []string{
"-I" + filepath.join(installDir, "include"),
"-L" + filepath.join(installDir, "lib"),
"-lipt",
}
ctx.setMetadata strings.join(metadata, " ")
}

onTest ctx => {
installDir := ctx.outputDir
testDir := filepath.join(ctx.SourceDir, "_llar_consumer")
os.mkdirAll(testDir, 0o755)!

sourcePath := filepath.join(testDir, "consumer.cpp")
os.writeFile(sourcePath, []byte(consumerSource), 0o644)!
binary := filepath.join(testDir, "consumer")
args := []string{
"-std=c++11",
"-I" + filepath.join(installDir, "include"),
sourcePath,
"-L" + filepath.join(installDir, "lib"),
"-lipt",
"-o", binary,
}
exec "c++", args...
lastErr!

if slices.contains(target.options["shared"], "ON") {
os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.setenv overwrites LD_LIBRARY_PATH/DYLD_LIBRARY_PATH rather than prepending to any existing value. If the test environment already relies on these paths (e.g. for the C++ runtime or another dependency), overwriting them could break loader resolution for the consumer binary. Prepending the install lib dir to the existing value is the safer idiom, e.g. os.getenv("LD_LIBRARY_PATH") joined with :. Low severity, but worth considering.

}
exec binary
lastErr!
}
4 changes: 4 additions & 0 deletions intel/libipt/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "intel/libipt",
"deps": {}
}
Loading