# Building extensions with Hoe

**URL:** <https://www.ruby-forum.com/t/building-extensions-with-hoe/81892>\
**Category:** Ruby\
**Created:** [January 16, 2007, 2:58am UTC](https://www.ruby-forum.com/t/building-extensions-with-hoe/81892 "2007-01-16T02:58:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [January 16, 2007, 2:58am UTC](https://www.ruby-forum.com/t/building-extensions-with-hoe/81892/1 "2007-01-16T02:58:45Z")

</div>

Hi,

I’m developing a library that includes a C extension, so during  
development I need to keep re-compiling the extension before testing.

I’m using Hoe for packaging, so I’ve added the following task to my  
Rakefile.rb which allows me to rebuild the extension using extconf.rb/  
make. My library has a further dependency on an external C library  
(libR), at the moment this is semi-hardcoded into the script by  
referencing the environment variable R\_HOME:

desc “Uses extconf.rb and make to build the extension”  
task :build\_extension do  
Dir.chdir(‘ext’)  
system(“ruby extconf.rb --with-R-dir=$R\_HOME”)  
system(“make”)  
Dir.chdir(’…’)  
end

Two questions (I’m pretty new with Rake/Hoe so forgive me if these  
are obvious):

1. The ‘build\_extension’ task works fine, but seems a little hacky,  
how do other people build extensions with Rake/Hoe?

2. Can I retrospectively add this task as a dependency of the ‘test’  
task, so that when I run my tests I can ensure the library is freshly  
built?

Alex G.

Bioinformatics Center  
Kyoto University

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [January 21, 2007, 3:37am UTC](https://www.ruby-forum.com/t/building-extensions-with-hoe/81892/2 "2007-01-21T03:37:01Z")

</div>

On Jan 15, 2007, at 17:53, Alex G. wrote:

> task :build\_extension do  
> how do other people build extensions with Rake/Hoe?  
> RubyGems looks for both an extconf.rb and an ‘extension’ rake task.

> 1. Can I retrospectively add this task as a dependency of the  
> ‘test’ task, so that when I run my tests I can ensure the library  
> is freshly built?

I’m not sure how to do this with rake, but we’d accept a patch to Hoe.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [January 21, 2007, 4:27am UTC](https://www.ruby-forum.com/t/building-extensions-with-hoe/81892/3 "2007-01-21T04:27:06Z")

</div>

Alex G. wrote:

> 1. Can I retrospectively add this task as a dependency of the ‘test’  
> task, so that when I run my tests I can ensure the library is freshly  
> built?  
> Yes. I forget exactly, but it’s something easy like  
> Rake::Task[‘test’].prerequisites \<\< ‘build\_extension’.

Devin
