Skip to content

Commit 393947e

Browse files
authored
Use CMake's FetchContent to install third_party dependencies (#68)
Use CMake's FetchContent to install third_party dependencies & remove git submodules. Managing software versions within a build allows for more easily reproducible builds.
1 parent a0bf06b commit 393947e

File tree

9 files changed

+48
-51
lines changed

9 files changed

+48
-51
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ jobs:
3636
software-properties-common
3737
fi
3838
- uses: actions/checkout@v4
39-
with:
40-
submodules: true
4139
- name: Install from repo in test mode
4240
run: pip install -e '.[dev]'
4341
- name: Run tests
@@ -54,8 +52,6 @@ jobs:
5452
- name: Ensure latest pip, wheel & setuptools
5553
run: python -m pip install -q --upgrade pip wheel setuptools
5654
- uses: actions/checkout@v4
57-
with:
58-
submodules: true
5955
- name: Generate sdist
6056
run: |
6157
NLE_RELEASE_BUILD=1 python setup.py sdist
@@ -82,8 +78,6 @@ jobs:
8278
- name: Ensure latest pip, wheel & setuptools
8379
run: python -m pip install -q --upgrade pip wheel setuptools
8480
- uses: actions/checkout@v4
85-
with:
86-
submodules: true
8781
- name: Generate sdist
8882
run: |
8983
NLE_RELEASE_BUILD=1 python setup.py sdist
@@ -113,8 +107,6 @@ jobs:
113107
os: [ubuntu-latest, ubuntu-24.04-arm]
114108
steps:
115109
- uses: actions/checkout@v4
116-
with:
117-
submodules: recursive
118110
- name: Build wheels
119111
if: github.event_name != 'release'
120112
uses: pypa/cibuildwheel@v3.1.3 # The main configuration is in pyproject.toml
@@ -147,8 +139,6 @@ jobs:
147139
- name: Ensure latest pip, wheel & setuptools
148140
run: python -m pip install -q --upgrade pip wheel tools
149141
- uses: actions/checkout@v4
150-
with:
151-
submodules: true
152142
- name: Get wheels artifacts
153143
uses: actions/download-artifact@v4
154144
with:

.gitmodules

Lines changed: 0 additions & 9 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.28)
22
file(STRINGS "version.txt" NLE_VERSION)
33
# Remove any rcXX suffix from the version number as CMake doesn't like it
44
string(REGEX REPLACE "rc[0-9+]$" "" CMAKE_NLE_VERSION ${NLE_VERSION})
@@ -53,6 +53,22 @@ message(STATUS "HACKDIR set to: ${HACKDIR}")
5353
set(VARDIR ${HACKDIR})
5454
set(INSTDIR ${HACKDIR})
5555

56+
# pybind11 via FetchContent
57+
include(FetchContent)
58+
FetchContent_Declare(
59+
pybind11
60+
GIT_REPOSITORY https://github.com/pybind/pybind11.git
61+
GIT_TAG v3.0.1
62+
EXCLUDE_FROM_ALL)
63+
FetchContent_MakeAvailable(pybind11)
64+
65+
# de-boost-ified version of boost.context via FetchContent
66+
FetchContent_Declare(
67+
deboost_context
68+
GIT_REPOSITORY https://github.com/septag/deboost.context.git
69+
GIT_HASH "259fc4103bad6bb484d5ff426ace56ac557107a4" EXCLUDE_FROM_ALL)
70+
FetchContent_MakeAvailable(deboost_context)
71+
5672
add_compile_definitions(
5773
GCC_WARN
5874
NOCLIPPING
@@ -78,9 +94,6 @@ set(NLE_DAT_GEN ${nle_BINARY_DIR}/dat)
7894
set(NLE_UTIL_GEN ${nle_BINARY_DIR}/util)
7995

8096
set(CMAKE_INSTALL_MESSAGE LAZY) # Don't tell us about up-to-date files.
81-
82-
# EXCLUDE_FROM_ALL: Don't install this static library into /usr/local.
83-
add_subdirectory(third_party/deboost.context EXCLUDE_FROM_ALL)
8497
add_subdirectory(util)
8598
add_subdirectory(dat)
8699

@@ -96,17 +109,27 @@ file(
96109
"win/tty/*.c"
97110
"win/rl/winrl.cc")
98111

99-
# static version of bzip2 library
100-
add_library(
101-
bz2_static STATIC
102-
"third_party/bzip2/blocksort.c"
103-
"third_party/bzip2/bzlib.c"
104-
"third_party/bzip2/compress.c"
105-
"third_party/bzip2/crctable.c"
106-
"third_party/bzip2/decompress.c"
107-
"third_party/bzip2/huffman.c"
108-
"third_party/bzip2/randtable.c")
109-
target_link_libraries(bz2_static)
112+
# FetchContent for bzip2
113+
include(FetchContent)
114+
FetchContent_Declare(
115+
bzip2
116+
GIT_REPOSITORY git://sourceware.org/git/bzip2.git
117+
GIT_HASH fbc4b11da543753b3b803e5546f56e26ec90c2a7 EXCLUDE_FROM_ALL)
118+
FetchContent_MakeAvailable(bzip2)
119+
120+
# Manually add bzip2 source files from the downloaded directory
121+
set(BZIP2_SRC
122+
${bzip2_SOURCE_DIR}/blocksort.c
123+
${bzip2_SOURCE_DIR}/bzlib.c
124+
${bzip2_SOURCE_DIR}/compress.c
125+
${bzip2_SOURCE_DIR}/crctable.c
126+
${bzip2_SOURCE_DIR}/decompress.c
127+
${bzip2_SOURCE_DIR}/huffman.c
128+
${bzip2_SOURCE_DIR}/randtable.c)
129+
130+
# EXCLUDE_FROM_ALL: Don't install this static library into /usr/local.
131+
add_library(bz2_static STATIC EXCLUDE_FROM_ALL ${BZIP2_SRC})
132+
target_include_directories(bz2_static PUBLIC ${bzip2_SOURCE_DIR})
110133

111134
# terminal emulator library
112135
add_library(tmt STATIC "third_party/libtmt/tmt.c")
@@ -119,8 +142,7 @@ set_target_properties(nethack PROPERTIES CXX_STANDARD 14 SUFFIX ".so")
119142
target_include_directories(
120143
nethack
121144
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${NLE_INC_GEN} /usr/local/include
122-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt
123-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/bzip2)
145+
${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt ${bzip2_SOURCE_DIR})
124146
# target_link_directories(nethack PUBLIC /usr/local/lib)
125147

126148
# Careful with -DMONITOR_HEAP: Ironically, it fails to fclose FILE* heaplog.
@@ -131,9 +153,8 @@ target_link_libraries(nethack PUBLIC m fcontext bz2_static tmt)
131153
# dlopen wrapper library
132154
add_library(nethackdl STATIC "sys/unix/nledl.c")
133155
target_include_directories(
134-
nethackdl
135-
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
136-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/deboost.context/include)
156+
nethackdl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
157+
${deboost_context_SOURCE_DIR}/include)
137158
target_link_libraries(nethackdl PUBLIC dl)
138159

139160
# rlmain C++ (test) binary
@@ -144,7 +165,6 @@ target_include_directories(rlmain PUBLIC ${NLE_INC_GEN})
144165
add_dependencies(rlmain util) # For pm.h.
145166

146167
# pybind11 core python library.
147-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/pybind11)
148168
pybind11_add_module(
149169
_pynethack
150170
win/rl/pynethack.cc
@@ -165,8 +185,7 @@ add_library(
165185
target_include_directories(
166186
converter
167187
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt
168-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/converter
169-
${CMAKE_CURRENT_SOURCE_DIR}/third_party/bzip2)
188+
${CMAKE_CURRENT_SOURCE_DIR}/third_party/converter ${bzip2_SOURCE_DIR})
170189
target_link_libraries(converter PUBLIC bz2_static tmt)
171190
if(CMAKE_BUILD_TYPE MATCHES Debug)
172191
target_compile_options(converter PRIVATE -Wall -Wextra -pedantic -Werror)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ with other gym (or Gynmasium) / RL environments.
3737

3838
## Installation
3939

40-
NLE requires `python>=3.10`, `cmake>=3.18` to be installed and available both when building the
40+
NLE requires `python>=3.10`, `cmake>=3.28` to be installed and available both when building the
4141
package, and at runtime.
4242

4343
On **MacOS**, one can use `Homebrew` as follows:
@@ -75,7 +75,7 @@ $ pip install nle
7575
NOTE: If you want to extend / develop NLE, please install the package as follows:
7676

7777
``` bash
78-
$ git clone https://github.com/NetHack-LE/nle --recursive
78+
$ git clone https://github.com/NetHack-LE/nle
7979
$ pip install -e ".[dev]"
8080
$ pre-commit install
8181
```

doc/nle/source/getting_started.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Getting Started
44
Dependencies
55
************
66

7-
NLE requires `python>=3.10`, `cmake>=3.18` and some NetHack dependencies
7+
NLE requires `python>=3.10`, `cmake>=3.28` and some NetHack dependencies
88
(e.g. `libncurses`) to be installed and available both when building the
99
package, and at runtime.
1010

@@ -47,7 +47,7 @@ Optionally, one can clone the repository and install the package manually.
4747

4848
.. code-block:: bash
4949
50-
$ git clone https://github.com/NetHack-LE/nle --recursive
50+
$ git clone https://github.com/NetHack-LE/nle
5151
$ conda activate nledev
5252
$ pip install .
5353

docker/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To build and run an image (e.g. `Dockerfile-jammy`) for your local
1515
architecture do:
1616

1717
```bash
18-
$ git clone https://github.com/NetHack-LE/nle --recursive
18+
$ git clone https://github.com/NetHack-LE/nle
1919
$ cd nle
2020
$ docker build --file docker/Dockerfile-jammy . --tag nle
2121
$ docker run -it --gpus all --rm --name nle nle
@@ -34,4 +34,4 @@ $ docker buildx build --platform linux/amd64,linux/arm64 -t nle -f docker/Docker
3434
```
3535

3636
The run instructions are as before. Docker will load the correct
37-
binaries for the architecture you are running the container on.
37+
binaries for the architecture you are running the container on.

third_party/bzip2

Lines changed: 0 additions & 1 deletion
This file was deleted.

third_party/deboost.context

Lines changed: 0 additions & 1 deletion
This file was deleted.

third_party/pybind11

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)