Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build system tweaks patchset #618

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eee07e8
[llvm] Bump ProGraML version to v0.3.2.
ChrisCummins Jan 21, 2022
54b8720
[llvm] Update ProGraML header file name.
ChrisCummins Jan 27, 2022
ce98aab
[cmake] Update ProGraML header path for library discovery.
ChrisCummins Mar 7, 2022
539172c
[cmake] Automatically enable ccache when it is available.
ChrisCummins Mar 9, 2022
9501b77
[cmake] Turn off exporting compile commands.
ChrisCummins Mar 9, 2022
4e49ada
[cmake] Remove conditional macOS logic.
ChrisCummins Mar 9, 2022
59383c5
[cmake] Use relative paths to build tools includes.
ChrisCummins Mar 9, 2022
771699e
[cmake] Force Ninja generator.
ChrisCummins Mar 9, 2022
9c149fe
[cmake] Find and enable lld if available.
ChrisCummins Mar 9, 2022
ed410fd
[cmake] Clarify variable usage through its name.
ChrisCummins Mar 9, 2022
8cd6c56
[ci] Add macOS step for installing build deps.
ChrisCummins Mar 9, 2022
8202bd8
[ci] Use unversioned clang/clang++.
ChrisCummins Mar 10, 2022
3748955
Bump absl-cpp dependency.
ChrisCummins Mar 4, 2022
7f1a1d2
Bump gbenchmark dependency.
ChrisCummins Mar 4, 2022
9b023e4
[cmake] Only build LLVM from source if LLVM_PROVIDE=internal.
ChrisCummins Mar 10, 2022
2dbc8f2
[INSTALL] Add note on building against pre-compiled LLVM.
ChrisCummins Mar 10, 2022
f660904
[cmake] Fix path to dead cmake targets.
ChrisCummins Mar 10, 2022
dd94fb4
[cmake] Remove "partial" workaround.
ChrisCummins Mar 10, 2022
9920fb9
[cmake] Fix regressions introduced in #600.
ChrisCummins Mar 10, 2022
0bc0612
[cmake] Bump ProGraML to pull in updated absl.
ChrisCummins Mar 10, 2022
3cdaa45
Pin back ProGraML revision to wip/CompilerGym-patches branch.
ChrisCummins Mar 10, 2022
cd94bb2
[llvm] Initialize only the native target.
ChrisCummins Mar 10, 2022
9af78f3
Reformat CMake file after rebase.
ChrisCummins Mar 10, 2022
87b70ba
[ci] Don't create versioned symlinks.
ChrisCummins Mar 10, 2022
f079693
[ci] Use pre-built clang+llvm for compilation.
ChrisCummins Mar 10, 2022
726b7f5
[cmake] Disable formatter on files gersemi fails on.
ChrisCummins Mar 10, 2022
26e287d
[ci] Disable the use of docker on macOS.
ChrisCummins Mar 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/actions/install-cmake-build-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ runs:
- name: Install CMake dependencies
run: |
if [ "$(uname)" = "Darwin" ]; then
echo "CMake build for Darwin is unimplemented."
exit 1
brew install bazelisk ccache cmake zlib
else
# Compiler
sudo apt-get install clang++-9 lld-9 tar bzip2 ninja-build
sudo apt-get install tar bzip2 ninja-build
sudo apt-get install -y bzip2 clang-9 clang++-9 lld-9 tar bzip2 ninja-build tar ninja-build
# CMake
wget https://github.com/Kitware/CMake/releases/download/v3.20.5/cmake-3.20.5-linux-x86_64.sh -O /tmp/cmake.sh
sudo bash /tmp/cmake.sh --prefix=/usr/local --exclude-subdir --skip-license
Expand Down
60 changes: 17 additions & 43 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,30 @@ jobs:
- name: Install build dependencies
uses: ./.github/actions/install-cmake-build-dependencies

- name: Download LLVM 10.0.0 release
run: |
if [ "$(uname)" = "Darwin" ]; then
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz -O ~/llvm.tar.xz
else
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -O ~/llvm.tar.xz
fi
# TODO(cummins): Remove 'v' debugging flag:
mkdir ~/llvm && tar xvf ~/llvm.tar.xz --strip-components 1 -C ~/llvm
rm ~/llvm.tar.xz
echo "Unpacked, testing for expected file:"
test -d ~/llvm/lib/cmake/llvm

- name: CMake Build
run: |
cmake \
-GNinja \
-DCMAKE_C_COMPILER=clang-9 \
-DCMAKE_CXX_COMPILER=clang++-9 \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
-DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \
-DCOMPILER_GYM_LLVM_PROVIDER=external \
-DLLVM_DIR=$HOME/llvm/lib/cmake/llvm \
-DPython3_FIND_VIRTUALENV=FIRST \
-DCOMPILER_GYM_BUILD_TESTS=ON \
-DCOMPILER_GYM_BUILD_EXAMPLES=ON \
Expand Down Expand Up @@ -345,42 +360,6 @@ jobs:
uses: codecov/codecov-action@v2

test-gcc-env-macos:
needs: build-macos
runs-on: macos-latest
steps:
- uses: docker-practice/actions-setup-docker@master

- name: Confirm docker install
run: docker version

- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Download Python wheel
uses: actions/download-artifact@v2
with:
name: macos-wheel

- name: Install wheel
run: python -m pip install *.whl

- name: Install runtime dependencies
uses: ./.github/actions/install-runtime-dependencies

- name: Install test dependencies
run: python -m pip install -r tests/requirements.txt

- name: Run the test suite
run: make install-test-cov TEST_TARGET="tests/gcc"

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v2

test-gcc-env-macos-no-docker:
needs: build-macos
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -446,11 +425,6 @@ jobs:
needs: build-macos
runs-on: macos-latest
steps:
- uses: docker-practice/actions-setup-docker@master

- name: Confirm docker install
run: docker version

- uses: actions/checkout@v2

- name: Set up Python
Expand Down
57 changes: 30 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(DARWIN TRUE)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(compiler_gym ASM C CXX)

set(CMAKE_C_STANDARD 11 CACHE STRING "C standard to be used.")
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to be used.")

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake)

# Project features.
set(COMPILER_GYM_BUILD_TESTS OFF CACHE BOOL "Enable Compiler Gym tests.")
set(COMPILER_GYM_BUILD_EXAMPLES OFF CACHE BOOL "Enable Comiler Gym examples.")

include(cg_macros)
include(cg_copts)
include(cg_genrule)
include(cg_cc_binary)
include(cg_cc_library)
include(cg_cc_test)
include(cg_py_binary)
include(cg_py_library)
include(cg_py_test)
include(cg_python)
include(cg_add_all_subdirs)
include(cg_filegroup)
include(grpc)
include(protobuf)

set(COMPILER_GYM_PYTHONPATH "$ENV{PYTHONPATH}"
# Toolchain configuration.
include(build_tools/cmake/FindAndEnableCcache.cmake)
include(build_tools/cmake/FindAndEnableLld.cmake)

include(build_tools/cmake/cg_macros.cmake)
include(build_tools/cmake/cg_copts.cmake)
include(build_tools/cmake/cg_genrule.cmake)
include(build_tools/cmake/cg_cc_binary.cmake)
include(build_tools/cmake/cg_cc_library.cmake)
include(build_tools/cmake/cg_cc_test.cmake)
include(build_tools/cmake/cg_py_binary.cmake)
include(build_tools/cmake/cg_py_library.cmake)
include(build_tools/cmake/cg_py_test.cmake)
include(build_tools/cmake/cg_python.cmake)
include(build_tools/cmake/cg_add_all_subdirs.cmake)
include(build_tools/cmake/cg_filegroup.cmake)
include(build_tools/cmake/grpc.cmake)
include(build_tools/cmake/protobuf.cmake)

# Set up the build Python path.
set(COMPILER_GYM_BUILD_PYTHONPATH "$ENV{PYTHONPATH}"
CACHE STRING "PYTHONPATH environment variable during build step."
)
if(COMPILER_GYM_PYTHONPATH)
string(PREPEND COMPILER_GYM_PYTHONPATH ":")
if(COMPILER_GYM_BUILD_PYTHONPATH)
string(PREPEND COMPILER_GYM_BUILD_PYTHONPATH ":")
endif()
string(PREPEND COMPILER_GYM_PYTHONPATH "${CMAKE_BINARY_DIR}")
include(set_command_pythonpath)
string(PREPEND COMPILER_GYM_BUILD_PYTHONPATH "${CMAKE_BINARY_DIR}")
include(build_tools/cmake/set_command_pythonpath.cmake)

set(DEFAULT_CMAKE_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
Expand All @@ -71,11 +71,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
find_package(Python3 REQUIRED COMPONENTS Interpreter)

include(external/external.cmake)

add_subdirectory(compiler_gym)

if(COMPILER_GYM_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if(COMPILER_GYM_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
23 changes: 19 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,24 @@ By default most dependencies are built together with Compiler Gym. To search for
* `COMPILER_GYM_GLOG_PROVIDER`
* `COMPILER_GYM_GRPC_PROVIDER`
* `COMPILER_GYM_GTEST_PROVIDER`
* `COMPILER_GYM_LLVM_PROVIDER`
* `COMPILER_GYM_NLOHMANN_JSON_PROVIDER`
* `COMPILER_GYM_PROTOBUF_PROVIDER`

```bash
cmake -GNinja \
cmake \
-DCMAKE_C_COMPILER=clang-9 \
-DCMAKE_CXX_COMPILER=clang++-9 \
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ # For faster rebuilds, can be removed
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \ # For faster builds, can be removed
-DPython3_FIND_VIRTUALENV=FIRST \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=true \
-S "<path to source directory>" \
-B "<path to build directory>"

cmake --build "<path to build directory>"
cmake --build "<path to build directory>"

pip install <path to build directory>/py_pkg/dist/compiler_gym*.whl --force-reinstall
```

Additional optional configuration arguments:

* Enables testing.
Expand Down Expand Up @@ -168,3 +168,18 @@ Additional optional configuration arguments:
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
```

By default, CompilerGym builds LLVM from source. This takes a long time and a
lot of compute resources. To prevent this, download a pre-compiled clang+llvm
release of LLVM 10.0.0 from the [llvm-project releases
page](https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.0), unpack
it, and pass path of the `lib/cmake/llvm` subdirectory in the archive you just
extracted to `LLVM_DIR`:

```
$ cmake ... \
-DCOMPILER_GYM_LLVM_PROVIDER=external \
-DLLVM_DIR=/path/to/llvm/lib/cmake/llvm
```

⚠️ CompilerGym requires exactly LLVM 10.0.0.
6 changes: 6 additions & 0 deletions PreLoad.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "Generator to use" FORCE)
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ boost_deps()

http_archive(
name = "programl",
sha256 = "c56360aade351eda1c138a594177fcb7cd2cda2a0a6c5c0d9aa62c7f856194bd",
strip_prefix = "ProGraML-4f0981d7a0d27aecef3d6e918c886642b231562d",
urls = ["https://github.com/ChrisCummins/ProGraML/archive/4f0981d7a0d27aecef3d6e918c886642b231562d.tar.gz"],
sha256 = "704826311b842b3ffc2dedcce593fdd319d76e95bdf5386985768007ebb22316",
strip_prefix = "ProGraML-83f00233b04f4ecf7f12a79c80ffe23c2953913f",
urls = ["https://github.com/ChrisCummins/ProGraML/archive/83f00233b04f4ecf7f12a79c80ffe23c2953913f.tar.gz"],
)

load("@programl//tools:bzl/deps.bzl", "programl_deps")
Expand Down
13 changes: 13 additions & 0 deletions build_tools/cmake/FindAndEnableCcache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

find_program(CCACHE ccache)
if(CCACHE)
message("Found ccache: ${CCACHE}")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
else()
message("ccache not found")
endif()
14 changes: 14 additions & 0 deletions build_tools/cmake/FindAndEnableLld.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

find_program(LLD lld)
if(LLD)
message("Found lld: ${LLD}")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=${LLD}")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=${LLD}")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=${LLD}")
else()
message("lld not found")
endif()
2 changes: 1 addition & 1 deletion build_tools/cmake/FindProGraML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ find_library(
)
find_path(
ProGraML_proto_programl_cc_INCLUDE_DIRS
programl/proto/program_graph_options.pb.h
programl/proto/program_graph.pb.h
)
if(
ProGraML_proto_programl_cc_LIBRARIES
Expand Down
4 changes: 4 additions & 0 deletions build_tools/cmake/cg_py_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# TODO(github.com/facebookresearch/CompilerGym/issues/621): Gersemi fails.
# gersemi: off

include(CMakeParseArguments)
include(cg_installed_test)
Expand Down Expand Up @@ -85,3 +87,5 @@ function(cg_py_test)
# CMake seems to not allow build targets to be dependencies for tests.
# One way to achieve this is to make the test execution a target.
endfunction()

# gersemi: on
5 changes: 5 additions & 0 deletions build_tools/cmake/cg_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# TODO(github.com/facebookresearch/CompilerGym/issues/621): Gersemi fails.
# gersemi: off

include(CMakeParseArguments)
include(cg_installed_test)

Expand Down Expand Up @@ -205,3 +208,5 @@ function(cg_pyext_module)
endif()
endif()
endfunction()

# gersemi: on
5 changes: 2 additions & 3 deletions build_tools/cmake/set_command_pythonpath.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

include(CMakeParseArguments)

function(set_command_pythonpath)
cmake_parse_arguments(_ARG "" "COMMAND;RESULT" "" ${ARGN})

if(COMPILER_GYM_PYTHONPATH)
if(COMPILER_GYM_BUILD_PYTHONPATH)
set(${_ARG_RESULT}
"\"${CMAKE_COMMAND}\" -E env \"PYTHONPATH=${COMPILER_GYM_PYTHONPATH}\" ${_ARG_COMMAND}"
"\"${CMAKE_COMMAND}\" -E env \"PYTHONPATH=${COMPILER_GYM_BUILD_PYTHONPATH}\" ${_ARG_COMMAND}"
PARENT_SCOPE
)
else()
Expand Down
16 changes: 0 additions & 16 deletions compiler_gym/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,9 @@

cg_add_all_subdirs()

# This target trickery with compiler_gym and compiler_gym_partial
# is needed because specs.py imports the compiler_gym module,
# therefore creating a circular dependency.
# compiler_gym_partial is all the other bits of the proto package so that
# specs.py can import it.
cg_py_library(
NAME
compiler_gym
GENERATED_SRCS
"$<TARGET_PROPERTY:compiler_gym__envs__llvm__specs,LOCATION>"
DEPS
::compiler_gym_partial
compiler_gym::envs::llvm::specs
PUBLIC
)

cg_py_library(
NAME
compiler_gym_partial
SRCS
"__init__.py"
DEPS
Expand Down
Loading