- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6k
Define _USE_MATH_DEFINES on Windows where needed #21166
Conversation
| Is there a single top-level place we could define this so people don't need to remember to add it if we start using Pi in a new place in the code? Realistically, I suspect we're unlikely to use it anywhere other than lib/ui. | 
| 
 We could put in in the global configs in the buildroot, but we probably don't want to do that; it would cause duplicate definition warnings if any third-party code defined it in their source. | 
        
          
                lib/ui/BUILD.gn
              
                Outdated
          
        
      | "//third_party/skia", | ||
| ] | ||
|  | ||
| defines = [] | 
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.
This is dangerous; if a config set defines, this could stomp them. Setting an existing list to something else is normally an error in GN, but if you set it to an empty list it assumes you're explicitly trying to clear it (https://gn.googlesource.com/gn/+/master/docs/reference.md#lists). I hit a case in Dart code where this pattern was accidentally suppressing what was intended to be a widely applied config.
I think what you want is:
if (!defined(defines)) {
  defines = []
}
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.
Nice catch. Done!
On Windows, to enable constants like M_PI in cmath/math.h the symbol _USE_MATH_DEFINES must be defined. It's easy to forget, and needs to be defined before the first (transitive) import of cmath, so instead we define in the build targets in which it's used.
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.
LGTM
On Windows, to enable constants like M_PI in cmath/math.h the symbol
_USE_MATH_DEFINES must be defined. It's easy to forget, and needs to be
defined before the first (transitive) import of cmath, so instead we
define in the build targets in which it's used.