Skip to content
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

add gperftools package #4572

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions recipes/gperftools/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.8.1":
sha256: 12f07a8ba447f12a3ae15e6e3a6ad74de35163b787c0c7b76288d7395f2f74e0
url: https://github.com/gperftools/gperftools/releases/download/gperftools-2.8.1/gperftools-2.8.1.tar.gz
83 changes: 83 additions & 0 deletions recipes/gperftools/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from conans import ConanFile, AutoToolsBuildEnvironment, tools
from conans.errors import ConanInvalidConfiguration
import os


Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import os
import os
required_conan_version = ">=1.29.1"

class GperftoolsConan(ConanFile):
name = "gperftools"

description = "Google Performance Tools"
topics = ("conan", "gperftools", "tcmalloc", "cpu/heap profiler")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/gperftools/gperftools"
license = ["BSD-3-Clause License"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
license = ["BSD-3-Clause License"]
license = ["BSD-3-Clause"]

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def configure(self):
def configure(self):
if self.options.shared:
del self.options.fPIC

del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("gperftools is not supported by Visual Studio")
if self.settings.os == "Windows" and self.options.shared:
# libtool: error: can't build i686-pc-mingw32 shared library unless -no-undefined is specified
raise ConanInvalidConfiguration("gperftools can't be built as shared on Windows")
Comment on lines +37 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try with CMakeLists? It could avoid msys2 build requirement (autotools are slow as hell on windows) and allow to build with Visual Studio.


def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_folder = "gperftools-{0}".format(self.version)
os.rename(extracted_folder, self._source_subfolder)

def build_requirements(self):
if tools.os_info.is_windows and not os.environ.get("CONAN_BASH_PATH"):
self.build_requires("msys2/20190524")

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
args = []
if self.options.shared:
args.extend(['--disable-static', '--enable-shared'])
else:
args.extend(['--disable-shared', '--enable-static'])
self._autotools.configure(configure_dir=self._source_subfolder, args=args)
return self._autotools

def build(self):
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
autotools = self._configure_autotools()
autotools.install()

tools.rmdir(os.path.join(self.package_folder, 'share'))
tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig'))
os.unlink(os.path.join(self.package_folder, "lib", "libprofiler.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_and_profiler.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_debug.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_minimal.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_minimal_debug.la"))
Comment on lines +75 to +80
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
os.unlink(os.path.join(self.package_folder, "lib", "libprofiler.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_and_profiler.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_debug.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_minimal.la"))
os.unlink(os.path.join(self.package_folder, "lib", "libtcmalloc_minimal_debug.la"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")


def package_info(self):
self.cpp_info.libs = ["tcmalloc_and_profiler"]
8 changes: 8 additions & 0 deletions recipes/gperftools/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
17 changes: 17 additions & 0 deletions recipes/gperftools/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
13 changes: 13 additions & 0 deletions recipes/gperftools/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <assert.h>
#include <gperftools/tcmalloc.h>

int main()
{
void *p1 = tc_malloc(10);
assert(p1 != NULL);

tc_free(p1);

return 0;
}

3 changes: 3 additions & 0 deletions recipes/gperftools/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.8.1":
folder: all