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

Add support for building on Mac OS X #2433

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
96c5487
Checkpoint Mac build support
analog-cbarber Aug 16, 2018
e069582
Add mac build instructions
analog-cbarber Aug 17, 2018
6c1f4f1
Merge branch 'master' into mac-build-0.9
analog-cbarber Aug 23, 2018
0bf0356
Allow Xcode version >= 9.2 in Mac Setup.command
analog-cbarber Aug 23, 2018
ac2759f
On the Mac, build using Xcode by default
analog-cbarber Aug 23, 2018
4ca1f03
Merge branch 'master' into mac-build-0.9
analog-cbarber Aug 24, 2018
6a596cb
Fix LibCarla tests for mac builds (issue #150)
analog-cbarber Aug 24, 2018
af117d6
Fix `make check` for mac build (issue #150)
analog-cbarber Aug 24, 2018
9e56a3d
Checkpoint merge from master
analog-cbarber Feb 9, 2019
9a8bc24
Checkpoint Mac build changes
analog-cbarber Feb 17, 2019
91e24c4
Adding missing link commands to setup.py for mac
analog-cbarber Feb 17, 2019
f04049a
Workaround pygame font issue on mac in manual_control.py
analog-cbarber Feb 17, 2019
a55b18f
Mac platform settings for Unreal
analog-cbarber Feb 18, 2019
65d98f4
Merge branch 'master' into mac-build-0.9
analog-cbarber Feb 18, 2019
f14f8c5
conda recipe for python 3.6
analog-cbarber Feb 18, 2019
b0a12e7
Merge 0.9.4 into mac-build-0.9 branch
analog-cbarber Mar 2, 2019
75a6daf
Fix missing braces warning on Mac
analog-cbarber Mar 2, 2019
39abe9b
Update mac build instructions
analog-cbarber Jul 10, 2019
b277478
fixes
geohot Feb 2, 2020
fcd09dc
add quotes
geohot Feb 2, 2020
be11ac3
more quotes
geohot Feb 2, 2020
8c143df
fixups
geohot Feb 2, 2020
4e8d0bf
command, not sh
geohot Feb 2, 2020
e70767b
didn't need that
geohot Feb 2, 2020
f9d11b1
launch
geohot Feb 3, 2020
c68027d
attempt to merge
geohot Feb 3, 2020
15036b1
setbacks
geohot Feb 3, 2020
f413edd
fix version.h issue
geohot Feb 3, 2020
164fa11
fix types
geohot Feb 3, 2020
44b3e13
extra }
geohot Feb 3, 2020
d97cd3e
mac doesn't use that one
geohot Feb 3, 2020
a112caa
remove unneeded changes
geohot Feb 3, 2020
092817d
recast on os x
geohot Feb 3, 2020
002f603
lane detector is dead code
geohot Feb 3, 2020
2f9e44a
need recast there too
geohot Feb 3, 2020
5f4ddd3
a real fix, and a broken thing
geohot Feb 3, 2020
d7425a8
unify BuildLibCarla
geohot Feb 3, 2020
9212464
unify BuildPythonAPI
geohot Feb 3, 2020
544eb2e
release and clang-7
geohot Feb 3, 2020
6c84278
unify Package
geohot Feb 3, 2020
356e15b
remove dead file
geohot Feb 3, 2020
15b6009
python import works now
geohot Feb 3, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Install
*.so
*.stackdump
*.sublime-workspace
*.swp
*.workspace
*CodeCompletionFolders.txt
*CodeLitePreProcessor.txt
Expand All @@ -45,3 +46,4 @@ _out*
_site
core
profiler.csv
Content.tar.gz
134 changes: 134 additions & 0 deletions Docs/how_to_build_on_mac.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# How to build CARLA on Mac OSX

Note that unlike the Linux build, this one uses the standard Mac compiler tools and
the standard Unreal Engine 4.21 distribution.
Copy link
Author

@geohot geohot Feb 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Change to 4.22


Prerequisites
-------------

### Install Xcode 9.4

*Later versions of Xcode may work, but using the same version that is used by Unreal 4.21 seems a safe bet.*

You should be able to install from [Apple's developer downloads](https://developer.apple.com/download/more/).

If you have installed more than one version of Xcode, you should activate 9.4 using
the `xcode-select` command line utility. This will set `/usr/bin/clang` and `/usr/bin/clang++`
to the appropriate versions, and these are what will be used in the build.

Note that Apple's has it's own clang versioning scheme that tracks the Xcode versions,
so it is not obvious how the features compare to the LLVM distributions, but this version
should fully support c++14 features.

**On Mac OSX Mojave 10.14 you also need to install the MacOS headers using:**

~~~sh
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
~~~

### Install Unreal Engine 4.21

Install the [Epic Games Launcher](https://www.epicgames.com/unrealtournament/download)
and use it to download version 4.21 of the Unreal Engine. The default install location
is `/Users/Shared/Epic Games/`, but it is a good idea to eliminate the space in the path
and instead use `/Users/Shared/EpicGames/` since some tools seem to have problems with
the space.

Although, you don't need to build the engine from source, you do need to add the file
[GenerateProjectFiles.sh](https://github.com/EpicGames/UnrealEngine/blob/4.21/GenerateProjectFiles.sh) to the root directory from a copy of the Unreal Engine source tree.

### Install the build tools and dependencies

~~~sh
$ brew install autoconf curl libtool ninja wget \
libpng
~~~

Use shipping python or install using your favorite method (e.g. brew, download installer from python.org,
Anaconda/miniconda).

If using conda environment:

~~~sh
$ conda install -c conda-forge nose2
~~~

else:

~~~sh
$ pip2 install nose2
~~~

In order for `boost-python` to build properly, you may need to add a `user-config.jam` file
to your home directory describing the location of your python implementations. For instance,
to use the preinstalled python2 and a python 3.6 from python.org installer you might use:

~~~jam
import toolset : using ;

using python : 2.7
: /usr/bin/python2.7
: /usr/include/python2.7
;

using python : 3.6
: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
: /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m
: /Library/Frameworks/Python.framework/Versions/3.6/lib
;
~~~

Currently, the build will only support the first listed python. Eventually, it should
support building apis for multiple python versions.

Build CARLA
-----------

Clone or download the project from our
[GitHub repository](https://github.com/carla-simulator/carla)

```sh
git clone https://github.com/carla-simulator/carla
```

Note that the `master` branch contains the latest fixes and features, for the
latest stable code may be best to switch to the latest release tag.

Now you need to download the assets package, to do so we provide a handy script
that downloads and extracts the latest version (note that the package is >12GB,
this step might take some time depending on your connection)

```sh
./Update.sh
```

For CARLA to find your Unreal Engine's installation folder you need to set the
following environment variable

```sh
export UE4_ROOT=/Users/shared/EpicGames/UE_4.21
```

You can also add this variable to your `~/.bashrc` or `~/.profile`.

Now that the environment is set up, you can run make to run different commands

```sh
make launch # Compiles CARLA and launches Unreal Engine's Editor.
make package # Compiles CARLA and creates a packaged version for distribution.
make help # Print all available commands.
```

Updating CARLA
--------------

Every new release of CARLA we release a new package with the latest changes in
the CARLA assets. To download the latest version and recompile CARLA, run

```sh
make clean
git pull
./Update.sh
make launch
```

16 changes: 12 additions & 4 deletions LibCarla/cmake/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,18 @@ if (LIBCARLA_BUILD_RELEASE)

add_library(carla_client STATIC ${libcarla_sources})

target_include_directories(carla_client SYSTEM PRIVATE
"${BOOST_INCLUDE_PATH}"
"${RPCLIB_INCLUDE_PATH}"
"${RECAST_INCLUDE_PATH}")
if (APPLE)
target_include_directories(carla_client SYSTEM PRIVATE
"${BOOST_INCLUDE_PATH}"
"${RPCLIB_INCLUDE_PATH}"
"${RECAST_INCLUDE_PATH}"
"/usr/local/include")
else (APPLE)
target_include_directories(carla_client SYSTEM PRIVATE
"${BOOST_INCLUDE_PATH}"
"${RPCLIB_INCLUDE_PATH}"
"${RECAST_INCLUDE_PATH}")
endif (APPLE)

if (BUILD_RSS_VARIANT)
target_compile_definitions(carla_client PRIVATE RSS_ENABLED)
Expand Down
4 changes: 4 additions & 0 deletions LibCarla/cmake/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ foreach(target ${build_targets})
target_include_directories(${target} PRIVATE
"${libcarla_source_path}/test")

if (APPLE)
target_include_directories(${target} PRIVATE "/usr/local/include")
endif (APPLE)

if (WIN32)
target_link_libraries(${target} "gtest_main.lib")
target_link_libraries(${target} "gtest.lib")
Expand Down
20 changes: 20 additions & 0 deletions LibCarla/source/carla/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ namespace carla {
return static_cast<size_type>(size);
} ()) {}

#ifdef __APPLE__
// On the Mac, std::size_t is unsigned long, where uint64_t
// is unsigned long long. Although both are 64-bits, they are
// distinct types, so this declaration is needed to avoid recursive
// delegation back to the template constructor.
explicit Buffer(std::size_t size)
: Buffer((uint64_t)size) {}
#endif

/// Copy @a source into this buffer. Allocates the necessary memory.
template <typename T>
explicit Buffer(const T &source) {
Expand All @@ -89,6 +98,7 @@ namespace carla {
copy_from(data, size);
}

#ifndef __APPLE__
/// @copydoc Buffer(size_type)
explicit Buffer(const value_type *data, uint64_t size)
: Buffer(data, [size]() {
Expand All @@ -97,6 +107,7 @@ namespace carla {
}
return static_cast<size_type>(size);
} ()) {}
#endif

Buffer(const Buffer &) = delete;

Expand Down Expand Up @@ -263,6 +274,15 @@ namespace carla {
reset(static_cast<size_type>(size));
}

#ifdef __APPLE__
// On the Mac, std::size_t is unsigned long, where uint64_t
// is unsigned long long. Although both are 64-bits, they are
// distinct types, so this declaration is needed.
void reset(std::size_t size) {
reset((uint64_t)size);
}
#endif

/// Release the contents of this buffer and set its size and capacity to
/// zero.
std::unique_ptr<value_type[]> pop() noexcept {
Expand Down
4 changes: 4 additions & 0 deletions LibCarla/source/carla/MsgPack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#include "carla/Buffer.h"

#ifdef __APPLE__
#define MSGPACK_DISABLE_LEGACY_NIL
#endif

#include <rpc/msgpack.hpp>

namespace carla {
Expand Down
6 changes: 3 additions & 3 deletions LibCarla/source/carla/MsgPackAdaptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace adaptor {

private:

template <uint64_t I>
template <unsigned long I>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Make this OS dependent?

static void copy_to_variant_impl(
const clmdep_msgpack::object &o,
boost::variant<Ts...> &v) {
Expand All @@ -115,9 +115,9 @@ namespace adaptor {
v = o.via.array.ptr[1].as<T>();
}

template <uint64_t... Is>
template <unsigned long... Is>
static void copy_to_variant(
const uint64_t index,
const unsigned long index,
const clmdep_msgpack::object &o,
boost::variant<Ts...> &v,
std::index_sequence<Is...>) {
Expand Down
3 changes: 1 addition & 2 deletions LibCarla/source/carla/client/BlueprintLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace client {
/// @todo Works as a list but its actually a map. We should assess the use
/// cases and reconsider this implementation.
class BlueprintLibrary
: public EnableSharedFromThis<BlueprintLibrary>,
private NonCopyable {
: public EnableSharedFromThis<BlueprintLibrary> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this due to a complaint about the move constructor, can look more into it.

using map_type = std::unordered_map<std::string, ActorBlueprint>;
public:

Expand Down
8 changes: 5 additions & 3 deletions LibCarla/source/carla/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "carla/PythonUtil.h"
//#include "carla/PythonUtil.h"
#include "carla/client/World.h"
#include "carla/client/detail/Simulator.h"

Expand Down Expand Up @@ -110,8 +110,10 @@ namespace client {
uint16_t port,
size_t worker_threads)
: _simulator(
new detail::Simulator(host, port, worker_threads),
PythonUtil::ReleaseGILDeleter()) {}
new detail::Simulator(host, port, worker_threads)
) {}
// TODO: pyconfig.h isn't included, so we can't have this
//,PythonUtil::ReleaseGILDeleter()) {}

} // namespace client
} // namespace carla
2 changes: 1 addition & 1 deletion LibCarla/source/carla/road/element/Waypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace std {

using argument_type = carla::road::element::Waypoint;

using result_type = uint64_t;
using result_type = unsigned long;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate based on OS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any problem using uint64_t in Mac?


/// Generates an unique id for @a waypoint based on its road_id, lane_id,
/// section_id, and "s" offset. The "s" offset is truncated to half
Expand Down
8 changes: 4 additions & 4 deletions LibCarla/source/test/common/test_listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ static void TestSequence(carla::ListView<Iterator> view) {
TEST(listview, sequence) {
int array[] = {0, 1, 2, 3, 4, 5};
TestSequence(MakeListView(array));
std::array<int, 6u> std_array = {0, 1, 2, 3, 4, 5};
std::array<int, 6u> std_array = {{0, 1, 2, 3, 4, 5}};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be changed?

TestSequence(MakeListView(std_array));
std::vector<int> vector = {0, 1, 2, 3, 4, 5};
std::vector<int> vector = {{0, 1, 2, 3, 4, 5}};
TestSequence(MakeListView(vector));
std::list<int> list = {0, 1, 2, 3, 4, 5};
std::list<int> list = {{0, 1, 2, 3, 4, 5}};
TestSequence(MakeListView(list));
std::set<int> set = {0, 1, 2, 3, 4, 5};
std::set<int> set = {{0, 1, 2, 3, 4, 5}};
TestSequence(MakeListView(set));
}

Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ include Util/BuildTools/Vars.mk
ifeq ($(OS),Windows_NT)
include Util/BuildTools/Windows.mk
else
include Util/BuildTools/Linux.mk
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
include Util/BuildTools/Mac.mk
else
include Util/BuildTools/Linux.mk
endif
endif
32 changes: 32 additions & 0 deletions PythonAPI/carla/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,38 @@ def walk(folder, file_filter='*'):
include_dirs += ['/usr/lib/gcc/x86_64-linux-gnu/7/include']
library_dirs += ['/usr/lib/gcc/x86_64-linux-gnu/7']
extra_link_args += ['/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a']

elif platform.system() == 'Darwin':
pwd = os.path.dirname(os.path.realpath(__file__))
pylib = "libboost_python%d%d.a" % (sys.version_info.major,
sys.version_info.minor)
extra_link_args = [
os.path.join(pwd, 'dependencies/lib/libcarla_client.a'),
os.path.join(pwd, 'dependencies/lib/librpc.a'),
os.path.join(pwd, 'dependencies/lib/libboost_filesystem.a'),
os.path.join(pwd, 'dependencies/lib/libRecast.a'),
os.path.join(pwd, 'dependencies/lib/libDetour.a'),
os.path.join(pwd, 'dependencies/lib/libDetourCrowd.a'),
os.path.join(pwd, 'dependencies/lib', pylib)]
extra_compile_args = [
'-isystem', 'dependencies/include/system',
'-mmacosx-version-min=10.13',
'-fPIC', '-std=c++14', '-Wno-missing-braces',
'-DBOOST_ERROR_CODE_HEADER_ONLY', '-DLIBCARLA_WITH_PYTHON_SUPPORT',
]
if 'BUILD_RSS_VARIANT' in os.environ and os.environ['BUILD_RSS_VARIANT'] == 'true':
print('Building AD RSS variant.')
extra_compile_args += ['-DLIBCARLA_RSS_ENABLED']
extra_link_args += [os.path.join(pwd, 'dependencies/lib/libad-rss.a')]

if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'true':
print('Travis CI build detected: disabling PNG support.')
extra_link_args += ['-ljpeg', '-ltiff']
extra_compile_args += ['-DLIBCARLA_IMAGE_WITH_PNG_SUPPORT=false']
else:
extra_link_args += ['-lpng', '-ljpeg', '-ltiff']
extra_compile_args += ['-DLIBCARLA_IMAGE_WITH_PNG_SUPPORT=true']

else:
raise NotImplementedError
elif os.name == "nt":
Expand Down
Loading