-
Notifications
You must be signed in to change notification settings - Fork 242
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
Fix openr.thrift Python Module Build #96
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (c) 2014-present, Facebook, Inc. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
# | ||
|
||
source "$(dirname "$0")/common.sh" | ||
|
||
alias thrift1=/opt/facebook/fbthrift/bin/thrift1 | ||
|
||
# Step 1: Stage compilation | ||
|
||
# folly Cython | ||
mkdir ./folly | ||
cp -r \ | ||
/tmp/fbcode_builder_getdeps-ZsrcZbuildZfbcode_builder-root/repos/github.com-facebook-folly.git/folly/python/* ./folly | ||
|
||
# fb303 thrift | ||
mkdir -p ./fb303-thrift | ||
cp -r /opt/facebook/fb303/include/thrift-files/fb303 ./fb303-thrift/ | ||
|
||
# fbzmq thrift | ||
mkdir -p ./fbzmq-thrift/fbzmq | ||
cp -r /opt/facebook/fbzmq/include/fbzmq/service ./fbzmq-thrift/fbzmq/ | ||
|
||
# fbthrift Cython and thrift | ||
cp -r /opt/facebook/fbthrift/include/thrift/lib/ ./thrift | ||
touch ./thrift/py3/__init__.py | ||
touch ./thrift/__init__.py | ||
|
||
mkdir /src/fbthrift-thrift | ||
cp -r \ | ||
/tmp/fbcode_builder_getdeps-ZsrcZbuildZfbcode_builder-root/repos/github.com-facebook-fbthrift.git/thrift/lib/thrift/* \ | ||
/src/fbthrift-thrift | ||
|
||
mkdir -p /src/thrift/py3 | ||
chown -R root /tmp/fbcode_builder_getdeps-ZsrcZbuildZfbcode_builder-root/repos/github.com-facebook-fbthrift.git/thrift/lib/py3/ | ||
cp -r \ | ||
/tmp/fbcode_builder_getdeps-ZsrcZbuildZfbcode_builder-root/repos/github.com-facebook-fbthrift.git/thrift/lib/py3/* \ | ||
/src/thrift/py3 | ||
touch /src/thrift/__init__.py | ||
|
||
# Open/R thrift | ||
mkdir -p ./openr-thrift/openr | ||
cp -r /src/openr/if/ ./openr-thrift/openr/ | ||
|
||
# Neteng thrift | ||
mkdir -p neteng-thrift/configerator/structs/neteng/config/ | ||
cp -r \ | ||
/tmp/fbcode_builder_getdeps-ZsrcZbuildZfbcode_builder-root/repos/github.com-facebook-openr.git/configerator/structs/neteng/config/routing_policy.thrift \ | ||
neteng-thrift/configerator/structs/neteng/config/ | ||
|
||
# HACK TO FIX CYTHON .pxd | ||
cp /cython/Cython/Includes/libcpp/utility.pxd /usr/lib/python3/dist-packages/Cython/Includes/libcpp/utility.pxd | ||
|
||
# Step 2. Generate mstch_cpp2 and mstch_py3 bindings | ||
|
||
python3 /src/build/gen.py | ||
|
||
# HACK TO FIX fbthrift-py/gen-cpp2/ | ||
echo " " > /src/fbthrift-thrift/gen-cpp2/metadata_metadata.h | ||
echo " " > /src/fbthrift-thrift/gen-cpp2/metadata_types.h | ||
echo " " > /src/fbthrift-thrift/gen-cpp2/metadata_types_custom_protocol.h | ||
|
||
# Step 3. Generate clients.cpp | ||
|
||
python3 /src/build/cython_compile.py | ||
|
||
# Step 4. Compile .so | ||
|
||
CC="/usr/bin/gcc-10" \ | ||
CXX="/usr/bin/g++-10" \ | ||
CFLAGS="-I. -Iopenr-thrift -Ifb303-thrift -Ifbzmq-thrift -Ineteng-thrift -std=c++20 -fcoroutines " \ | ||
CFLAGS="$CFLAGS -w -D_CPPLIB_VER=20" \ | ||
CXXFLAGS="$CFLAGS" \ | ||
python3 openr/py/setup.py build -j10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (c) 2014-present, Facebook, Inc. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
# | ||
|
||
GETDEPS="$(dirname "$0")/fbcode_builder/getdeps.py" | ||
INSTALL_PREFIX="/opt/facebook" | ||
PYTHON3=$(command -v python3) | ||
PIP3=$(command -v pip3) | ||
EXTRA_CMAKE_DEFINES='{"CMAKE_POSITION_INDEPENDENT_CODE": "ON"}' | ||
|
||
errorCheck() { | ||
return_code=$? | ||
if [ $return_code -ne 0 ]; then | ||
echo "[ERROR]: $1" | ||
exit $return_code | ||
fi | ||
} | ||
|
||
if [ "$PYTHON3" == "" ]; then | ||
echo "ERROR: No \`python3\` in PATH" | ||
exit 1 | ||
fi | ||
|
||
if [ "$PIP3" == "" ]; then | ||
echo "ERROR: No \`pip3\` in PATH" | ||
exit 2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
from subprocess import Popen, check_call | ||
|
||
thrift_files = [] | ||
procs = [] | ||
for root, dirs, files in os.walk('openr-thrift'): | ||
for f in files: | ||
if f.endswith(".pyx"): | ||
thrift_file = os.path.join(root, f) | ||
cmd = \ | ||
[ | ||
"cython3", | ||
"--fast-fail", | ||
"-3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this even an option anymore :P |
||
"--cplus", | ||
thrift_file, | ||
"-o", | ||
root, | ||
"-I.", | ||
"-I/src", | ||
"-I/usr/lib/python3/dist-packages/Cython/Includes", | ||
"-I/src/fbthrift-thrift/gen-py3", | ||
"-I/src/fb303-thrift/fb303/thrift/gen-py3", | ||
"-I/src/neteng-thrift/configerator/structs/neteng/config/gen-py3", | ||
] | ||
print(f"Generating cython module {f}") | ||
procs += [Popen( cmd)] | ||
|
||
print("Waiting for cython generation to finish...") | ||
failures = 0 | ||
for proc in procs: | ||
proc.wait() | ||
if proc.returncode != 0: | ||
failures += 1 | ||
print(f"{len(procs) - failures}/{len(procs)} succeeded") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
from subprocess import check_call | ||
|
||
def generate_thrift_files(): | ||
""" | ||
Get list of all thrift files (absolute path names) and then generate | ||
python definitions for all thrift files. | ||
""" | ||
|
||
thrift_dirs = [ | ||
"openr-thrift", | ||
"fb303-thrift", | ||
"fbzmq-thrift", | ||
"fbthrift-thrift", | ||
"neteng-thrift", | ||
] | ||
generators = ['mstch_cpp2', 'py', 'mstch_py3'] | ||
includes = [ | ||
"openr-thrift", | ||
"fb303-thrift", | ||
"fbzmq-thrift", | ||
"neteng-thrift", | ||
"fbthrift-thrift", | ||
".", | ||
] | ||
|
||
# Find .thrift files | ||
thrift_files = [] | ||
for thrift_dir in thrift_dirs: | ||
for root, dirs, files in os.walk(thrift_dir): | ||
for file in files: | ||
if file.endswith(".thrift"): | ||
thrift_files += [os.path.join(root, file)] | ||
|
||
# Generate cpp and python | ||
for gen in generators: | ||
cmd = ["/opt/facebook/fbthrift/bin/thrift1", '--gen', gen] | ||
for include in includes: | ||
cmd += ["-I", f"{include}"] | ||
for thrift_file in thrift_files: | ||
check_call([*cmd, '-o', os.path.join(os.path.dirname(thrift_file)), str(thrift_file)]) | ||
|
||
# Add __init__.py for compiling cython modules | ||
for include in includes: | ||
for root, dirs, files in os.walk(f"{include}"): | ||
for f in files: | ||
check_call( | ||
[ | ||
"touch", | ||
os.path.join(root, os.path.dirname(f), '__init__.py') | ||
] | ||
) | ||
|
||
generate_thrift_files() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we really need to do this. Our image is way to big.