There are things companies can do to encourage women. For example on LinkedIn, there are a number of groups for women in technology, and I feel more favourable to companies whose job ads I see there than if I've only seen them in general job listings.
HR can remove as much as possible personal information from CVs before handing them to hiring managers for review - after all, you aren't meant to consider gender or age when recruiting, and you can change recruitment practices so that you have CVs with qualifications and experience but not names (Candidate 1, etc). It won't work entirely - so my CV will contain info about the work I've done with the company's women's association, which will at least imply I may be female. But it can remove some of the basic biases, the unconscious stuff when you know for sure someone's gender.
It can also help to have more diverse interview panels, but it's hard to include more women when you just don't have that many in the workplace, particularly for a particular department you're recruiting for. We've also had training for managers on unconscious bias, and I know we're not the only company to do this - awareness has to be the first step in breaking down the effects of such bias.
Lots of companies (including my own) do do quite a bit with local schools and the community, to tell them the sort of careers which are available and so on. However, I suppose people may only be aware of that sort of thing if you're a school or company which is already involved.
As for retaining women already there - I hope increased awareness of unconscious bias and so on will help. Companies can do more to help women come back to work after maternity; important in all jobs, but I think it can be particularly important in a tech-heavy role where the technology can have moved on a lot just in the course of one maternity leave. Also, having women's associations can help - mine is very active in promoting resources available in the company to help your career, and as a result, I often know things which are happening before my manager does. We also have sessions where we "meet" (usually by video conference) various people high up in the company - sometimes men, but we do focus on women, and they get to talk about their career paths and pass on any tips, and people can ask questions. It's also an opportunity to get involved with organising various events and so on, which gives you a chance to gain experience which you might not get in your main role (particularly if you have a manager who holds you back for some reason.) Just getting to learn about other areas of the business and meet people you wouldn't come across in the course of your normal job is invaluable, too.
I don't know how much it helps our retention rates, to be honest, but I know that HR have definitely been looking at women across the business - our overall figures are pretty much industry-average, but that's partly because HR (about 49-51%) balances more techy areas, like my own division is around 8% women. I do know it's one of the things helping to retain me, though.