Skip to content

build: enable OSX builds#1346

Merged
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
turbinelabs:osx-bazel-support
Jul 31, 2017
Merged

build: enable OSX builds#1346
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
turbinelabs:osx-bazel-support

Conversation

@zuercher
Copy link
Copy Markdown
Member

Copies in bazel/tools/osx for xcode support. Fixes bugs related to ar and strip flags.

Modifies build-related shell scripts to account for flag differences between GNU and
OSX command line tools.

Disables tcmalloc on OSX and removes various linker flags incompatible linker flags.

Partially fixes #128.

Copies in bazel/tools/osx for xcode support. Fixes bugs related to ar and strip flags.

Modifies build-related shell scripts to account for flag differences between GNU and
OSX command line tools.

Disables tcmalloc on OSX and removes various linker flags incompatible linker flags.
mattklein123
mattklein123 previously approved these changes Jul 27, 2017
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks @zuercher. LGTM. @htuch or @lizan can you take a look?

@zuercher zuercher mentioned this pull request Jul 28, 2017
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

@zuercher what should I expect after this PR? sucessful build for deps?

One missing shell script fix is the use of realpath, OSX doesn't have it, if it is needed to be installed, document it.

bazel/osx/BUILD Outdated
-framework Foundation -o $@ $<
"""

genrule(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this genrule hasn't been changed from the original one, and original one has public visibility. Can it just be referred from @bazel_tools//tools/osx ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This combined with the code in #1348 should let you build and test on OSX. By itself it just shouldn't break the linux build, I guess.

I'll try to remove some stuff from bazel/osx again -- I had trouble before that I though was related to sandboxing, but I may have been mistaken.

Will add a note about installing realpath.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think @bazel_tools is defined by Bazel. The only way to do this would be to include the Bazel git tree as a git_repository and then reference these files. I think that would be reasonable to do for unchanged subtrees. Looking below, I think it might make sense to do this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is fine if it doesn't work, assuming it is just a temporary workaround until upstream solves it.

@htuch @bazel_tools is definitely defined by bazel itself, try run bazel build @bazel_tools//tools/cpp:stl ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, neat. I could have sworn that in the past that didn't work. In that case, I agree with what you say, we should use references to @bazel_tools for the unmodified files (where they don't have modified dependencies).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

FWIW, I could revert the change that enables the darwin compiler toolchain and turn that on in the PR with all the other necessary changes to get it compiling under OSX.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was able to remove most of the copied bazel files. I've left the configure_osx_toolchain invocation in cc_configure.bzl.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Awesome @zuercher. Thanks for getting this to build. My main feedback is that in places that we do things differently or can't support what's done on Linux, that we document and file tracking issues or add TODOs so we can fix things later if possible.

# Compute the final linkopts based on various options.
def envoy_linkopts():
return select({
"//bazel/osx:darwin": [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How come we aren't providing pertinent link options here on OS X? Can we still get the appropriate build hash and libraries linked statically? I assume so as tests pass, but I'm confused why we don't need to provide explicit link options.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OS X system libraries are distributed exclusively as dynamically loaded libraries. So, all the thirdparty dependencies (e.g. ci/build_container/build_recipes) are linked statically, but the binary links libc++ and libSystem dynamically. That second library dynamically links libraries for libpthread and libuuid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As far as build hash goes, the --build-id flag to ld requests create of a ".note.gnu.build-id" ELF note section. Not sure if OS X's Mach-O format supports something similar or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think one could inject a custom section into the mach-o executable by adding a flag to ld. Something like -sectcreate __TEXT __build_id file. And then git_rewrite_sha.py could be modified to update it with the git SHA.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Personally I would just put in a TODO. This is really only useful in a production setting when dealing with core dumps.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a TODO.

repository + "//bazel:dbg_build": ["-ggdb3"],
}) + select({
repository + "//bazel:disable_tcmalloc": [],
"//bazel/osx:darwin": [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the permanent plan? Does gperftools support OS X? tcmalloc has some performance advantages in addition to performance insight via the tools.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I cribbed this from @Reflejo's old branch. I believe he encountered problems with tcmalloc deadlocking (c.f. #128 (comment)).

I'm game to try turning it on.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seems to work, so I put it back in.

bazel/osx/BUILD Outdated
-framework Foundation -o $@ $<
"""

genrule(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think @bazel_tools is defined by Bazel. The only way to do this would be to include the Bazel git tree as a git_repository and then reference these files. I think that would be reasonable to do for unchanged subtrees. Looking below, I think it might make sense to do this.

print 'Usage: %s <Envoy binary path> ' % sys.argv[0]
sys.exit(1)
if platform.system() == 'Darwin':
print 'Stamping not supported on OSX'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the limitation here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At a minimum, OS X binaries are not ELF format, so this particular tool will not work. I don't know enough about Mach-O to say whether it's possible to do something similar.

@htuch
Copy link
Copy Markdown
Member

htuch commented Jul 28, 2017 via email

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM modulo small comment request.

return select({
# TODO(zuercher): build id could be supported via "-sectcreate __TEXT __build_id <file>"
# The file could should contain the current git SHA (or enough placeholder data to allow
# it to be rewritten by tools/git_sha_rewriter.py).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you also include a comment on how static/system libs work on OS X?

@htuch
Copy link
Copy Markdown
Member

htuch commented Jul 28, 2017

@zuercher Can you file issues with https://github.com/bazelbuild/bazel/issues for the static link issue if you haven't already and add references to that in this commit? Ideally these get fixes one day upstream and we can unwind our hacks. Here's the issue I filed to track the Linux stuff bazelbuild/bazel#2840.

@zuercher
Copy link
Copy Markdown
Member Author

zuercher commented Jul 30, 2017

@htuch I apologize. The ar bug is fixed in upstream bazel. I thought it hadn't because the incorrect flags I was modifing are still there. In 0.5.2, they just don't get used for some reason.

The strip bug has already been reported by someone else as bazelbuild/bazel#209. If not for that bug, we could use bazel 0.5.2's configure_osx_toolchain without modification.

I modified the bazel/osx/crosstool bits to use the 0.5.2 CROSSTOOL.tpl with just my fix for stripping and added diff headers referring to the strip bug and the git tag the files came from.

tool {
tool_path: "wrapped_clang"
execution_requirement: "requires-darwin"
tool_path: "DUMMY_TOOL"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit confused by the introduction of DUMMY_TOOL here - it doesn't appear to be in crosstool.tpl.diff or in the upstream https://github.com/bazelbuild/bazel/blob/master/tools/osx/crosstool/CROSSTOOL.tpl.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted to submit a simple project as a test case for the ar bug, but after I was unable to reproduce it, I realized that the 0.5.2 tag is not bazelbuild/bazel@7b85122, the latter being the SHA from which other stuff was copied.

I think what's happened is that a 0.5.2 release branch was started, and the ar bug was fixed there. Meanwhile in master the DUMMY_TOOL entries were removed (presumably because they weren't being used) and the ar bug was also fixed there, but after 7b85122c. I'm at a loss to explain what actually fixes the bug or why the DUMMY_TOOL entries don't seem to bother anything.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

And I should add, I copied this CROSSTOOL.tpl from the 0.5.2 tag, hence the older DUMMY_TOOL entries.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zuercher I don't know any of the details here, but FYI 0.5.3 is out of that changes anything.

@htuch
Copy link
Copy Markdown
Member

htuch commented Jul 30, 2017

@zuercher Sounds good on the upstream story. Could you also leave a comment on bazelbuild/bazel#209 to remind folks this is also affecting Envoy? Thanks.

@zuercher
Copy link
Copy Markdown
Member Author

So, the CROSSTOOL.tpl from 0.5.2 had didn't work with the just-released 0.5.3. However, the 0.5.3 version (plus the strip fix) works in 0.5.2.

I think all the comments are addressed at this point.

@mattklein123 mattklein123 merged commit ef08a87 into envoyproxy:master Jul 31, 2017
@zuercher zuercher deleted the osx-bazel-support branch August 10, 2017 16:07
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: #1338 changed argv, but kept argc the same. This PR updates command line args to no longer depend on a hardcoded value.
Risk Level: low
Testing: local build to make sure all command line args were being respected.

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: #1338 changed argv, but kept argc the same. This PR updates command line args to no longer depend on a hardcoded value.
Risk Level: low
Testing: local build to make sure all command line args were being respected.

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
mathetake pushed a commit that referenced this pull request Mar 3, 2026
)

**Description**

This completes metrics and tracing and updates docs. So, now
/v1/completions is complete!

**Related Issues/PRs (if applicable)**

Fixes #1231

---------

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSX support

4 participants