CppCast - Clang Power Tools
Episode Date: November 30, 2017Rob and Jason are joined by Victor Ciura from Caphyon to talk about bringing clang tidy magic to Visual Studio C++ Developers with Clang Power Tools. Victor Ciura is a Senior Software Engineer... at CAPHYON and Technical Lead on the Advanced Installer team. For over a decade, he designed and implemented several core components and libraries of Advanced Installer such as: IIS, Repackager, OS virtualization and others. He’s a regular guest at Computer Science Department of his Alma Mater, University of Craiova, where he gives student lectures & workshops on “Using C++STL for Competitive Programming and Software Development”. Currently, he spends most of his time working with his team on improving and extending the repackaging and virtualization technologies in Advanced Installer, helping clients migrate their Win32 desktop apps to the Windows Store (AppX). News Sy Brand Meeting C++ Trip Report C++ Coroutines: Understanding operator co_await Cmake 3.1.0 released Launching Tech Talks in your workplace 2017 Coding Toys Victor Ciura @ciura_victor Links Advanced Installer Caphyon Clang Power Tools Clang Power Tools GitHub CppCon 2017: Victor Ciura "Bringing Clang-tidy Magic to Visual Studio C++ Developers" Sponsors Backtrace JetBrains Hosts @robwirving @lefticus
Transcript
Discussion (0)
This episode of CppCast is sponsored by Backtrace, the turnkey debugging platform that helps you
spend less time debugging and more time building. Get to the root cause quickly with detailed
information at your fingertips. Start your free trial at backtrace.io slash cppcast.
And by JetBrains, maker of intelligent development tools to simplify your challenging tasks and
automate the routine ones. JetBrains is offering a 25% discount for an
individual license on the C++ tool of your choice, CLion, ReSharper, C++, or AppCode.
Use the coupon code JetBrains for CppCast during checkout at JetBrains.com.
Episode 128 of CppCast with guest Victor Chura, recorded November 27th, 2017.
In this episode, we talk about workplace tech talks and toys for young coders.
Then we talk to Victor Chura from Capion.
Victor talks to us about bringing clang-t, the only podcast for C++ developers by C++ developers.
I'm your host, Rob Irving, joined by my co-host, Jason Turner.
Jason, how are you doing today?
Doing well, Rob. How are you doing?
I'm doing pretty good. Recovering from Turkey Day and everything. You have a good holiday weekend?
Yeah, I was with my family, my wife's family. It was a very small gathering, so it wasn't a bunch of crazy overloading on football and food. But yes, it was nice.
Yeah, I had a pretty laid back on myself okay well at the top of every episode i'd like to read a piece of feedback uh this week we
got a tweet from augmented reality and i guess they found our episode from last week with dave
moore from oculus research saying very interesting podcast episode of cPDcast with Dave Moore from Oculus Reg Research for AR VR glasses.
So yeah, it was a really interesting discussion.
And we talked a lot about the AR and VR stuff
without necessarily talking too much about the C++ components,
but I thought all of that was really interesting.
I thought it was a ton of fun, personally.
I could have just talked about some of those things
and picking his brain for hours, personally. Yeah, I could have just talked about some of those things and picking his brain for hours, probably.
Yeah, definitely.
Well, we'd love to hear your thoughts about the show as well.
You can always reach out to us on Facebook, Twitter, or email us at feedback at cpcast.com.
And don't forget to leave us a review on iTunes.
Joining us today is Victor Chura.
Victor is a senior software engineer at Caffeon and technical lead on the Advanced Installer team.
For over a decade, he designed and implemented several core components in libraries of Advanced Installer, such as IIS, Repackager, OS Virtualization, and others.
He's a regular guest at the Computer Science Department of Almada, the University of Krova, where he gives student lectures and workshops using C++ STL for competitive programming and software development. Currently, he spends most of his time working with his team on improving and extending the
repackaging and virtualization technologies in Advanced Installer, helping clients migrate
their Win32 desktop apps to the Windows Store.
Victor, welcome to the show.
Hey, it's good to be here.
So can you tell us a little bit more about this Advanced Installer?
I don't think I've heard of it before.
I actually have used this.
I'm using this at my company right now.
So I'm familiar with it a bit.
So I found a customer.
Excellent, excellent.
Hope you're happy with it.
Yeah, absolutely.
So the reason Jason hasn't heard of it yet
because he's not living too much in Windows world, I think. So Advanced Installer
is an IDE helping Windows developers package and deploy their applications on Windows platform,
exclusively on Windows. So at the same time, we address sysadmins and IT pros that have
enterprise deployment and provisioning requirements for their software infrastructure.
So you really got to be deep in Windows to know Advanced Installer.
Almost everything I work on is actually cross-platform,
but I use whatever installer tools that CMake prefers.
So Insys on Windows specifically is what I've tended to use.
I recently switched from NSYS to Advanced Installer.
Good choice, Rob. Good choice.
So I actually know NSYS, and it's a freeware installer framework,
and it's very scriptable and friendly.
That's why it integrates very well with CMake
because it's amenable to scripting.
But good choice, Rob.
I'd stick with the advanced installer.
Well, then, if you don't mind my asking,
does advanced installer work with CMake?
No.
We don't have any actual CMake support,
but we do have a CLI interface
and soon we're going to add
a PowerShell interface so
you can integrate it via command line
for now.
So it could be done.
It could be done, yeah, but you have to learn the
specific syntax for interacting with it.
The REPL.
Okay.
Well, Victor, we we got a couple news articles
to discuss. Feel free to comment
on any of these, and we'll start talking more about
the work you did with
Clang Power Tools, okay?
Cool.
Okay. So this first one is a really great trip report
for meeting C++ from Simon Brand.
And it's
very long. He went into a pretty good
description of all the talks he went
to, including some of the
side talks and lightning
talks, which weren't necessarily recorded
or
listed in the schedule.
But it sounds like he had a great time.
Yes, it did.
And I want to call out
Jonathan Bacara's talk. We had him on the show. And
Simon's, who has also been on the show, he says this talk was quite a struggle against technical
difficulties. Yeah, I was actually in that talk. Oh, so yeah, he had some technical issues with
the display adapter or something like that, HDMI adapter.
We started late, but it was a very, very good talk.
Yeah, I was there also, actually.
Yeah.
I just wanted to point out that Jonathan did a spectacular job
of just, like, once it got started,
he just went straight through his talk at a perfectly even pace
and got done exactly on time still.
It was amazing.
Yeah, yeah.
You kind of thought it was going to run late
or maybe he would have to skip some slides or anything,
but I guess he adapted very well to the time constraint
and the talk itself was very instructive.
I very much liked it right from the start.
So I'm a big fan of Jonathan's.
I follow his blog regularly.
Yes, that's a great blog to follow.
I very much enjoyed his talk at Meeting C++.
And I actually met Simon as well.
We just briefly chatted via
CPP Slack channels, so
I never met him. And I got the chance
to meet Simon at Berlin.
And we actually chatted, and
I saw his talk
as well about
debuggers.
Did you see that? I missed that one.
I'm looking forward to seeing it when it's on YouTube.
Yeah.
It was very instructive for me,
as I'm not very familiar with GDB and LLDB.
I'm more familiar with how Windows debuggers work.
And it was very instructive for me,
and I think he did a very good job on it.
Excellent.
I learned a lot.
I hope you like it when you see it.
There's also, and what you mentioned,
getting to meet Simon,
and you had only known him on Slack before,
and this is one of the comments that he makes here, too,
that he had a wonderful time meeting those
whom he had only ever met on Twitter or Slack before.
And I'm seeing this kind of community thing growing,
it seems, continuously at the conferences.
People are really connecting
who only knew each other online before.
And it seems to be changing rapidly.
Two years ago, I didn't feel like I saw the same thing,
and now I do.
That's great.
Yeah.
People get very friendly at conferences,
especially after the sessions finish in the hotel lobbies or the conference venues or at dinner, over drinks.
So even between sessions on the hallways during lunch breaks or something like that, I think that's the best part of the conference because you can always catch the videos online but the conversations you have right there ad hoc with meeting people and exchanging the ideas and
people are very open and friendly to talk to perfect strangers and get acquainted and sharing
with passion the stuff they work on and they even discuss that that their favorite talks so far so that's always very
interesting to hear or maybe you hear a good recommendation so what do you guys gonna see next
so what's your favorite talk from today so right it's always very very productive for me i like it
one other thing i wanted to call out in this this trip report is the secret lightning talks that Simon attended, which were, I guess, given before the keynote.
There was one from Guy Davidson and one from Kate Gregory.
Guy talking about diversity and inclusion in the C++ community is obviously very important.
And Kate Gregory talking about things she learned when she thought she was dying from a cancer diagnosis,
which sounds like an incredibly personal talk.
Were either of you guys able to attend those?
Yeah, yeah. It was a plenary thing.
I especially liked Kate's talk.
It was very moving.
Nothing at all C++ in it, but good life lessons nevertheless.
I especially liked her lightning talk. Very good, but good life lessons nevertheless. I especially liked
her lightning talk.
Very good.
I had already had to leave at
that point, so I wasn't able to catch that.
Okay, well,
next article we have is C++
coroutines
understanding operator co-await.
And this is a really
lengthy article going in a lot of depth
about how the await operator works with coroutines.
I'll be honest, I didn't have a chance to get through the article completely.
Did either of you guys make it all the way through?
I did not.
I could say I got through it, but I was lying if I would say I understood all of it.
So it's still new for me.
This coroutine business is very fresh and I didn't have a chance to really play with them.
But I think the most fun way to learn about coroutines is actually watch Gornishanov's talks.
He actually had a very entertaining and instructive talk at CPPCon this September.
I think it's called something like Naked Coroutines with Networking
or something along the lines of that.
His talks are always very entertaining and instructive and easy to follow.
He actually builds up examples, and that's probably the best way to get into coroutines.
And later on, dig deep with articles such as this one that go into a lot of details on how you can actually customize the behavior of the waiter and the promise.
Right.
That's a really good point because, yeah,
Gore's done several talks at this point. Yeah.
He's actually the champion of coroutines right now.
Yeah, definitely.
From my understanding, the specification in the TS for coroutines
is that it gives a lot of leverage for the implementers
in how they actually implement awaiters and awaitables.
And it basically is just a contract between some interfaces
that you can implement in your library to customize their behavior
and the compiler that hooks in into those implementations
and actually drives the behavior
on how you choose to implement those interfaces.
So it's very, very customizable.
The actual library support is very, very thin,
just a few types.
Interesting.
So I think it's still uncharted territory.
And so far, I haven't seen very complex examples.
I mean, like production quality code using coroutines.
So I'm still looking forward to some more serious examples of coroutines. But I mean, apart from the usual Fibonacci
and server client communication examples
that you see everywhere.
But I'm still very excited about this.
So I follow everything that's available regarding this.
But I haven't got a chance to actually play around with them.
Have you guys?
I was going to say several.
I have not, but several compilers do support it,
so you should do that.
Report back to us.
Yeah, it's invisible to me now, I believe, right?
Yeah, yeah, yeah.
And I think Gore actually led the implementation in Clang as well.
Yes, I do.
But I'm not sure which version, maybe 6.0.
That sounds right.
Not sure either.
And maybe you have to throw some special switch
in the command line to activate the feature.
Okay, next we have CMake 3.10.0 is available for download.
Jason, you being the CMake expert,
is there anything notable in here?
There's a couple of things.
The one thing that really stood out to me
is that the CPAC Debian Packager Generator
is now available on Windows.
So you can build Debian packages from Windows, hypothetically.
It says it's lacking some basic command line
tool support, but that's
interesting.
That was the main thing that really stood out to me as
surprising.
Also,
there's a new support for a new Fortran
compiler.
Yeah, that's very exciting.
I didn't know that they were still adding support
for Fortran in CMA. No. I didn't know that they were still adding support for Fortran and CMake.
No.
I guess there's still a big community there.
I guess.
There's also this Gtest Discover Tests.
And if you've worked with anything like Gtest and CTest,
and you have your C++ tests that you've written,
and you want CMake to be able to automatically
enumerate them and report on which tests
have succeeded and failed, there's a good chance
that you've written your own parser that goes
through your C++ code and looks
for the
G test macros and then
adds those into your C test
targets.
But there's a new
G test discover test that was added. So it does
that for you and you don't have to have your own hand rolled parser for that anymore. But since you
gave me the platform, Rob, go for it. I'm going to go on a slight little rant here. So we see that
there's this new CPAC, um, for, for day BN and CPAC for FreeBSD. I didn't mention that one.
So I go to the official CMake.org wiki for the list of package generators that exist.
This page hasn't been updated. Let's see. It says it was last modified in September of 2017. But it doesn't say anything about Debian for Windows.
It doesn't say anything about FreeBSD.
And while I was, you know, I thought, hey, it's been a while since I've really looked at CMake.
I'm going to look and see what other package generators there are.
Because I've had a problem for like five years on Mac OS that the officially supported CPAC generator is PackageMaker,
but PackageMaker is no longer supported by Apple. So it's a huge pain to try to find the right
PackageMaker binaries on Apple's website, get them installed on your most recently updated Mac,
and then use that to generate the PackageMaker binaries from CPAC
so that you can have your installer.
All right.
Rant will be done in just a moment.
I was browsing through the CMake modules on GitHub,
and I see that there is another new macOS package generator that's in here,
and it says the file the uh file was first edited
like four years ago and there's still no documentation about it or any mention as to
whether or not it's in any official release so they gotta keep updating their docs whenever
they change these like release these change logs i feel like the at least the wiki pages which are
the first things that come up when you do Google searches or DuckDuckToGo searches, are always like it's hit or miss whether or not it's actually up to date and what you need to know from it.
Okay, I'm done.
Okay.
Maybe a call for volunteers is in order.
It's something.
And I don't even know how you're supposed to discover some of these things is my real complaint here.
Yeah. supposed to discover some of these things is my real like complaint here yeah how am i supposed
to discover what package generators there are if the official wiki page of package generators
doesn't have all the package generators on it yeah that's a that's a problem all right sorry
about that it's okay we're gonna get comments now you're gonna get comments comments. Victor, you asked us to talk about this article,
launching tech talks in your workplace,
which actually makes me think of,
we were talking about Jonathan Bacher
during the other article
and how he gave a great talk in meeting C++.
And he talked about this when we had him on
about having tech talks in your workplace.
He actually coined the term, I think,
the C++ dailies.
Yes.
That's small, bite-sized content
that you can actually pitch in 10 minutes every day
to some small group of teammates.
I very much like that idea.
I haven't tried it yet.
I'm looking forward to it.
Yeah, and this article isn't necessarily suggesting
daily talks.
No, no.
You know, like doing every month or so, doing an hour-long talk.
Yeah, I think it's a format for an hour-long,
and it's either a one-hour-long talk or several talks combining up to an hour.
Even Lightning Talks, he actually explored some of the strategies he employed in dry periods when attendance was low and interest diminished within the company.
So he tried various things.
And I very much like the case study nature of the article.
And I think we can all learn from various strategies that he employed here.
I actually exchanged some messages with him over Twitter about this article and I found
myself in the same position as I've been organizing tech sessions at my company for almost eight
years now.
Wow.
Yeah.
It wasn't continuous.
We had very dry periods.
And we try to do it weekly.
We call them tech session Fridays.
And it varies in format, usually an hour.
Live presentations most of the time to encourage people to actually attend. We watch pre-recorded
technical sessions, like sessions from CPPCon, CPPNow, and other conferences, and later dissect
them and analyze them right there. So we pause the video and discuss the things we've seen, or maybe we'll have a debate at the end regarding the issues
and how those issues pertain to our actual development within the team.
That's a good idea.
And we actually tried live presentations as well,
but people are difficult to keep interested
and convince multiple speakers to actually put on a show, so to speak.
And it's difficult maintaining momentum.
It's quite easy to start.
Surprisingly, it's quite easy to bootstrap such an effort.
But it's very difficult to keep the momentum going
and keep people attending and interested
and encouraging other people to submit topics
for the sessions.
And even more difficult to actually convince people
to present.
Because oftentimes you have very good developers
on your team, but they don't have very good presenter skills
and they're kind of
shy away from the opportunity
to talk to fellow developers even though they
do it every day but when you put
a formal setting on it
somehow they become
shy
I think the article
it's very instructive
for people trying out such a thing at their company or within their teams.
And you can definitely learn tricks that he describes in the article about keeping people interested in showing up, basically.
So I very much liked it.
I was reading the blog post
and I was just seeing my situation in his words.
So it really struck a chord with me.
That's why I suggested that we discuss this article
in the news section.
Do you guys have any comments on the article per se?
I don't really have a workplace.
But in terms of actually convincing people to regularly keep up with training
and keeping up with the news in the C++ community
and encouraging people to keep learning.
I think this is more like something like
you could perceive it as a company culture thing
or as a team culture thing,
as well as a personal drive to improve and continuously learn.
Yeah, it does seem like... Oh, go ahead.
Sorry. For example, you do training, Jason.
Yes.
A big part of this is actually companies being willing to invest in training
and people being interested in actually showing up
and signing up for those training sessions
and actually
being
willing to learn and improve
themselves and keeping up to date with the
new standards and the new techniques and idioms
and
Yeah, it's an interesting mix
when I do my own trainings
if I like put on my own training or if I'm doing something at CPPCon or whatever,
to hear some portion of the people say, I'm here because I'm interested in going to one of your trainings.
And the rest of the people say, I'm here, I don't know anything about you, but my company made me come, basically.
Those are the best customers. they don't ask any questions well no i mean they've all been
they've all been great students but i'm always just kind of surprised it's always fascinating
to me to hear who came and why and it seems like those are the two basic answers right there
okay i don't know how that translates to, you know, meetings in your company.
Yeah.
Okay.
Last article I wanted to bring up is an important list for your holiday,
my favorite coding toys of 2017.
And this was written by Sarah Chips,
who of course we had on a couple months ago talking about Jewelbots.
And Jewelbots is on this list as well as several other coding toys
most of which i haven't heard of um there's the kano computer kits which sounded pretty cool
you're actually building a computer that you can then go and play minecraft on and uh codepillar
uh this little uh toy where you program a caterpillar to do different moves. And there's actually, uh,
these code babies books,
which are board books with coding stuff in it.
And there is one for C++.
I have pretty cool.
I knew those existed.
Yeah.
Like C++ for babies and C++ for infants or toddlers or something.
I don't know.
Is that child abuse or what?
I don't know.
Have you done any of this for your kids, Rob? No't i need to i we we do have the um one of the goldie blocks toys that are
listed here they're not really coding specific they're more like just kind of general stem toys
but i do have some of those for my daughter i like this description of the um of the code babies book
that says a gift like this says to your partner or friend,
I'm not going to stop until this kid thinks
and acts just like me.
Yeah.
Well, we are in the holiday season now,
so if you want to get your kids into coding,
definitely check out this list.
I actually like the Coda Peeler for toddlers.
I have a four-year-old, so maybe I'll try it on.
Yeah, that looks like fun.
Yeah, yeah.
It does.
Okay, so Victor, let's start talking about Clang Power Tools.
How did you get started working with Clang Tidy?
Yeah, it all started I think
almost a year ago
at
it all started actually with
Clang Format, not Clang Tidy
and it started at
I think at the Birds of a
Feather session at CppCon
2016
so last year
and I actually attended that Birds of a Feather session
and people freely discussed and shared ideas about
their strategies and embracing Clang format and
mitigating issues with regards to coding standards and
workflows within their companies. And I thought at the time
we weren't using the clank format so
that was a very interesting experience for me and um i i got charged up and
full of ideas and came back and pitched the idea to my teammates and very quickly got their support.
And we actually decided to experiment with Clang format.
And we, after endless debates about configurations and coding standards,
and of course, we actually reached a compromise.
And in a very, very short period of time we managed to
reformat in one big push our whole code base with clang format and integrate clang format in our
in our daily editing workflow with auto format on save and that was that and everybody was very
happy and no more debates about formatting issues in code reviews and discussions.
And all the code looked uniform and okay and easy to grab for, as in terms of white space and such.
So endless debates over formatting within code reviews were immediately gone. Wow.
And that was very, very easy and deceptively easy
because after this Clang format success,
we got very excited about actually using Clang tools on Windows
because we always had tool envy.
At conferences, people were always very excited
about new developments in the open source ecosystem,
especially in the Clang ecosystem,
and always bragging and discussing about cool tools
and facilities and checks continuously being added.
And I always felt like I was being left out of that ecosystem.
So I got very courageous, so to speak,
and started to experiment with Clang Tidy on Windows.
We already had an LLVM distribution for Windows,
and that was the best part of it
because we didn't have to do any actual work
of porting it to Windows.
So the actual LLVM distribution on Windows worked just fine.
And I started experimenting with Clang ID,
and especially I experimented with the modernized checks.
So the first difficult part was actually getting the code to compile under Clang
because as opposed to Clang format, which is happy to reformat your code
even though Clang is not able to actually compile it,
it just needs to be able to parse it.
So using Clang Tiny, it's a whole different story. You actually need to be able to compile it. So using Clang Tiny, it's a whole different story.
You actually need to be able to compile your code base under Clang.
Even though we only use the front end, so we use the dash F syntax only,
we had several, several issues in compatibility.
So our code compiled fine with Visual Studio,
and we even used the highest warning levels
available like W4
and we actually didn't have
any warnings.
We used
three warnings as errors setting.
So everything was fine
under Visual Studio
2015 and later on 2017
as we migrated during this time frame to 2017.
But there were non-standard constructs being used
and if you can have non-standard syntax
or non-standard constructs available,
people will use them, either knowingly or not.
So we had several issues of incompatibilities, and we had to adjust those and fix those in
our code as we started building the whole code base under Clang.
It actually took a lot less time than I originally anticipated. And it was actually a part-time
effort. We did this as a hobby project, so to speak. So it was not something that we
actually scheduled or anything. And we didn't have any actual assignees on this task. People
actually pitched in to help.
So I started this effort as more or less like a hobby,
as I said, and other people pitched in to help
because they got interested in the changes I was making
to the code base and basically volunteered
their time to work on this.
And we managed to do this, I think, in about three months
on two and a half million lines of C++ code.
And on a part-time effort, at the same time,
we were working on the production features
of Advanced Installer on actually shipping the product.
So this was like a part-time effort,
and we managed to have all the code compiled with
w all under clang wow yeah that was a big milestone it was gradual initially we disabled a whole lot
of warnings to be able to get up and running because we also wanted to leverage Clang Tidy to do transformations
that we wanted to perform.
So it kind of was like a catch-22 kind of thing.
So we wanted to use Clang Tidy to perform some transformations like member initializer
list reordering and stuff like that that were too tedious to do by hand or to automate via
grep replaces.
So we disabled some warnings to be able to use Tidy,
and then after using Tidy, we were able to remove even more warnings
and re-enable those warnings that we initially ignored.
So it was a rinse and repeat kind of thing.
And after a few months, we actually managed to compile our whole base with WALL.
And we got even more courageous
and started tackling WXtra.
We're still not there yet.
Lots more warnings in there to fix.
And after that, we just jumped in
and used the tidy checks for the first targets were obviously the modernized checks
because our code base was C++98.
It's a 14-year-old code base.
So the modernized checks in Clang tidy were the first target we tackled.
And we were very happy with the transformations. We were able to run large-scale transformations on our code base
with fairly low negative issues or impactful issues.
There were issues.
I actually presented some of those.
I had a session about this at CppCon and later on at meetings C++.
And I presented some of the issues we encountered and how we mitigated them and some of the workflows we developed in tackling these transformations. And aside from the modernizations
and readability transformations,
we also tackled reports from the static analyzer
because ClankTidy now includes the static analyzer.
Right.
And we were able to run the static analysis
and analyze the reports
and found several issues
that we managed to fix
this way.
I'm curious, just from the
Clang-Tidy standpoint,
before you do the analysis and you're talking about the
warnings that you had to fix,
did you find any real
bugs in your code that just
simply trying to run it through Clang-Tidy
found for you?
Yep. Yes, we did.
Okay.
There were
several kind of issues.
One
that comes to mind right now is that
we found some
near misses in terms of virtual
functions. Clang Tidy actually
checks for the and offers to put in the override keyword.
Right.
We didn't leverage the override keyword
because that came in later.
So a lot of our code base
actually relied on conventions
and actually marking with some comments
that, okay, this function is virtual
and overrides some base class functions.
We actually found some errors
that derived functions in derived classes
were not actually called.
Wow.
Even though they were intended to be called.
So this one comes to mind,
and it's a serious issue,
not something that you're going to take lightly.
So we're very happy serious issue, not something that you're going to take lightly.
We're very happy that we were able to run a
modernized check that actually
put overrides
over all our virtual functions
that were actually overridden.
Now you have
the
security of being able to
tell when somebody renames the method
and your overrides don't get called.
Very cool.
We actually found several issues
just at the stage of making it compile under Clang.
Ignoring Clang analysis and everything else.
So just making sure it's standard compliant code,
we actually found and fixed issues.
And missing field initializers
and uninitialized memory and other things like that.
So we actually found quite a few issues.
That's interesting.
It was a very surprising experience.
So we expected to find issues, but some of them were so severe that we've actually been shocked that nobody caught those issues in that horrible bug.
So definitely, we didn't have any coverage in test units in that regard.
Clients maybe spotted some of the issues, but they were intermittent.
So we weren't able to always pinpoint the cause of certain issues.
And we were amazed about some of our findings.
It's an interesting experience, and I highly recommend that people try it on.
Because it's very worthwhile.
Yes, it's a pain to fix all the warnings,
but you do have huge payoffs in terms of unexpected things
that you might find in your code base.
It was very revealing, for us at least.
Did you end up submitting back any bug reports
or support requests or anything back to the Visual Studio team
for things that you thought they should have been catching all along?
No, no.
Some of the things are just plain non-standard syntax
that Microsoft officially supported.
But stuff like that, it usually gets abused.
And the compiler just gives up in trying to warn you
about stuff that's just non-standard stuff.
So it will just plainly let you use unsafe things.
And another category of issues is issues that
could generate undefined behavior.
And Clang warns you about certain classes of these issues.
And those were another source of bugs for us.
So stuff that might cause undefined behavior.
Okay.
That was very interesting as well.
I want to interrupt this discussion for just a moment to bring you a word from our sponsors. Okay. That was very interesting as well. debugging and reduce your mean time to resolution by using the first and only platform to combine symbolic debugging, error aggregation, and state analysis. At the time of error, Bactres jumps into
action, capturing detailed dumps of application and environmental state. Bactres then performs
automated analysis on process memory and executable code to classify errors and highlight important
signals such as heap corruption, malware, and much more. This data is aggregated and archived in a centralized object store, providing your team
a single system to investigate errors across your environments.
Join industry leaders like Fastly, Message Systems, and AppNexus that use Backtrace to
modernize their debugging infrastructure.
It's free to try, minutes to set up, fully featured with no commitment necessary.
Check them out at backtrace.io.cppcast.
So you just kind of shared this journey of going into Clang Tidy
and Clang Format and applying it to your code base.
How did that result in creating these Clang Power Tools?
Good question, Rob.
We actually started with a very primitive tool, Windows batch files. So we basically started putting together clan command lines, very long command lines, to
make sure we are able to compile our code.
And a lot of the work was actually trying to use the correct project settings because we do have strong dependencies on the Windows SDK
and
we did have the need
to actually use all the
settings from within our projects like
preprocessor definitions
and include direct stories and
platform target settings and
PCH
information and other kinds of
information, MS build variables and other
kinds of information that is found in Visual Studio project files.
That are Visual Studio project files are actually MS build scripts in themselves as syntax.
And they can reference other property sheets within and it's kind of like a recursive script invocation or inclusion.
So we very quickly ran into problems in using this approach,
this crude approach of automation using batch files.
And there's so much things you can do with batches,
scripting and processing on Windows.
We immediately started implementing a PowerShell script for this.
My colleague Gabriel, who's a PowerShell wizard here,
I'm actually not very good at PowerShell at all.
He pitched in to help me with the script,
and very quickly we were able to do very complex analysis
and parsing of Visual Studio project files
and spit out the correct commands
to drive the GCC driver for Clang and Tidy on Windows.
So all the magic in adapting and mining settings
from Visual Studio and Visual Studio project configurations
into Clang command lines and Clang Tidy command lines,
all the magic happens within that PowerShell script.
Okay.
And we use that PowerShell script
in the process of actually running
the modernizer checks on our codebase.
And when we fixed all the warnings that Clang issued.
And as soon as we achieved Clang double wall compilability, so to speak, when we were able to compile our whole code base with Clang,
the first issue was how to keep that code base clean under Clang, so that new code that comes in or code changes don't break the Clang builder immediately. Because people were not running
those scripts, developers on the team, I mean. And the first thing we did was integrate that PowerShell script into continuous integration.
We used Jenkins here for continuous integration.
And we immediately integrated that PowerShell script in Jenkins' job that actually compiled
every SEM change, so every new check-in,
was compiled with Clang and issued a report that was delivered via email and even we have a Slack bot.
People love Slack here.
So we actually have a Slack bot, a Jenkins Slack bot,
that delivers the Clang errors
or warnings to developers on the team.
So this way we made sure that every check-in
that breaks the Clang build is immediately taken care of
by the actual developer that made that check-in.
So the next obvious thing was
developers were not so happy about running a PowerShell script
and giving command lines for actually finding the error under Clang
and fixing it.
So we immediately started thinking about,
okay, how can we make developer lives easier
in this workflow?
So the obvious thing here was a Visual Studio extension
because we live in Visual Studio
and developers like to have the whole experience
right there in the IDE.
So it was a no-brainer for us
to start developing a Visual Studio extension.
And we actually had experience in this matter,
so we didn't start from scratch learning how to do that
because we do have a Visual Studio extension for our commercial product.
So we did have the knowledge in-house on how to do that.
And another colleague, Jonutz, pitched in the help to develop this Clang Power Tools extension
that practically comes into the developer workflow.
And so every developer on the team has this extension installed.
And whenever you have a triggered notification from Jenkins
via email or the Slack bot that the Clang build is broken.
The developer in question automatically runs the source file that is targeted to be fixed,
runs it under the Clang Power Tools Visual Studio extension,
and right there in Visual Studio, he can see the breaking change in the report
and navigate right through the
error or the warning and fix it.
So this was almost obvious choice for us in making sure that developers have an easy-to-use
workflow to fix those errors that were constantly being checked in
because people, when they check in their changes,
they usually check them under Visual Studio and that's it.
They don't think about, oh, will this work under Clang?
No.
So we actually use it like this, like post-mortem fixing.
So when an error occurs, developer is notified and fixes the issue.
And we thought about how much
time we've put in in developing these tools, the PowerShell scripts
and the extension itself, and we thought it was
appropriate for us to just make them available to the community.
And that was not a goal we set out initially.
We just selfishly wanted to code those tools for us to use them internally.
But after we were able to successfully use them internally, we thought, hey, why not
share those tools with the community?
And we made the
project available on GitHub.
So the whole project is on GitHub.
The Visual Studio extension code,
the PowerShell scripts,
all the project
is on GitHub.
And we
also maintained
the Visual Studio extension on the
Visual Studio Marketplace the Visual Studio marketplace.
We gave it a snazzy name like Clang Power Tools.
And we made it available for free on the marketplace because it's easy to discover there.
When people search for Clang from the Visual Studio extension IDE in the extension manager or within the marketplace, they will
find it.
It's the first result they see.
And we want it to be very easily discoverable and very easy to install so they don't have
to build the extension themselves.
Of course, you can check it out from GitHub and build it on your own.
But we want it to have a zero barrier of entry
on using the tools.
So we actually maintain a distribution,
V6 package for it,
on the marketplace right there.
And you also get automatic updates.
So Visual Studio automatically gives you updates
for the installed extensions you have.
So, for example, today we released our 11th version of the extension, version 2.0.
We actually released 11 versions in just two months.
Wow.
Yeah.
We had quite a few issues reported.
So, for example, today we pushed version 2.0 and automatically Visual Studio will
inform you and automatically update your extension and you're just ready to go. So, this is the kind
of workflow we want to encourage so that people can and will leverage Clang-Tidy on Windows.
Because if it's difficult to use,
if you have to pass huge command lines
and you have to figure out what to extract
from your Visual Studio projects to pass to Clang,
you have no chance in using it
or convincing your teammates to embrace these tools.
So it really has to be a zero effort
to be able to convince your teammates to actually use the tools.
So you said zero effort.
So I can go to the marketplace,
I can click install,
and then what? Do I have to do anything
else? Does that get clang and everything for me?
No.
You have to install the official
LLVM distribution for Windows.
That has an installer.
So you just have to download it from LLVM distribution for Windows. That has an installer. So you just have to download it
from LLVM website.
It has a Windows installer package.
You just click. It has an installation wizard
so you don't have to build anything.
You just install the standard
Windows distro for LLVM.
It will work with LLVM
3.9, 4.0, and 5.0
so far.
So whichever version of LLVM you're using,
you just install it,
and the Visual Studio extension will just detect it
in your path and be able to run with it.
So there's nothing else you need to install to make it work.
Just the standard LLVM distribution for Windows
that brings
the compiler and
tidy and all the other tools required.
And what versions of
Visual Studio does it work with?
2015 and
2017. Okay.
Those are the most popular right now.
And then
after you get the power tools
running, I'm guessing you
obviously might need to do lots of work on your code
base, the type of stuff you went through
with just getting your code to be able to compile with Clang
if you're only targeting Windows currently.
Exactly. And I think people
should focus on their code, not on
the tooling itself. So this is
exactly what we wanted to achieve.
People should focus on actually
fixing their code and fixing
the warnings and fixing the warnings
and analyzing the reports from the static
analyzing and doing
code transformations on scale
with Clang-Tidy, with
modernize or readability
checks or
performance checks.
It even has performance checks. So people
should focus solely
on their code and don't worry about how to use the tool itself.
So the tool is just a means to achieving better code
and modern code.
So we think people will be much more well-served
if we do the hard part,
and we actually did the hard part
in making the tool run on Windows
and actually syncing all the settings
with your Visual Studio projects
and Visual Studio property sheets.
And this part is very difficult and tedious,
and it took us a lot of effort.
And people should just focus on their code,
not on the mechanics on how to get the tool working
on Visual Studio and on Windows.
Right.
And I think having tools like this available,
you basically have no excuse in actually running your code
under Clang and leveraging all the power
that Clang-tidy makes available for you.
And you unlock a lot of possibility for custom transformations as well.
Because as soon as you get your code compiling under Clang,
you can write your own transforms, your own tools on top of lib tooling.
Because lib tooling exposes all the AST
and all the goodness of the...
and all the hard part of actually parsing C++
is done in lib tooling.
So you can implement your own tidy checks.
You can implement custom transformations.
We actually did implement some custom transformations
for our code base.
Stuff that we didn't open source
because it was very project specific.
We did some transformations
and we're going to continue doing some transformations
that are very specific to our project.
Some special refactorings that we need to perform.
And those are not of reuse value to anybody else.
But maybe we can open source them as samples
in how other people can write their own.
But I think the community
does a good job there
and you'll find
lots of content online about
writing tidy checks
and writing
your own analyzers
and writing any
transformations on top of lib tooling.
So basically you're, by unlocking this window,
in bringing these magical tools to the Windows ecosystem,
you basically can tap in everything you see online
in terms of Clang tooling itself.
That's the biggest win there.
Your journey started with Clang format.
Does the Clang Power Tools still support Clang format?
Surprisingly, no.
We do have an open issue regarding this on GitHub.
So we do want to incorporate Clang format in this extension.
Yeah, so our plan is that Clang Power Tools,
it will be your one-stop shop for everything Clang on Windows, so to speak. So very soon, it will get Clang format support
and tidy transformations that have autofixes
because you can run tidy transformations with autofixes,
those will apply Clang format as well after fixing the code.
Okay.
So very soon.
Keep an eye on the project.
Very soon.
I must say this project sounds magical in a way,
because I'm a huge proponent of cross-platform development
because it gives you all the advantages
of all the various compilers out there.
And you've really, it sounds like,
made it very accessible for someone
who has no reason to be on multiple platforms
to still get the advantages
of doing cross-platform development.
People keep asking me the question,
do you plan to use Clang
to build your commercial product on Windows?
And I keep telling them, no, we don't have any plans to build
and distribute our binaries built with Clang or LVM on Windows.
We just want to leverage all the tooling in the Clang ecosystem.
So we're going to continue using Visual Studio 2017
and the follow-up releases,
and we're building the actual bits
for the advanced installer project with Visual Studio.
So we don't have any plans on switching compiler toolchains, but we did have this tool envy,
and we did want to tap into this ecosystem of clang resources and tools and various refactoring libraries that are out there.
And we just wanted to leverage those tools.
And this is what we're trying to achieve.
We're not trying to...
And Clang Power Tools actually doesn't produce any output
in terms of binaries or object files.
We just use f syntax only.
We just use the front-end compiler
from Clang.
Because our focus is
achieving standard
compatibility in terms of
your code base and leveraging
the tooling in this ecosystem.
So since you only do syntax only,
is it fast?
It's fast
because we leverage
parallel compilation for projects
and we actually emit
pre-compiled headers.
So if your Visual Studio project
uses pre-compiled headers, and people
use pre-compiled headers a lot on Windows
in Visual Studio,
we will tap into that
and pick up your PCH
configuration and we'll generate
Clang PCH. We'll generate
Clang PCH information for your project.
Interesting. And we also
parallelize, depending on how many
cores you have on your machine, we actually
saturate your machine in terms of
executing parallel compilation for
translation units.
Okay.
Because we don't have to worry about linking the translation units, and we don't have to
worry about the dependencies between the various translation units.
We just parallelize the compilation.
So actually running a Clang pass through our project is much faster than running Visual
Studio because we just parse it.
Good, yeah.
Well, that's what you'd hope for for this kind of tool.
Exactly, exactly.
You want it to run fast.
Because you just parse to make sure,
okay, it's compliant.
Okay, I can still use it to run tidy checks.
And this is another thing.
As soon as we open sourced the project,
we were amazed about the different ways
in which people use Visual Studio projects on Windows.
So we thought we had a very complex configuration
for our build systems and our projects.
We were so wrong.
So we found people that were very willing to try the tool as soon as we released
and very willing to help us and actually sent us their Visual Studio projects
and their Visual Studio property sheets to help us debug the issues we had
because our extension didn't properly parse their projects.
So we uncovered a ton of issues that we didn't think were even on the radar when we started.
So we're in pretty good shape right now.
I'm very proud of our latest release.
And we're going to keep improving based on the feedback we received from our earlier adapters. și vom începe să împărtășim în base la feedback-ul
care am reușit de adaptoarele noastre. De până acum am avut aproape 8000 instalare în doar 2
luni. Am publicat această extensiune și am deschis-o de fapt la CppCon at the end of September. So in just two months we had 8,000 installs
and people are very happy so far with it. And they submitted a lot of issues but they
were very eager to help and we actually debugged a lot of stuff and fixed a lot of their issues. And I'm very happy with the momentum it gained.
So we welcome
external contributions.
The project is open source.
And we've actually had people
forking the project and
people pitched in and made pull requests
with changes.
So I was amazed about
the reception within the community.
I honestly didn't expect that.
So I'm very happy with that, and I hope more people will use it.
And the end goal really is not about the tool itself.
The end goal is achieving better code quality within your project.
So focus on code quality, modernize your projects.
If you have an old code base on C++98,
and if you can upgrade to a newer version of C++,
I know that's an issue that's difficult in many companies,
modernizing the tool chains.
But if you can do it, modernize your code,
your teammates will thank you.
So people usually ask me
if I can give a return of investment
or give them some metric
in terms of our experience
in using these tools
within our commercial products.
I always tell them that
the best metric is that
my teammates are happy.
They are happy because
they work in a modern code base right now,
and we have more confidence in the code
because of finding and fixing reports from the static analyzer.
And we were very amazed about the subtle latent bugs
that we uncovered
just by making it compile in a standard conformant way.
And if your teammates are happy, I think that's the best magic for a success story
in terms of developer tooling.
So I'm looking at the link right now to Clang Power Tools in the marketplace,
which I'll put in the show notes. And it definitely looks really easy to use.
One last question I had was, you talked about how you're using Clang as part of your CI script.
Is there any way to go from, I'm using Clang Power Tools and I now want to apply it so that
everyone on my team can see these reports through Jenkins CI or something like that.
Can I use Clang Power Tools as part of that,
or do I need to go and implement that separately?
So the Clang Power Tools Visual Studio extension,
it's just a shell to get things driving within the IDE.
Behind the scenes, the actual work is done
by the same PowerShell script file that I mentioned earlier.
So the Visual Studio extension actually hosts
its own PowerShell script within the package,
and it runs the same script that you can use for automation.
So the same functionality.
Basically, the script is the brains of the tool. The PowerShell script does every operation
with regards to parsing the Visual Studio project files
and extracting all the relevant settings
and constructing the appropriate comma line
for the Clang and Clang-Tidy.
So the extension is just a shell
that allows you easy integration
with toolbar, context menu.
It gives you context-aware information
and context-aware output in the right places
you would expect in the IDE,
in the output window, in the error window.
It handles navigation to errors
at the right line and column.
It gives you all the goodness of integration within the IDE.
But the actual brains within the tool is the PowerShell script.
So you can take that PowerShell script,
which is available on GitHub,
and you can integrate it in your workflow
in whichever way you see fit.
We use it with Jenkins, for example.
And it's very configurable.
That PowerShell script has switches
that you can configure
and basically create your own workflow.
Either tidy or compilation.
It doesn't matter.
Very cool.
And it can spit out reports
like tidy would.
There's no difference in terms of output.
Okay, well, Victor,
it's been great having you on the show today.
Where can people find you
or find your company online?
So,
you can find me on Twitter.
I guess you'll put my Twitter handle in the show notes,
so no need to mention it.
So, you can definitely follow us on GitHub.
I encourage you to start the project
so you can receive updates if you're following up on issues.
Do submit issues.
If you try the tool and you find issues within your projects,
do submit them.
We try to take care of issues as soon as possible.
We try to keep up an agile pace
and release as quick as possible.
We usually release weekly with fixes.
But we do need your input.
So use the tool, give us feedback,
contribute if you have the passion and the time.
Why not?
So you can find us at clangpowertools.com
and you can definitely chat on Twitter
and even reach out to me on Slack.
So just search for Clang Power Tools
and you'll probably find me as well on Google.
If you're interested in a more detailed story
about our case study,
you can watch the recordings from CppCon.
It's called Bringing Clang Tidy Magic
to Visual Studio C++ Developers.
And a similar version of that talk,
but updated with the latest developments,
will be available from Meeting C++ Conference in Berlin.
So the video is still not out yet,
but if people are interested in a more detailed approach.
Okay.
Thank you so much for your time today, Victor.
Thanks for having me.
It was a pleasure to talk with you.
Thanks so much for listening in as we chat about C++.
I'd love to hear what you think of the podcast.
Please let me know if we're discussing the stuff you're interested in.
Or if you have a suggestion for a topic, I'd love to hear what you think of the podcast. Please let me know if we're discussing the stuff you're interested in. Or if you have a suggestion for a topic, I'd love to hear about that too.
You can email all your thoughts to feedback at cppcast.com.
I'd also appreciate if you like CppCast on Facebook and follow CppCast on Twitter.
You can also follow me at Rob W. Irving and Jason at Leftkiss on Twitter.
And of course, you can find all that info and the show notes on the podcast website at cppcast.com. Theme music for this episode is provided by podcastthemes.com.