I did these steps:
sudo xcode-select -switch /Applications/Xcode-beta.app/
As of October 2018, the solution for making brew and brew install succeed is to:
export CFLAGS="-I/usr/local/include -L/usr/local/lib -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include"
No need to download Xcode manually, but you may want to remove the beta version if you installed it.
The magic part is at the end, where xcrun obtains the correct location of the SDK.