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

libsass: add mingw support and pure C consumer + del fPIC if shared + early checks in configure() + explicit pkg_config name #4240

Merged
merged 8 commits into from
Jan 14, 2021
Merged
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
78 changes: 68 additions & 10 deletions recipes/libsass/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.29.1"


class LibsassConan(ConanFile):
name = "libsass"
Expand All @@ -14,17 +16,31 @@ class LibsassConan(ConanFile):
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

build_requires = "autoconf/2.69", "libtool/2.4.6"

_autotools = None

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

def validate(self):
if self.settings.os not in ["Linux", "FreeBSD", "Macos"]:
raise ConanInvalidConfiguration("libsass supports only Linux, FreeBSD and Macos")
@property
def _is_mingw(self):
return self.settings.os == "Windows" and self.settings.compiler == "gcc"

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

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler == "Visual Studio":
# TODO: add Visual Studio support
raise ConanInvalidConfiguration("Visual Studio not yet supported in libsass recipe")

def build_requirements(self):
if self.settings.os != "Windows":
self.build_requires("autoconf/2.69")
self.build_requires("libtool/2.4.6")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
Expand All @@ -34,7 +50,6 @@ def source(self):
def _configure_autotools(self):
if self._autotools:
return self._autotools
self.run("autoreconf -fiv", run_environment=True)
self._autotools = AutoToolsBuildEnvironment(self)
args = []
args.append("--disable-tests")
Expand All @@ -43,21 +58,64 @@ def _configure_autotools(self):
self._autotools.configure(args=args)
return self._autotools

def build(self):
def _build_autotools(self):
with tools.chdir(self._source_subfolder):
tools.save(path="VERSION", content="%s" % self.version)
self.run("{} -fiv".format(tools.get_env("AUTORECONF")))
autotools = self._configure_autotools()
autotools.make()

def package(self):
@property
def _make_program(self):
return tools.get_env("CONAN_MAKE_PROGRAM", tools.which("make") or tools.which("mingw32-make"))

def _build_mingw(self):
makefile = os.path.join(self._source_subfolder, "Makefile")
tools.replace_in_file(makefile, "CFLAGS += -O2", "")
tools.replace_in_file(makefile, "CXXFLAGS += -O2", "")
tools.replace_in_file(makefile, "LDFLAGS += -O2", "")
with tools.chdir(self._source_subfolder):
env_vars = AutoToolsBuildEnvironment(self).vars
env_vars.update({
"BUILD": "shared" if self.options.shared else "static",
"PREFIX": tools.unix_path(os.path.join(self.package_folder)),
# Don't force static link to mingw libs, leave this decision to consumer (through LDFLAGS in env)
"STATIC_ALL": "0",
"STATIC_LIBGCC": "0",
"STATIC_LIBSTDCPP": "0",
})
with tools.environment_append(env_vars):
self.run("{} -f Makefile".format(self._make_program))

def build(self):
if self._is_mingw:
self._build_mingw()
else:
self._build_autotools()

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

def _install_mingw(self):
self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
Copy link
Contributor

Choose a reason for hiding this comment

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

so, make install doesn't work for MinGW?

Copy link
Contributor Author

@SpaceIm SpaceIm Jan 13, 2021

Choose a reason for hiding this comment

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

Generally speaking, it should work, but install target calls something that didn't work on my computer (maybe a shell, so it can't work without msys2, not sure). Moreover it installs runtime in lib folder, so it's just easier to manually copy these files.

self.copy("*.dll", dst="bin", src=os.path.join(self._source_subfolder, "lib"))
self.copy("*.a", dst="lib", src=os.path.join(self._source_subfolder, "lib"))

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
if self._is_mingw:
self._install_mingw()
else:
self._install_autotools()

def package_info(self):
self.cpp_info.names["pkg_config"] = "libsass"
self.cpp_info.libs = ["sass"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["dl", "m"]
self.cpp_info.system_libs.extend(["dl", "m"])
if not self.options.shared and tools.stdcpp_library(self):
self.cpp_info.system_libs.append(tools.stdcpp_library(self))
5 changes: 2 additions & 3 deletions recipes/libsass/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

project(test_package C)

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

add_executable(${PROJECT_NAME} test_package.cpp)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sass.h"
#include <cstdio>
#include <sass.h>

#include <stdio.h>

int main() {
printf("libsass version %s\t language version %s\n", libsass_version(), libsass_language_version());
Expand Down