Skip to content

Commit

Permalink
Merge pull request #59 from kzhuravl/kzhuravl/packaging
Browse files Browse the repository at this point in the history
Several HIPCC improvements
  • Loading branch information
david-salinas committed Apr 3, 2023
2 parents 2f3b708 + 8ced3fe commit 49ab7a6
Show file tree
Hide file tree
Showing 13 changed files with 1,352 additions and 17 deletions.
7 changes: 7 additions & 0 deletions amd/hipcc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Merge files created by git.
*.orig
# Reject files created by patch.
*.rej

# Nested build directory.
/build*
120 changes: 106 additions & 14 deletions amd/hipcc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,114 @@
cmake_minimum_required(VERSION 3.16.3)
project (hipcc.bin)
cmake_minimum_required(VERSION 3.13.4)

project(hipcc VERSION "1.0.0" LANGUAGES C CXX)
set(hipcc_NAME "${PROJECT_NAME}")

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

find_package(ROCM QUIET)
if(ROCM_FOUND)
include(ROCMSetupVersion)
rocm_setup_version(VERSION "${hipcc_VERSION}")
endif()

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set (LINK_LIBS libstdc++fs.so)
add_executable(hipcc.bin src/hipBin.cpp)
if (NOT WIN32) # C++17 does not require the std lib linking
target_link_libraries(hipcc.bin ${LINK_LIBS} ) # for hipcc.bin
set(ADDITIONAL_SHARED_LIBRARIES_TO_LINK
libstdc++fs.so)

set(HIPCC_BIN
hipcc.bin)
set(HIPCC_SOURCES
src/hipBin.cpp)

set(HIPCONFIG_BIN
hipconfig.bin)
set(HIPCONFIG_SOURCES
src/hipBin.cpp)

add_executable(${HIPCC_BIN} ${HIPCC_SOURCES})
if(NOT WIN32)
# C++17 does not require std lib linking.
target_link_libraries(${HIPCC_BIN} ${ADDITIONAL_SHARED_LIBRARIES_TO_LINK})
endif()

project (hipconfig.bin)
add_executable(hipconfig.bin src/hipBin.cpp)
if (NOT WIN32) # C++17 does not require the std lib linking
target_link_libraries(hipconfig.bin ${LINK_LIBS} ) # for hipconfig.bin
add_executable(${HIPCONFIG_BIN} ${HIPCONFIG_SOURCES})
if(NOT WIN32)
# C++17 does not require std lib linking.
target_link_libraries(${HIPCONFIG_BIN} ${ADDITIONAL_SHARED_LIBRARIES_TO_LINK})
endif()

# Copy scripts and batch files to build directory.
file(COPY ${CMAKE_SOURCE_DIR}/bin/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

set(CPACK_GENERATOR "DEB;RPM;ZIP" CACHE STRING "Default packaging generators")
set(CPACK_PACKAGE_CONTACT "ROCm Compiler Support <rocm.compiler.support@amd.com>")
set(CPACK_PACKAGE_DESCRIPTION "HIP Compiler Driver")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.")
set(CPACK_PACKAGE_VERSION_MAJOR "${hipcc_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${hipcc_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${hipcc_VERSION_PATCH}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")

# Debian-specific packaging variables.
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "hip-dev, libfile-basedir-perl, libfile-copy-recursive-perl, libfile-listing-perl, libfile-which-perl, liburi-encode-perl, perl (>= 5.0), rocm-core, rocm-llvm")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ROCm-Developer-Tools/HIPCC")
if(DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
else()
set(CPACK_DEBIAN_PACKAGE_RELEASE "local")
endif()

# RPM-specific packaging variables.
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_LICENSE "NCSA")
set(CPACK_RPM_PACKAGE_REQUIRES "hip-devel, perl >= 5.0, perl-File-BaseDir, perl-File-Listing, perl-File-Which, perl-URI-Encode, rocm-core, rocm-llvm")
if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE})
set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE})
else()
set(CPACK_RPM_PACKAGE_RELEASE "local")
endif()
if(CPACK_RPM_PACKAGE_RELEASE)
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
endif()

# ROCM versioning.
set(ROCM_VERSION_FOR_PACKAGE "")
if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
set(ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_LIBPATCH_VERSION})
elseif(DEFINED ENV{ROCM_VERSION})
string(REGEX REPLACE "." "" ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_VERSION})
else()
set(ROCM_VERSION_FOR_PACKAGE "99999")
endif()
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${ROCM_VERSION_FOR_PACKAGE}")

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
DESTINATION .
USE_SOURCE_PERMISSIONS)
install(FILES
"LICENSE.txt"
"README.md"
COMPONENT ${hipcc_NAME}
DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(TARGETS ${HIPCC_BIN}
COMPONENT ${hipcc_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS ${HIPCONFIG_BIN}
COMPONENT ${hipcc_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

# TODO: WIN32 check need to be removed if backward
# compatibility is required for WIN32.
option(HIPCC_BACKWARD_COMPATIBILITY "Enable HIPCC backward compatibility" ON)
if(NOT WIN32)
if(HIPCC_BACKWARD_COMPATIBILITY)
include(hipcc-backward-compat.cmake)
endif()
endif()

set(HIP_VERSION_MAJOR 4 PARENT_SCOPE)
set(HIP_VERSION_MINOR 4 PARENT_SCOPE)
set(HIP_VERSION_PATCH 4 PARENT_SCOPE)
include(CPack)
74 changes: 74 additions & 0 deletions amd/hipcc/bin/hipcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env perl
# Copyright (c) 2015 - 2021 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Need perl > 5.10 to use logic-defined or
use 5.006; use v5.10.1;

use warnings;

use File::Basename;
use File::Spec::Functions 'catfile';

# TODO: By default select perl script until change incorporated in HIP build script.
my $USE_PERL_SCRIPT = $ENV{'HIP_USE_PERL_SCRIPTS'};
$USE_PERL_SCRIPT //= 1; # use defined-or assignment operator. Use env var, but if not defined default to 1.

my $isWindows = ($^O eq 'MSWin32' or $^O eq 'msys');
# escapes args with quotes SWDEV-341955
foreach $arg (@ARGV) {
if ($isWindows) {
$arg =~ s/[^-a-zA-Z0-9_=+,.:\/\\ ]/\\$&/g;
}
}

my $SCRIPT_DIR=dirname(__FILE__);
if ($USE_PERL_SCRIPT) {
#Invoke hipcc.pl
my $HIPCC_PERL=catfile($SCRIPT_DIR, '/hipcc.pl');
system($^X, $HIPCC_PERL, @ARGV);
} else {
$BIN_NAME="/hipcc.bin";
if ($isWindows) {
$BIN_NAME="/hipcc.bin.exe";
}
my $HIPCC_BIN=catfile($SCRIPT_DIR, $BIN_NAME);
if ( -e $HIPCC_BIN ) {
#Invoke hipcc.bin
system($HIPCC_BIN, @ARGV);
} else {
print "hipcc.bin not present; install HIPCC binaries before proceeding\n";
exit(-1);
}
}

# Because of this wrapper we need to check
# the output of the system command for perl and bin
# else the failures are ignored and build fails silently
if ($? == -1) {
exit($?);
}
elsif ($? & 127) {
exit($?);
}
else {
$CMD_EXIT_CODE = $? >> 8;
}
exit($CMD_EXIT_CODE);
2 changes: 2 additions & 0 deletions amd/hipcc/bin/hipcc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@set HIPCC="%~dp0hipcc"
@perl %HIPCC% %*
Loading

0 comments on commit 49ab7a6

Please sign in to comment.