Skip to content

Commit 7a5adcd

Browse files
committed
Add a dir_config for users on MacOS
- Users on MacOS that installed Ruby through different installer such as `ruby-install` will have their Ruby built with this `configure_args` `--with-libyaml-dir=/opt/homebrew/opt/libyaml`. This commit adds a `dir_config("libyaml")` so that the flag is taken in consideration. Otherwise the header and function can't be found leading to a compilation error. I'm not super familiar with C extensions, but from reading the doc it seems that `dir_config` just "pushes" to the list of directories ruby will search for libraries and include files. It shouldn't affect users that are not on MacOS.
1 parent 1c11dc3 commit 7a5adcd

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

system/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ That's pretty simple, but is enough to demonstrate the integration with `libyaml
4545
The `extconf.rb` is still simple (and similar to `isolated/ext/isolated/extconf.rb` but contains this additional block:
4646
4747
``` ruby
48+
dir_config('libyaml')
4849
unless find_header("yaml.h") && find_library("yaml", "yaml_get_version")
4950
abort("\nERROR: *** could not find libyaml development environment ***\n\n")
5051
end
5152
```
5253

54+
`dir_config` is optional and mostly for users on MacOS as most ruby installers build Ruby with the `--with-libyaml-dir=/opt/homebrew/opt/libyaml` flag. The `dir_config` allows for this flag to be taken in consideration and help Ruby determine where to search for the yaml library.
55+
5356
`find_header` and `find_library` are `MakeMakefile` helper methods which will search your system's standard directories looking for files. If it finds them, it makes sure the compile step will be able to find `yaml.h`, and the link step will be able to find the `libyaml` library file.
5457

5558
We ask `find_header` to look for the `yaml.h` header file because that's what our C code needs (see `ext/system/system.h`). We ask `find_library` to look for a library named `libyaml` and check that it has the function `yaml_get_version()` defined in it.

system/ext/system/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "mkmf"
22

3+
dir_config('libyaml')
34
unless find_header("yaml.h") && find_library("yaml", "yaml_get_version")
45
abort("\nERROR: *** could not find libyaml development environment ***\n\n")
56
end

0 commit comments

Comments
 (0)