Opened 7 years ago

Closed 6 years ago

#1190 closed defect (fixed)

Mac bundle builds fail when compiling C code

Reported by: Tristan Croll Owned by: Conrad Huang
Priority: moderate Milestone:
Component: Tool Shed Version:
Keywords: Cc:
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

Clang complains and crashes if you ask it to compile a C file with -std=c++11. While bundle_builder.py currently contains the following:

        if sys.platform == "darwin":
            libraries = self.libraries
            # Unfortunately, clang on macOS (for now) exits
            # when receiving a -std=c++11 option when compiling
            # a C (not C++) source file, which is why this value
            # is named "cpp_flags" not "compile_flags"
            cpp_flags = ["-std=c++11", "-stdlib=libc++"]

... it isn't actually used as such, and cpp_flags just gets attached to every compilation. The following amendment to _CLibrary.compile() is one way to tackle it (here I'm killing two birds with one stone by also parallelising it over all available cores):

        from concurrent.futures import ThreadPoolExecutor
        import os
        results = []
        with ThreadPoolExecutor(max_workers=os.cpu_count()-1) as executor:
            for f in self.source_files:
                l = compiler.detect_language(f)
                if l == 'c':
                    preargs = []
                elif l == 'c++':
                    preargs = cpp_flags
                else:
                    raise RuntimeError('Unsupported language for {}'.format(f))
                results.append(executor.submit(compiler.compile, [f], extra_preargs=preargs, macros=macros, debug=debug))
            #Ensure all have finished before continuing
            for r in results:
                r.result()
        #compiler.compile(self.source_files, extra_preargs=cpp_flags, macros=macros, debug=debug)

Not quite sure how to tackle the same problem with _CModule, though - that's a somewhat different beast.

Attachments (1)

bundle_builder.py (26.6 KB ) - added by Tristan Croll 7 years ago.
Further bug fixes

Download all attachments as: .zip

Change History (5)

by Tristan Croll, 7 years ago

Attachment: bundle_builder.py added

Further bug fixes

comment:1 by Tristan Croll, 7 years ago

A few more enhancements/fixes in the attached:

  • In _CLibrary, extra_link_arguments were not being applied (the argument to compiler.link_shared_object() should be extra_preargs=extra_link_args, not extra_post_args=extra_link_args)
  • In Linux, the rpath link argument needs the dollar sign escaped (i.e. it should be -Wl,-rpath,\$ORIGIN) and it needs to be applied for both _CModule and _CLibrary
  • I went ahead and added a <CompileArgument> field.

comment:2 by Conrad Huang, 6 years ago

Status: assignedfeedback

Has the been resolved as part of another ticket?

in reply to:  4 comment:3 by tic20@…, 6 years ago

Yep - I’ve been using the official bundle builder for months now with no issues.
 

 


comment:4 by Conrad Huang, 6 years ago

Resolution: fixed
Status: feedbackclosed
Note: See TracTickets for help on using tickets.