Skip to content

Commit 49ab7a6

Browse files
Merge pull request #59 from kzhuravl/kzhuravl/packaging
Several HIPCC improvements
2 parents 2f3b708 + 8ced3fe commit 49ab7a6

File tree

13 files changed

+1352
-17
lines changed

13 files changed

+1352
-17
lines changed

amd/hipcc/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Merge files created by git.
2+
*.orig
3+
# Reject files created by patch.
4+
*.rej
5+
6+
# Nested build directory.
7+
/build*

amd/hipcc/CMakeLists.txt

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,114 @@
1-
cmake_minimum_required(VERSION 3.16.3)
2-
project (hipcc.bin)
1+
cmake_minimum_required(VERSION 3.13.4)
2+
3+
project(hipcc VERSION "1.0.0" LANGUAGES C CXX)
4+
set(hipcc_NAME "${PROJECT_NAME}")
5+
6+
include(CMakePackageConfigHelpers)
7+
include(GNUInstallDirs)
8+
9+
find_package(ROCM QUIET)
10+
if(ROCM_FOUND)
11+
include(ROCMSetupVersion)
12+
rocm_setup_version(VERSION "${hipcc_VERSION}")
13+
endif()
314

4-
# Specify the C++ standard
515
set(CMAKE_CXX_STANDARD 17)
616
set(CMAKE_CXX_STANDARD_REQUIRED True)
717

8-
set (LINK_LIBS libstdc++fs.so)
9-
add_executable(hipcc.bin src/hipBin.cpp)
10-
if (NOT WIN32) # C++17 does not require the std lib linking
11-
target_link_libraries(hipcc.bin ${LINK_LIBS} ) # for hipcc.bin
18+
set(ADDITIONAL_SHARED_LIBRARIES_TO_LINK
19+
libstdc++fs.so)
20+
21+
set(HIPCC_BIN
22+
hipcc.bin)
23+
set(HIPCC_SOURCES
24+
src/hipBin.cpp)
25+
26+
set(HIPCONFIG_BIN
27+
hipconfig.bin)
28+
set(HIPCONFIG_SOURCES
29+
src/hipBin.cpp)
30+
31+
add_executable(${HIPCC_BIN} ${HIPCC_SOURCES})
32+
if(NOT WIN32)
33+
# C++17 does not require std lib linking.
34+
target_link_libraries(${HIPCC_BIN} ${ADDITIONAL_SHARED_LIBRARIES_TO_LINK})
1235
endif()
1336

14-
project (hipconfig.bin)
15-
add_executable(hipconfig.bin src/hipBin.cpp)
16-
if (NOT WIN32) # C++17 does not require the std lib linking
17-
target_link_libraries(hipconfig.bin ${LINK_LIBS} ) # for hipconfig.bin
37+
add_executable(${HIPCONFIG_BIN} ${HIPCONFIG_SOURCES})
38+
if(NOT WIN32)
39+
# C++17 does not require std lib linking.
40+
target_link_libraries(${HIPCONFIG_BIN} ${ADDITIONAL_SHARED_LIBRARIES_TO_LINK})
41+
endif()
42+
43+
# Copy scripts and batch files to build directory.
44+
file(COPY ${CMAKE_SOURCE_DIR}/bin/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
45+
46+
set(CPACK_GENERATOR "DEB;RPM;ZIP" CACHE STRING "Default packaging generators")
47+
set(CPACK_PACKAGE_CONTACT "ROCm Compiler Support <[email protected]>")
48+
set(CPACK_PACKAGE_DESCRIPTION "HIP Compiler Driver")
49+
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
50+
set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.")
51+
set(CPACK_PACKAGE_VERSION_MAJOR "${hipcc_VERSION_MAJOR}")
52+
set(CPACK_PACKAGE_VERSION_MINOR "${hipcc_VERSION_MINOR}")
53+
set(CPACK_PACKAGE_VERSION_PATCH "${hipcc_VERSION_PATCH}")
54+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
55+
56+
# Debian-specific packaging variables.
57+
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
58+
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")
59+
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ROCm-Developer-Tools/HIPCC")
60+
if(DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
61+
set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
62+
else()
63+
set(CPACK_DEBIAN_PACKAGE_RELEASE "local")
64+
endif()
65+
66+
# RPM-specific packaging variables.
67+
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
68+
set(CPACK_RPM_PACKAGE_LICENSE "NCSA")
69+
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")
70+
if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE})
71+
set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE})
72+
else()
73+
set(CPACK_RPM_PACKAGE_RELEASE "local")
74+
endif()
75+
if(CPACK_RPM_PACKAGE_RELEASE)
76+
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
77+
endif()
78+
79+
# ROCM versioning.
80+
set(ROCM_VERSION_FOR_PACKAGE "")
81+
if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
82+
set(ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_LIBPATCH_VERSION})
83+
elseif(DEFINED ENV{ROCM_VERSION})
84+
string(REGEX REPLACE "." "" ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_VERSION})
85+
else()
86+
set(ROCM_VERSION_FOR_PACKAGE "99999")
87+
endif()
88+
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${ROCM_VERSION_FOR_PACKAGE}")
89+
90+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
91+
DESTINATION .
92+
USE_SOURCE_PERMISSIONS)
93+
install(FILES
94+
"LICENSE.txt"
95+
"README.md"
96+
COMPONENT ${hipcc_NAME}
97+
DESTINATION ${CMAKE_INSTALL_DOCDIR})
98+
install(TARGETS ${HIPCC_BIN}
99+
COMPONENT ${hipcc_NAME}
100+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
101+
install(TARGETS ${HIPCONFIG_BIN}
102+
COMPONENT ${hipcc_NAME}
103+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
104+
105+
# TODO: WIN32 check need to be removed if backward
106+
# compatibility is required for WIN32.
107+
option(HIPCC_BACKWARD_COMPATIBILITY "Enable HIPCC backward compatibility" ON)
108+
if(NOT WIN32)
109+
if(HIPCC_BACKWARD_COMPATIBILITY)
110+
include(hipcc-backward-compat.cmake)
111+
endif()
18112
endif()
19113

20-
set(HIP_VERSION_MAJOR 4 PARENT_SCOPE)
21-
set(HIP_VERSION_MINOR 4 PARENT_SCOPE)
22-
set(HIP_VERSION_PATCH 4 PARENT_SCOPE)
114+
include(CPack)

amd/hipcc/bin/hipcc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env perl
2+
# Copyright (c) 2015 - 2021 Advanced Micro Devices, Inc. All rights reserved.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in
12+
# all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
# THE SOFTWARE.
21+
22+
# Need perl > 5.10 to use logic-defined or
23+
use 5.006; use v5.10.1;
24+
25+
use warnings;
26+
27+
use File::Basename;
28+
use File::Spec::Functions 'catfile';
29+
30+
# TODO: By default select perl script until change incorporated in HIP build script.
31+
my $USE_PERL_SCRIPT = $ENV{'HIP_USE_PERL_SCRIPTS'};
32+
$USE_PERL_SCRIPT //= 1; # use defined-or assignment operator. Use env var, but if not defined default to 1.
33+
34+
my $isWindows = ($^O eq 'MSWin32' or $^O eq 'msys');
35+
# escapes args with quotes SWDEV-341955
36+
foreach $arg (@ARGV) {
37+
if ($isWindows) {
38+
$arg =~ s/[^-a-zA-Z0-9_=+,.:\/\\ ]/\\$&/g;
39+
}
40+
}
41+
42+
my $SCRIPT_DIR=dirname(__FILE__);
43+
if ($USE_PERL_SCRIPT) {
44+
#Invoke hipcc.pl
45+
my $HIPCC_PERL=catfile($SCRIPT_DIR, '/hipcc.pl');
46+
system($^X, $HIPCC_PERL, @ARGV);
47+
} else {
48+
$BIN_NAME="/hipcc.bin";
49+
if ($isWindows) {
50+
$BIN_NAME="/hipcc.bin.exe";
51+
}
52+
my $HIPCC_BIN=catfile($SCRIPT_DIR, $BIN_NAME);
53+
if ( -e $HIPCC_BIN ) {
54+
#Invoke hipcc.bin
55+
system($HIPCC_BIN, @ARGV);
56+
} else {
57+
print "hipcc.bin not present; install HIPCC binaries before proceeding\n";
58+
exit(-1);
59+
}
60+
}
61+
62+
# Because of this wrapper we need to check
63+
# the output of the system command for perl and bin
64+
# else the failures are ignored and build fails silently
65+
if ($? == -1) {
66+
exit($?);
67+
}
68+
elsif ($? & 127) {
69+
exit($?);
70+
}
71+
else {
72+
$CMD_EXIT_CODE = $? >> 8;
73+
}
74+
exit($CMD_EXIT_CODE);

amd/hipcc/bin/hipcc.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@set HIPCC="%~dp0hipcc"
2+
@perl %HIPCC% %*

0 commit comments

Comments
 (0)