Skip to content

Commit

Permalink
[openblas] make openblas build on MinGW (#20986)
Browse files Browse the repository at this point in the history
* [openblas] make openblas build on MinGW

* Portfile cleanup: Join separate vcpkg_check_feature calls and add double quotes according to maintainer guidelines.

* Portfile cleanup: Migrate vcpkg cmake commands from deprecated to new functions.

* Portfile cleanup: Migrate vcpkg cmake commands from deprecated to new functions (2) - missed a spot.

* Re-factory code

* version

* [shogun] Fix include cblas path

* version

Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com>
  • Loading branch information
ChristopherSchwartzXRITE and JackBoosY authored Nov 19, 2021
1 parent 297ff7b commit 4389f62
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 72 deletions.
22 changes: 22 additions & 0 deletions ports/openblas/install-tools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/cmake/prebuild.cmake b/cmake/prebuild.cmake
index 0c126e3..bb0124b 100644
--- a/cmake/prebuild.cmake
+++ b/cmake/prebuild.cmake
@@ -558,6 +558,8 @@ else(NOT CMAKE_CROSSCOMPILING)
if (NOT ${GETARCH_RESULT})
MESSAGE(FATAL_ERROR "Compiling getarch failed ${GETARCH_LOG}")
endif ()
+
+ install(FILES "${PROJECT_BINARY_DIR}/${GETARCH_BIN}" DESTINATION bin)
endif ()
unset (HAVE_AVX2)
unset (HAVE_AVX)
@@ -601,6 +603,8 @@ execute_process(COMMAND "${BLASHELPER_BINARY_DIR}/${GETARCH_BIN}" 1 OUTPUT_VARIA
if (NOT ${GETARCH2_RESULT})
MESSAGE(FATAL_ERROR "Compiling getarch_2nd failed ${GETARCH2_LOG}")
endif ()
+
+ install(FILES "${PROJECT_BINARY_DIR}/${GETARCH2_BIN}" DESTINATION bin)
endif ()

# use the cmake binary w/ the -E param to run a shell command in a cross-platform way
109 changes: 40 additions & 69 deletions ports/openblas/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ vcpkg_from_github(
fix-redefinition-function.patch
fix-uwp-build.patch
fix-marco-conflict.patch
install-tools.patch
)

find_program(GIT NAMES git git.cmd)

# sed and awk are installed with git but in a different directory
get_filename_component(GIT_EXE_PATH ${GIT} DIRECTORY)
get_filename_component(GIT_EXE_PATH "${GIT}" DIRECTORY)
set(SED_EXE_PATH "${GIT_EXE_PATH}/../usr/bin")

# openblas require perl to generate .def for exports
vcpkg_find_acquire_program(PERL)
get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
get_filename_component(PERL_EXE_PATH "${PERL}" DIRECTORY)
set(PATH_BACKUP "$ENV{PATH}")
vcpkg_add_to_path("${PERL_EXE_PATH}")
vcpkg_add_to_path("${SED_EXE_PATH}")
Expand All @@ -29,83 +30,53 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
threads USE_THREAD
simplethread USE_SIMPLE_THREADED_LEVEL3
"dynamic-arch" DYNAMIC_ARCH
)

set(COMMON_OPTIONS -DBUILD_WITHOUT_LAPACK=ON)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
"dynamic-arch" DYNAMIC_ARCH
)

if(VCPKG_TARGET_IS_OSX)
if("dynamic-arch" IN_LIST FEATURES)
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
message(STATUS "Openblas with \"dynamic-arch\" option for OSX supports only dynamic linkage. It's not a bag of openblas but bug of combination cmake+ninja+osx. See: https://gitlab.kitware.com/cmake/cmake/-/issues/16731")
endif()
endif()

set(OPENBLAS_EXTRA_OPTIONS)
# for UWP version, must build non uwp first for helper
# binaries.
if(VCPKG_TARGET_IS_UWP)
message(STATUS "Building Windows helper files")
set(TEMP_CMAKE_SYSTEM_NAME "${VCPKG_CMAKE_SYSTEM_NAME}")
set(TEMP_CMAKE_SYSTEM_VERSION "${VCPKG_CMAKE_SYSTEM_VERSION}")
set(TEMP_TARGET_TRIPLET "${TARGET_TRIPLET}")
unset(VCPKG_CMAKE_SYSTEM_NAME)
unset(VCPKG_CMAKE_SYSTEM_VERSION)
set(TARGET_TRIPLET "x64-windows")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS ${FEATURE_OPTIONS}
${COMMON_OPTIONS}
-DTARGET=NEHALEM
)

# add just built path to environment for gen_config_h.exe,
# getarch.exe and getarch_2nd.exe
vcpkg_add_to_path("${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")

# restore target build information
set(VCPKG_CMAKE_SYSTEM_NAME "${TEMP_CMAKE_SYSTEM_NAME}")
set(VCPKG_CMAKE_SYSTEM_VERSION "${TEMP_CMAKE_SYSTEM_VERSION}")
set(TARGET_TRIPLET "${TEMP_TARGET_TRIPLET}")

message(STATUS "Finished building Windows helper files")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
${COMMON_OPTIONS}
-DCMAKE_SYSTEM_PROCESSOR=AMD64
-DVS_WINRT_COMPONENT=TRUE
"-DBLASHELPER_BINARY_DIR=${CURRENT_BUILDTREES_DIR}/x64-windows-rel")

elseif(VCPKG_TARGET_IS_WINDOWS)
vcpkg_configure_cmake(
PREFER_NINJA
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
${COMMON_OPTIONS}
${FEATURE_OPTIONS}
)
else()
if(VCPKG_TARGET_IS_UWP)
list(APPEND OPENBLAS_EXTRA_OPTIONS -DCMAKE_SYSTEM_PROCESSOR=AMD64
"-DBLASHELPER_BINARY_DIR=${CURRENT_HOST_INSTALLED_DIR}/tools/${PORT}")
elseif(NOT (VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW))
string(APPEND VCPKG_C_FLAGS " -DNEEDBUNDERSCORE") # Required to get common BLASFUNC to append extra _
string(APPEND VCPKG_CXX_FLAGS " -DNEEDBUNDERSCORE")
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
${COMMON_OPTIONS}
${FEATURE_OPTIONS}
-DNOFORTRAN=ON
-DBU=_ #required for all blas functions to append extra _ using NAME
)
list(APPEND OPENBLAS_EXTRA_OPTIONS
-DNOFORTRAN=ON
-DBU=_ #required for all blas functions to append extra _ using NAME
)
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
${COMMON_OPTIONS}
${OPENBLAS_EXTRA_OPTIONS}
)

vcpkg_cmake_install()
vcpkg_copy_pdbs()

vcpkg_cmake_config_fixup(CONFIG_PATH share/cmake/OpenBLAS)

if (EXISTS "${CURRENT_PACKAGES_DIR}/bin/getarch${VCPKG_HOST_EXECUTABLE_SUFFIX}")
vcpkg_copy_tools(TOOL_NAMES getarch AUTO_CLEAN)
endif()
if (EXISTS "${CURRENT_PACKAGES_DIR}/bin/getarch_2nd${VCPKG_HOST_EXECUTABLE_SUFFIX}")
vcpkg_copy_tools(TOOL_NAMES getarch_2nd AUTO_CLEAN)
endif()

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/OpenBLAS TARGET_PATH share/openblas)
set(ENV{PATH} "${PATH_BACKUP}")

set(pcfile "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/openblas.pc")
Expand All @@ -128,14 +99,14 @@ vcpkg_fixup_pkgconfig()
# openblas do not make the config file , so I manually made this
# but I think in most case, libraries will not include these files, they define their own used function prototypes
# this is only to quite vcpkg
file(COPY ${CMAKE_CURRENT_LIST_DIR}/openblas_common.h DESTINATION ${CURRENT_PACKAGES_DIR}/include)

file(READ ${SOURCE_PATH}/cblas.h CBLAS_H)
string(REPLACE "#include \"common.h\"" "#include \"openblas_common.h\"" CBLAS_H "${CBLAS_H}")
file(WRITE ${CURRENT_PACKAGES_DIR}/include/cblas.h "${CBLAS_H}")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/openblas_common.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include")

vcpkg_copy_pdbs()
vcpkg_replace_string(
"${SOURCE_PATH}/cblas.h"
"#include \"common.h\""
"#include \"openblas_common.h\""
)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include ${CURRENT_PACKAGES_DIR}/debug/share)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
13 changes: 13 additions & 0 deletions ports/openblas/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
{
"name": "openblas",
"version": "0.3.15",
"port-version": 1,
"description": "OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.",
"homepage": "https://github.com/xianyi/OpenBLAS",
"dependencies": [
{
"name": "openblas",
"host": true
},
{
"name": "pthread",
"platform": "!windows & !uwp"
},
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
Expand Down
13 changes: 13 additions & 0 deletions ports/shogun/fix-cblas-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/shogun/mathematics/lapack.h b/src/shogun/mathematics/lapack.h
index 6ba466f..f5de479 100644
--- a/src/shogun/mathematics/lapack.h
+++ b/src/shogun/mathematics/lapack.h
@@ -38,7 +38,7 @@ extern "C" {
#include <vecLib/cblas.h>
#endif
#else
-#include <cblas.h>
+#include <openblas/cblas.h>
#endif

#ifdef HAVE_ACML
1 change: 1 addition & 0 deletions ports/shogun/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vcpkg_from_github(
cmake-config.in.patch
fix-dirent.patch
fix-ASSERT-not-found.patch
fix-cblas-path.patch
)

vcpkg_find_acquire_program(PYTHON3)
Expand Down
2 changes: 1 addition & 1 deletion ports/shogun/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shogun",
"version-string": "6.1.4",
"port-version": 5,
"port-version": 6,
"description": "Unified and efficient Machine Learning",
"homepage": "https://github.com/shogun-toolbox/shogun",
"dependencies": [
Expand Down
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4870,7 +4870,7 @@
},
"openblas": {
"baseline": "0.3.15",
"port-version": 0
"port-version": 1
},
"opencascade": {
"baseline": "7.6.0",
Expand Down Expand Up @@ -6238,7 +6238,7 @@
},
"shogun": {
"baseline": "6.1.4",
"port-version": 5
"port-version": 6
},
"signalrclient": {
"baseline": "1.0.0-beta1-9",
Expand Down
5 changes: 5 additions & 0 deletions versions/o-/openblas.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "048ae3833af8e5633ce86c3174e20c2794fe573d",
"version": "0.3.15",
"port-version": 1
},
{
"git-tree": "2a214e1bac47c70d932caef7d74771c8658b1f7a",
"version": "0.3.15",
Expand Down
5 changes: 5 additions & 0 deletions versions/s-/shogun.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "0ae86e647188a99b1602164f4614ba54d55cf22a",
"version-string": "6.1.4",
"port-version": 6
},
{
"git-tree": "bc5a003bcb8a42fc935726d0d8de55156318a3db",
"version-string": "6.1.4",
Expand Down

0 comments on commit 4389f62

Please sign in to comment.