Skip to content

Commit

Permalink
Improve pthread detection
Browse files Browse the repository at this point in the history
My initial attempts at this weren't ideal, as some people are having
trouble building Command-T, especially those with older versions of
Ruby:

  https://wincent.com/issues/2135
  https://wincent.com/issues/2153
  #65

I'd forgotten about the `have_library` method in the `MakeMakefile`
module, which not only checks for the presence of the library, but also
modifies the list of libraries to be linked:

  http://ruby-doc.org/stdlib-2.1.0/libdoc/mkmf/rdoc/MakeMakefile.html#method-i-have_library

Note that I guard all of this inside a `THREAD_MODEL` check. I believe
this should prevent us from linking to pthread when the local Ruby has
explicitly opted out of using pthread (common in older Ruby versions due
to performance overhead).

I tested this against a few versions of Ruby on my OS X box:

  1.8.7-p249
  1.9.1-p430
  1.9.2-p326
  1.9.3-p545
  2.0.0-p451
  2.1.0
  2.1.1

With the command:

  ruby -r rbconfig -e 'puts RbConfig::CONFIG["THREAD_MODEL"]'

This prints "pthread" on 1.9.1 and up, and on 1.8.7 it prints "nil". On
2.0.0 and up `RbConfig` is always visible, so this works even without
the `require`.

Hopefully this will work pretty much everywhere. Fingers crossed.

Signed-off-by: Wincent Colaiuta <win@wincent.com>

diff --git a/ruby/command-t/extconf.rb b/ruby/command-t/extconf.rb
index eedeae0..44cfacc 100644
--- a/ruby/command-t/extconf.rb
+++ b/ruby/command-t/extconf.rb
@@ -1,4 +1,4 @@
-# Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2014 Wincent Colaiuta. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are met:
@@ -36,8 +36,10 @@ def header(item)
 header('stdlib.h')
 header('string.h')

-# optional headers
-have_header('pthread.h') # sets HAVE_PTHREAD_H if found
+# optional
+if RbConfig::CONFIG['THREAD_MODEL'] == 'pthread'
+  have_library('pthread', 'pthread_create') # sets HAVE_PTHREAD_H if found
+end

 RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
  • Loading branch information
wincent committed Mar 6, 2014
1 parent ad95572 commit 069be54
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ruby/command-t/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
# Copyright 2010-2014 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -36,8 +36,10 @@ def header(item)
header('stdlib.h')
header('string.h')

# optional headers
have_header('pthread.h') # sets HAVE_PTHREAD_H if found
# optional
if RbConfig::CONFIG['THREAD_MODEL'] == 'pthread'
have_library('pthread', 'pthread_create') # sets HAVE_PTHREAD_H if found
end

RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']

Expand Down

0 comments on commit 069be54

Please sign in to comment.