From efaf427cdb8db3857798fec51e16af2668c59d51 Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Sun, 14 Feb 2021 12:00:36 -0500 Subject: [PATCH] Remove libponyc's link dependency on blake2 library. When trying to use libponyc from a pony program I ran into two linking problems. Both libblake2 and llvm are required to resolve symbols in libponyc. Handling all the LLVM dependencies is large issue, addressing the libblake dependency is much simpler. This commit moves libblake from being a library that gets built as a `.a` and instead links its `.o` directly into libponyc. This change along with a much larger change to address the LLVM dependency should make it possibly to easily include libponyc into pony programs via C-FFI. --- benchmark/libponyc/CMakeLists.txt | 1 - lib/CMakeLists.txt | 9 --------- src/libponyc/CMakeLists.txt | 2 +- {lib => src/libponyc}/blake2/blake2-impl.h | 4 ++-- {lib => src/libponyc}/blake2/blake2.h | 0 {lib => src/libponyc}/blake2/blake2b-ref.c | 0 src/libponyc/pkg/package.c | 2 +- src/libponyc/pkg/program.c | 2 +- src/ponyc/CMakeLists.txt | 2 -- test/libponyc/CMakeLists.txt | 3 --- 10 files changed, 5 insertions(+), 20 deletions(-) rename {lib => src/libponyc}/blake2/blake2-impl.h (97%) rename {lib => src/libponyc}/blake2/blake2.h (100%) rename {lib => src/libponyc}/blake2/blake2b-ref.c (100%) diff --git a/benchmark/libponyc/CMakeLists.txt b/benchmark/libponyc/CMakeLists.txt index 3839df80d6..ec79691144 100644 --- a/benchmark/libponyc/CMakeLists.txt +++ b/benchmark/libponyc/CMakeLists.txt @@ -22,7 +22,6 @@ target_link_directories(libponyc.benchmarks target_link_libraries(libponyc.benchmarks PRIVATE libponyc PRIVATE libponyrt - PRIVATE blake2 PRIVATE benchmark::benchmark ) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7ed6c175c0..589f12fcc9 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -19,15 +19,6 @@ ExternalProject_Add(googletest CMAKE_ARGS -DCMAKE_BUILD_TYPE=${PONYC_LIBS_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_CXX_FLAGS=-fpic -Dgtest_force_shared_crt=ON --no-warn-unused-cli ) -add_library(blake2 STATIC blake2/blake2b-ref.c) -set_property(TARGET blake2 PROPERTY POSITION_INDEPENDENT_CODE ON) - -install(TARGETS blake2 - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - COMPONENT library -) - find_package(Git) set(LLVM_DESIRED_HASH "c1a0a213378a458fbea1a5c77b315c7dce08fd05") diff --git a/src/libponyc/CMakeLists.txt b/src/libponyc/CMakeLists.txt index e5cfda85cf..06c5a5ef37 100644 --- a/src/libponyc/CMakeLists.txt +++ b/src/libponyc/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(libponyc STATIC ast/symtab.c ast/token.c ast/treecheck.c + blake2/blake2b-ref.c codegen/codegen.c codegen/genbox.c codegen/gencall.c @@ -105,7 +106,6 @@ target_compile_definitions(libponyc PRIVATE target_include_directories(libponyc PUBLIC ../common PRIVATE ../../build/libs/include - PRIVATE ../../lib/blake2 ) if (MSVC) diff --git a/lib/blake2/blake2-impl.h b/src/libponyc/blake2/blake2-impl.h similarity index 97% rename from lib/blake2/blake2-impl.h rename to src/libponyc/blake2/blake2-impl.h index 5dff7fc7a3..f53cbaf713 100644 --- a/lib/blake2/blake2-impl.h +++ b/src/libponyc/blake2/blake2-impl.h @@ -72,8 +72,8 @@ static BLAKE2_INLINE uint16_t load16( const void *src ) return w; #else const uint8_t *p = ( const uint8_t * )src; - return (( uint16_t )( p[0] ) << 0) | - (( uint16_t )( p[1] ) << 8) ; + return ( uint16_t )(( uint16_t )( p[0] ) << 0) | + ( uint16_t )(( uint16_t )( p[1] ) << 8) ; #endif } diff --git a/lib/blake2/blake2.h b/src/libponyc/blake2/blake2.h similarity index 100% rename from lib/blake2/blake2.h rename to src/libponyc/blake2/blake2.h diff --git a/lib/blake2/blake2b-ref.c b/src/libponyc/blake2/blake2b-ref.c similarity index 100% rename from lib/blake2/blake2b-ref.c rename to src/libponyc/blake2/blake2b-ref.c diff --git a/src/libponyc/pkg/package.c b/src/libponyc/pkg/package.c index 674217d5ec..f0c72cdf1f 100644 --- a/src/libponyc/pkg/package.c +++ b/src/libponyc/pkg/package.c @@ -11,7 +11,7 @@ #include "../../libponyrt/mem/pool.h" #include "../../libponyrt/sched/scheduler.h" #include "ponyassert.h" -#include +#include "../blake2/blake2.h" #include #include #include diff --git a/src/libponyc/pkg/program.c b/src/libponyc/pkg/program.c index d1e77c9f08..0e700cda8f 100644 --- a/src/libponyc/pkg/program.c +++ b/src/libponyc/pkg/program.c @@ -4,7 +4,7 @@ #include "../../libponyrt/gc/serialise.h" #include "../../libponyrt/mem/pool.h" #include "ponyassert.h" -#include +#include "../blake2/blake2.h" #include diff --git a/src/ponyc/CMakeLists.txt b/src/ponyc/CMakeLists.txt index 04dab649af..48bbd648d1 100644 --- a/src/ponyc/CMakeLists.txt +++ b/src/ponyc/CMakeLists.txt @@ -18,7 +18,6 @@ if (MSVC) target_link_libraries(ponyc PRIVATE libponyc PRIVATE libponyrt - PRIVATE blake2 PRIVATE dbghelp PRIVATE ucrt PRIVATE Ws2_32 @@ -36,7 +35,6 @@ else() target_link_libraries(ponyc PRIVATE libponyc libponyrt - blake2 ) llvm_config(ponyc all) diff --git a/test/libponyc/CMakeLists.txt b/test/libponyc/CMakeLists.txt index 4c1c800fb4..0f15a9aeaa 100644 --- a/test/libponyc/CMakeLists.txt +++ b/test/libponyc/CMakeLists.txt @@ -83,7 +83,6 @@ if (MSVC) target_link_libraries(libponyc.tests PRIVATE libponyc PRIVATE libponyrt - PRIVATE blake2 PRIVATE GTest::gtest PRIVATE dbghelp PRIVATE ucrt @@ -104,7 +103,6 @@ else() target_link_libraries(libponyc.tests PRIVATE -Wl,-force_load,../../src/libponyrt/libponyrt.a libponyc - blake2 GTest::gtest ) else() @@ -113,7 +111,6 @@ else() libponyrt -Wl,--no-whole-archive libponyc - blake2 GTest::gtest ) endif()