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 libsafec/3.6.0 #4434

Merged
merged 24 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2055c9a
Add safeclib/3.6.0
klimkin Jan 31, 2021
47ae028
Use tools.remove_files_by_mask
klimkin Jan 31, 2021
623f56b
Use libsafec for alignment with existing distribution packages
klimkin Jan 31, 2021
fa0d020
Fail test_package if not working constraint handler
klimkin Jan 31, 2021
1c1701b
Fix licenses
klimkin Jan 31, 2021
786731a
Remove "make check" due to build complaints for test sources
klimkin Jan 31, 2021
3b4d9ab
Strip too explicit version from resulting library file name
klimkin Feb 1, 2021
8e6458d
Limit recipe GCC version to >= 5
klimkin Feb 1, 2021
23d084b
Update recipes/libsafec/all/conanfile.py
klimkin Feb 1, 2021
61e22f2
Disable Werror to allow warnings
klimkin Feb 1, 2021
d68956c
Avoid extra patching, use version in the library name
klimkin Feb 1, 2021
824c37d
Fix exported includedirs to match original pkg-config package
klimkin Feb 1, 2021
a58d400
Update recipes/libsafec/all/test_package/conanfile.py
klimkin Feb 1, 2021
50d4f5f
Update recipes/libsafec/all/conanfile.py
klimkin Feb 1, 2021
1d736c8
Fix includedirs.append
klimkin Feb 1, 2021
6ef5574
Isolate autotools.configure for better --keep-build support
klimkin Feb 1, 2021
178a6bf
Add explicit name for pkg_config
klimkin Feb 1, 2021
4851818
Minor name fix
klimkin Feb 1, 2021
cb9a215
Keep autoreconf in build method
klimkin Feb 2, 2021
dfda98c
Enforce standard compatibility for exported include path
klimkin Feb 5, 2021
97fa103
Revert "Enforce standard compatibility for exported include path"
klimkin Feb 5, 2021
b65111d
Disable build for apply-clang with libc++
klimkin Feb 7, 2021
9eb7d10
Revert "Disable build for apply-clang with libc++"
klimkin Feb 7, 2021
dbe22de
Update recipes/libsafec/all/conanfile.py
klimkin Feb 8, 2021
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
8 changes: 8 additions & 0 deletions recipes/libsafec/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"3.6.0":
url: "https://github.com/rurban/safeclib/archive/v3.6.tar.gz"
sha256: "bd99d4555030719a83807649b3749bc483143b3548278daaa0a4af0fed5dc4de"
patches:
"3.6.0":
- patch_file: "patches/fix-ndebug-redifinition.patch"
base_path: "source_subfolder"
93 changes: 93 additions & 0 deletions recipes/libsafec/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import glob
import os

from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
klimkin marked this conversation as resolved.
Show resolved Hide resolved


class LibSafeCConan(ConanFile):
name = "libsafec"
description = "This library implements the secure C11 Annex K[^5] functions" \
" on top of most libc implementations, which are missing from them."
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/rurban/safeclib"
license = "MIT"
topics = ("conan", "safec", "libc")

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

build_requires = "autoconf/2.69", "libtool/2.4.6"
exports_sources = "patches/*"

__autotools = None
_source_subfolder = "source_subfolder"

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

@property
def _supported_compiler(self):
compiler = self.settings.compiler
version = tools.Version(self.settings.compiler.version)
if compiler == "Visual Studio":
return False
if compiler == "gcc" and version < "5":
return False
return True

def configure(self):
if not self._supported_compiler:
raise ConanInvalidConfiguration(
"libsafec doesn't support compiler: {} on OS: {}.".format(
self.settings.compiler, self.settings.os))
klimkin marked this conversation as resolved.
Show resolved Hide resolved
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = glob.glob("safeclib-*")[0]
os.rename(extracted_dir, self._source_subfolder)

@property
def _autotools(self):
if self.__autotools:
return self.__autotools
self.run("autoreconf -fiv", run_environment=True)
klimkin marked this conversation as resolved.
Show resolved Hide resolved
self.__autotools = AutoToolsBuildEnvironment(self)
if self.options.shared:
args = ["--enable-shared", "--disable-static"]
else:
args = ["--disable-shared", "--enable-static"]
args.extend(["--disable-doc", "--disable-dependency-tracking"])
if self.settings.build_type in ("Debug", "RelWithDebInfo"):
args.append("--enable-debug")
self.__autotools.configure(args=args)
return self.__autotools

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "Makefile.am"), "_@SAFEC_API_VERSION@", "")
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "Makefile.am"), "-@SAFEC_API_VERSION@", "")
tools.replace_in_file(os.path.join(self._source_subfolder, "tests", "Makefile.am"), "-@SAFEC_API_VERSION@", "")
klimkin marked this conversation as resolved.
Show resolved Hide resolved
with tools.chdir(self._source_subfolder):
self._autotools.make()

def package(self):
with tools.chdir(self._source_subfolder):
self._autotools.install()
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
with tools.chdir(os.path.join(self.package_folder, "lib")):
tools.rmdir("pkgconfig")
tools.remove_files_by_mask(".", "*.la")

def package_info(self):
klimkin marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.libs = ["safec"]
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
15 changes: 15 additions & 0 deletions recipes/libsafec/all/patches/fix-ndebug-redifinition.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/safeclib_private.h b/src/safeclib_private.h
index 2974d5c9..a60a2016 100644
--- a/src/safeclib_private.h
+++ b/src/safeclib_private.h
@@ -35,8 +35,10 @@
#define __SAFECLIB_PRIVATE_H__

#ifndef DEBUG
+#ifndef NDEBUG
#define NDEBUG
#endif
+#endif
klimkin marked this conversation as resolved.
Show resolved Hide resolved

#include "config.h"

8 changes: 8 additions & 0 deletions recipes/libsafec/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 C)

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

add_executable(test_package test_package.c)
target_link_libraries(test_package ${CONAN_LIBS})
19 changes: 19 additions & 0 deletions recipes/libsafec/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conans import CMake, ConanFile, tools


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 tools.cross_building(self.settings):
return
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
klimkin marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions recipes/libsafec/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <libsafec/safe_str_lib.h>
#include <stdlib.h>

void
constraint_handler(const char* msg, void* ptr, errno_t error)
{
printf("Constraint handler: %s\n", msg);
printf("Success!\n");
exit(0);
}

int
main(int argc, char** argv)
{
char dst[2];

set_str_constraint_handler_s(constraint_handler);

strcpy_s(dst, sizeof dst, "Too long!");
printf("Fail!\n");

return 1;
}
3 changes: 3 additions & 0 deletions recipes/libsafec/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.6.0":
folder: all