KLayout / klayout

KLayout Main Sources
http://www.klayout.org
GNU General Public License v3.0
808 stars 206 forks source link

Modified the macOS build system so that the debug build uses ASAN (Adress SANitizer) for clang++ #1788

Closed Kazzz-S closed 4 months ago

Kazzz-S commented 4 months ago
klayoutmatthias commented 4 months ago

Hi @Kazzz-S,

thanks for lot for this PR.

Just one question: why the system call?

  USE_ASAN_MAC = $$system(echo $$(MAC_USE_ASAN))
  equals(USE_ASAN_MAC, "1") {
    ..
  }

I think you could simply use

  equals(MAC_USE_ASAN, "1") {
    ..
  }

Or is there a problem with that?

Matthias

Kazzz-S commented 4 months ago

Hi @klayoutmatthias,

Thank you for reviewing my PR. Yes, the code is intentional. Advised by ChatGPT.

MAC_USE_ASAN is an environment variable defined by build4mac.py on the fly. In other words, it is not a variable_name-value pair (like HAVE_GIT2=1) directly passed to qmake together with *.[pro|pri]. build4mac

If I write the particular part as follows... klayout pri

MacBookPro2{kazzz-s} klayout (1)% ./build4mac.py --debug

### You are going to build KLayout
    for  <Monterey 21.6.0 x86_64>
    with <Qt=Qt5MacPorts, Ruby=RubyMonterey, Python=PythonMonterey>
    with Pymod <disabled>...

{   'BuildPymodWhl': False,
:
    'debug_mode': True,
:
    'ruby': '/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby'}
Scanning installation ..
:
:
Features:
    Qt bindings enabled
    Uses libgit2 for Git access
    Compilation caching is deactivated!
    Installation target: qt5MP.bin.macos-Monterey-debug-RsysPsys
    Build directory: qt5MP.build.macos-Monterey-debug-RsysPsys

    Build flags:
      HAVE_RUBY=1
      HAVE_PYTHON=1
      HAVE_QTBINDINGS=1
      HAVE_QT=1
      HAVE_QT_UITOOLS=1
      HAVE_QT_NETWORK=1
      HAVE_QT_SQL=1
      HAVE_QT_SVG=1
      HAVE_QT_PRINTSUPPORT=1
      HAVE_QT_MULTIMEDIA=1
      HAVE_QT_DESIGNER=1
      HAVE_QT_XML=1
      HAVE_64BIT_COORD=0
      HAVE_CURL=0
      HAVE_PNG=0
      HAVE_EXPAT=0
      HAVE_GIT2=1
      RPATH=/Library/Developer/CommandLineTools/Library/Frameworks
    Building plugins: streamers tools

Running /opt/local/libexec/qt5/bin/qmake ..
QMake version 3.1
Using Qt version 5.15.12 in /opt/local/libexec/qt5/lib
/opt/local/libexec/qt5/bin/qmake /Users/sekigawa/GitWork/klayout/src/klayout.pro -recursive CONFIG+=debug RUBYLIBFILE=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/libruby.tbd RUBYVERSIONCODE=20610 HAVE_RUBY=1 PYTHON=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9 PYTHONLIBFILE=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/libpython3.9.dylib PYTHONINCLUDE=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/include/python3.9 PYTHONEXTSUFFIX=.cpython-39-darwin.so HAVE_PYTHON=1 HAVE_QTBINDINGS=1 HAVE_QT_UITOOLS=1 HAVE_QT_NETWORK=1 HAVE_QT_SQL=1 HAVE_QT_SVG=1 HAVE_QT_PRINTSUPPORT=1 HAVE_QT_MULTIMEDIA=1 HAVE_QT_DESIGNER=1 HAVE_QT_XML=1 HAVE_64BIT_COORD=0 HAVE_QT=1 HAVE_CURL=0 HAVE_EXPAT=0 HAVE_PNG=0 HAVE_GIT2=1 PREFIX=/Users/sekigawa/GitWork/klayout/qt5MP.bin.macos-Monterey-debug-RsysPsys RPATH=/Library/Developer/CommandLineTools/Library/Frameworks KLAYOUT_VERSION=0.29.4 KLAYOUT_VERSION_DATE=2024-07-14 KLAYOUT_VERSION_REV=ae1315212 RUBYINCLUDE=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Headers RUBYINCLUDE2=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Headers/ruby
Project ERROR: Oops! MAC_USE_ASAN != 1
:
:

ChatGPT says ChatGPT

Best regards, Kazzz-S

klayoutmatthias commented 4 months ago

I understand. That is because it is an environment variable.

I never had trouble with environment variables in qmake, but maybe I never came across the problem that CatGPT mentions. I used $$(VAR) and it was working for me. Here is a description of this option: https://stackoverflow.com/questions/7754218/qmake-how-to-add-and-use-a-variable-into-the-pro-file

I consider adding a general option to the build script to enable ASAN. So in that case you could simply use build.sh -use-asan .. or something like that. But that is for later.

Thanks,

Matthias