Skip to content

Commit

Permalink
Update ProcDump to use cmake rather than make (#218)
Browse files Browse the repository at this point in the history
* Move to CMake check-point

* Update build and contributing docs

* Add cmake to pre-reqs

* update path
  • Loading branch information
MarioHewardt authored Nov 10, 2023
1 parent ed78e3e commit c57b95b
Show file tree
Hide file tree
Showing 34 changed files with 480 additions and 202 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ bin/
release/
pkgbuild/
obj/
build/
22 changes: 9 additions & 13 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,30 @@ make install
- clang v10+
- gcc v10+
- zlib
- make
- cmake 3.10+

### Ubuntu
```
sudo apt update
sudo apt -y install gcc make clang gdb zlib1g-dev
sudo apt -y install gcc make clang gdb zlib1g-dev cmake
```

### Rocky Linux
```
sudo yum install gcc make clang gdb zlib-devel
sudo yum install gcc make clang gdb zlib-devel cmake
```

## Build
```sh
mkdir build
cd build
cmake ..
make
make install
```

# Building Packages
The distribution packages for Procdump for Linux are constructed utilizing `debbuild` for Debian targets and `rpmbuild` for Fedora targets.
The distribution packages for Procdump for Linux are constructed utilizing `dpkg-deb` for Debian targets and `rpmbuild` for Fedora targets.

To build a `deb` package of Procdump:
```sh
make && make deb
```

To build a `rpm` package of Procdump:
```sh
make && make rpm
```
make packages
```
206 changes: 206 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#
#
# ProcDump-for-Linux
#
# Copyright (c) Microsoft Corporation
#
# All rights reserved.
#
# MIT License
#
# 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.
#
#

#################################################################################
#
# CMakeLists.txt
#
# Build script
#
#################################################################################

cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0048 NEW)

#
# set the project name - version is MAJOR.MINOR.PATCH.RELEASE - releases start at 1
#
if (DEFINED ENV{VERSION})
project(ProcDumpForLinux VERSION $ENV{VERSION})
else()
project(ProcDumpForLinux VERSION 0.0.0)
endif()

set(PROJECT_VERSION_TWEAK 0)
file(READ "dist/changelog" CHANGE_LOG)

#
# package name
#
set(PACKAGE_NAME "procdump")

#
# MAN page
#
set(PROCDUMP_COMPRESS_MAN "procdump.1.gz")

add_custom_target(procDumpManPageCompress ALL
DEPENDS ${PROJECT_BINARY_DIR}/${PROCDUMP_COMPRESS_MAN}
)

add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/${PROCDUMP_COMPRESS_MAN}
COMMAND gzip -9n -f -c "${CMAKE_SOURCE_DIR}/procdump.1" > ${PROJECT_BINARY_DIR}/${PROCDUMP_COMPRESS_MAN}
COMMENT "Compressing ProcDump man page"
DEPENDS "${CMAKE_SOURCE_DIR}/procdump.1"
)

#
# Change log
#
set(PROCDUMP_COMPRESS_CHANGELOG "changelog.gz")

add_custom_target(procDumpChangelogCompress ALL
DEPENDS ${PROJECT_BINARY_DIR}/${PROCDUMP_COMPRESS_CHANGELOG}
)

add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/${PROCDUMP_COMPRESS_CHANGELOG}
COMMAND cp "${CMAKE_SOURCE_DIR}/dist/changelog" ${PROJECT_BINARY_DIR} && gzip -f -c "${CMAKE_SOURCE_DIR}/dist/changelog" > ${PROJECT_BINARY_DIR}/${PROCDUMP_COMPRESS_CHANGELOG}
COMMENT "Compressing changelog"
DEPENDS "${CMAKE_SOURCE_DIR}/dist/changelog"
)

#
# Paths
#
set(profiler_INC ${CMAKE_SOURCE_DIR}/profiler/inc)
set(profiler_SRC ${CMAKE_SOURCE_DIR}/profiler/src)
set(procdump_INC ${CMAKE_SOURCE_DIR}/include)
set(procdump_SRC ${CMAKE_SOURCE_DIR}/src)
set(procdump_Test ${CMAKE_SOURCE_DIR}/tests/integration)
set(LD "/usr/bin/ld")

#
# Configure files
#
configure_file(${procdump_INC}/ProcDumpVersion.h.in ${PROJECT_BINARY_DIR}/ProcDumpVersion.h)
configure_file(dist/DEBIAN.in/control.in DEBIANcontrol)
configure_file(dist/SPECS.in/spec.in SPECS.spec)

#
# Make procdump profiler
#
set(CMAKE_CXX_COMPILER "clang++")

# Figure out which architecture we are building for
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
set(CLRHOSTDEF -DHOST_AMD64 -DHOST_64BIT)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL x86 OR CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
set(CLRHOSTDEF -DHOST_X86)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv6 OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv6l)
set(CLRHOSTDEF -DHOST_ARM -DHOST_ARMV6)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a)
set(CLRHOSTDEF -DHOST_ARM)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(CLRHOSTDEF -DHOST_ARM64 -DHOST_64BIT)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64)
set(CLRHOSTDEF -DHOST_LOONGARCH64 -DHOST_64BIT)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL riscv64)
set(CLRHOSTDEF -DHOST_RISCV64 -DHOST_64BIT)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL s390x)
set(CLRHOSTDEF -DHOST_S390X -DHOST_64BIT -DBIGENDIAN)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL mips64)
set(CLRHOSTDEF -DHOST_MIPS64 -DHOST_64BIT=1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le)
set(CLRHOSTDEF -DHOST_POWERPC64 -DHOST_64BIT)
else()
message(FATAL_ERROR "'${CMAKE_SYSTEM_PROCESSOR}' is an unsupported architecture.")
endif()

add_library(ProcDumpProfiler SHARED
${profiler_SRC}/ClassFactory.cpp
${profiler_SRC}/ProcDumpProfiler.cpp
${profiler_SRC}/dllmain.cpp
${profiler_SRC}/corprof_i.cpp
${profiler_SRC}/easylogging++.cc
)

target_compile_options(ProcDumpProfiler PRIVATE -DELPP_NO_DEFAULT_LOG_FILE -DELPP_THREAD_SAFE -g -pthread -Wno-pragma-pack -Wno-pointer-arith -Wno-conversion-null -Wno-write-strings -Wno-format-security -fPIC -fms-extensions ${CLRHOSTDEF} -DPAL_STDCPP_COMPAT -DPLATFORM_UNIX -std=c++11)
set_target_properties(ProcDumpProfiler PROPERTIES PREFIX "")

target_include_directories(ProcDumpProfiler PUBLIC
"${profiler_INC}"
"${procdump_INC}"
/usr/include
)

add_custom_command(OUTPUT ProcDumpProfiler.o
COMMAND "${LD}" -r -b binary -o "${PROJECT_BINARY_DIR}/ProcDumpProfiler.o" ProcDumpProfiler.so
COMMENT "Packing ProcDumpProfiler.so into ProcDumpProfiler.o"
DEPENDS ProcDumpProfiler
)

#
# Make ProcDump
#
SET (CMAKE_C_COMPILER "clang")
add_executable(procdump
${procdump_SRC}/CoreDumpWriter.c
${procdump_SRC}/DotnetHelpers.c
${procdump_SRC}/Events.c
${procdump_SRC}/GenHelpers.c
${procdump_SRC}/Handle.c
${procdump_SRC}/Logging.c
${procdump_SRC}/Monitor.c
${procdump_SRC}/Procdump.c
${procdump_SRC}/ProcDumpConfiguration.c
${procdump_SRC}/Process.c
${procdump_SRC}/ProfilerHelpers.c
${PROJECT_BINARY_DIR}/ProcDumpProfiler.o
)

target_compile_options(procdump PRIVATE -pthread -std=gnu99 -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -O2 -Werror)

target_include_directories(procdump PUBLIC
${procdump_INC}
${PROJECT_BINARY_DIR}
/usr/include
)

target_link_libraries(procdump pthread)

#
# Copy integration test directory
#
add_custom_target(copy_integration_test_dir ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/tests/integration ${CMAKE_BINARY_DIR}/tests/integration
COMMENT "Copying the tests/integration directory to the build directory"
)

#
# Make test application
#
add_executable(ProcDumpTestApplication
${procdump_Test}/ProcDumpTestApplication.c
)

target_compile_options(ProcDumpTestApplication PRIVATE -pthread -std=gnu99 -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Werror)

target_include_directories(ProcDumpTestApplication PUBLIC
/usr/include
)

target_link_libraries(ProcDumpTestApplication pthread)

#
# Make package(s)
#
add_custom_target(packages
COMMAND "${CMAKE_SOURCE_DIR}/makePackages.sh" "${CMAKE_SOURCE_DIR}" "${PROJECT_BINARY_DIR}" "${PACKAGE_NAME}" "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" "0"
DEPENDS "${CMAKE_SOURCE_DIR}/dist" "${PROJECT_BINARY_DIR}/procdump"
)
24 changes: 4 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,11 @@ The master branch contains current development. While CI should ensure that mas
To contribute, fork the repository and create a branch in your fork for your work. Please keep branch names short and descriptive. Please direct PRs into the upstream master branch.

## Build and run from source
### Environment
* Linux OS (dev team is using Ubuntu 18.04)
* Development can be done on Windows Subsystem for Linux (WSL), but ProcDump cannot be executed in that environment
* git
* GDB
* GCC (or other C compiler)
* GNU Make

## Building from source
* Clone the repo
* Run `make` from the project root
* The procdump executable will be placed into the `bin` directory
```sh
git clone https://github.com/microsoft/ProcDump-for-Linux
cd ProcDump-for-Linux
make
```
Please refer to [Build instructions](BUILD.md) for details on how to build ProcDump for Linux.

## Testing
* There are a multitude of tests included in the `tests` directory of the repository.
* Add new tests corresponding to your change, if applicable. Include tests when adding new features. When fixing bugs, start with adding a test that highlights how the current behavior is broken.
* There are a multitude of tests included in the `tests` directory of the repository.
* Add new tests corresponding to your change, if applicable. Include tests when adding new features. When fixing bugs, start with adding a test that highlights how the current behavior is broken.
* Make sure that the tests are all passing, including your new tests.

## Creating integration tests
Expand All @@ -39,7 +23,7 @@ Test scripts will return `0` when they succeed and `1` when they fail.

Most of the tests are written using [stress-ng](https://wiki.ubuntu.com/Kernel/References/stress-ng "stress-ng manual"), but you can write your own code to simulate the scenario you require.

After writing a new test, run the `run.sh` script and verify that no tests fail.
After writing a new test, run the `run.sh` script from $build/tests/integration and verify that no tests fail.

## Pull Requests
* Always tag a work item or issue with a pull request.
Expand Down
Loading

0 comments on commit c57b95b

Please sign in to comment.