Skip to content

Commit

Permalink
♻️ Replace boilerplate w/ libhal-bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
kammce committed Mar 7, 2024
1 parent afe4612 commit 21ffd8f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 115 deletions.
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ libhal_test_and_make_library(
TEST_SOURCES
tests/__device__.test.cpp
tests/main.test.cpp

PACKAGES
libhal
libhal-util

LINK_LIBRARIES
libhal::libhal
libhal::util
)
62 changes: 6 additions & 56 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
# limitations under the License.

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import copy
from conan.tools.build import check_min_cppstd
import os


required_conan_version = ">=2.0.14"
Expand All @@ -30,61 +26,15 @@ class libhal___device___conan(ConanFile):
description = ("A collection of drivers for the __device__")
topics = ("__device__", "libhal", "driver")
settings = "compiler", "build_type", "os", "arch"
exports_sources = ("include/*", "tests/*", "LICENSE", "CMakeLists.txt",
"src/*")
generators = "CMakeToolchain", "CMakeDeps"

@property
def _min_cppstd(self):
return "20"

@property
def _compilers_minimum_version(self):
return {
"gcc": "11",
"clang": "14",
"apple-clang": "14.0.0"
}

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, self._min_cppstd)

def build_requirements(self):
self.tool_requires("cmake/3.27.1")
self.tool_requires("libhal-cmake-util/4.0.2")

self.test_requires("boost-ext-ut/1.1.9")
self.test_requires("libhal-mock/[^3.0.0]")
python_requires = "libhal-bootstrap/[^0.0.3]"
python_requires_extend = "libhal-bootstrap.library"

def requirements(self):
self.requires("libhal/[^3.0.0]", transitive_headers=True)
self.requires("libhal-util/[^4.0.0]")

def layout(self):
cmake_layout(self)

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

def package(self):
copy(self,
"LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
copy(self,
"*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
copy(self,
"*.hpp",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))

cmake = CMake(self)
cmake.install()
# Adds libhal and libhal-util as transitive headers, meaning library
# consumers get the libhal and libhal-util headers downstream.
bootstrap = self.python_requires["libhal-bootstrap"]
bootstrap.module.add_library_requirements(self)

def package_info(self):
self.cpp_info.libs = ["libhal-__device__"]
Expand Down
7 changes: 0 additions & 7 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ libhal_build_demos(

PACKAGES
libhal-__device__
prebuilt-picolibc

LINK_LIBRARIES
libhal::__device__
picolibc

LINK_FLAGS
-Wl,--wrap=__cxa_allocate_exception
-Wl,--wrap=__cxa_free_exception
-Wl,--wrap=__cxa_call_unexpected
)
27 changes: 4 additions & 23 deletions demos/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,14 @@
# 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.

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout


class demos(ConanFile):
settings = "compiler", "build_type", "os", "arch"
generators = "CMakeToolchain", "CMakeDeps", "VirtualBuildEnv"
options = {"platform": ["ANY"]}
default_options = {"platform": "unspecified"}

def build_requirements(self):
self.tool_requires("cmake/3.27.1")
self.tool_requires("libhal-cmake-util/4.0.2")
python_requires = "libhal-bootstrap/[^0.0.4]"
python_requires_extend = "libhal-bootstrap.demo"

def requirements(self):
self.requires(f"prebuilt-picolibc/{self.settings.compiler.version}")
if str(self.options.platform).startswith("lpc40"):
self.requires("libhal-lpc40/[^3.0.0]")
bootstrap = self.python_requires["libhal-bootstrap"]
bootstrap.module.add_demo_requirements(self)
self.requires("libhal-__device__/[>=0.0.0]")
self.requires("libhal-util/[^4.0.0]")

def layout(self):
platform_directory = "build/" + str(self.options.platform)
cmake_layout(self, build_folder=platform_directory)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
22 changes: 2 additions & 20 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,12 @@
# limitations under the License.

from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

def build_requirements(self):
self.tool_requires("cmake/3.27.1")
python_requires = "libhal-bootstrap/[^0.0.1]"
python_requires_extend = "libhal-bootstrap.library_test_package"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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

def test(self):
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
1 change: 0 additions & 1 deletion test_package/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#include <libhal-__device__/__device__.hpp>
#include <libhal/error.hpp>

int main()
{
Expand Down

0 comments on commit 21ffd8f

Please sign in to comment.