Commit graph

704 commits

Author SHA1 Message Date
Nobuyoshi Nakada
68a03167a5 Suppress maybe-uninitialized warnings 2025-07-31 23:07:08 +09:00
Nobuyoshi Nakada
2fe8b9cd3d Copy to path with the base name 2025-05-12 02:50:25 +09:00
Nobuyoshi Nakada
8c9cd65d82
Fix unnecessary false in CLEANLIBS 2025-04-13 16:53:18 +09:00
Nobuyoshi Nakada
4daa5ebb77
[DOC] About create_makefile
Describe two features that were missing from the documentation:

- yields configuration part if a block is given.
- "depend" file will be included.
2025-01-14 15:34:17 +09:00
Nobuyoshi Nakada
b19fcd02fa Use the dedicated constants LIBARG and LIBPATHFLAG 2024-12-23 11:52:14 +09:00
Julien Marrec
be7e5f1f85 Implements [Feature #3456]: Support pkgconf on windows
1. Store the `PKG_CONFIG` variable in Makefile.sub (or try to get it from the ENV var PKG_CONFIG in mkmf.rb)
2. Try to use --msvc-syntax, with a fallback to replacing -Lxxx with -libpath:xxx. --msvc-syntax has been in pkgconf since 1.4.0 (released 7 years ago). pkg-config (freedesktop), does not support it, hence the fallback.
3. The `try_ldflags` passes these `ldflags` as the `opt` parameter to the `link_command`, not as `ldflags`. Unix systems are forgiving in that regard, MSVC is not: as a result as passing them as `opt`, they (specifically the `/libpath:xxx` ones) end up passed before the `-link` command to `cl.exe` and it throws because it ignores it and therefore can't find the lib.

```
cl : Command line warning D9002 : ignoring unknown option '-libpath:C:/Users/julien/.conan2/p/libff3726d89a6255c/p/lib'
```
2024-12-23 11:52:14 +09:00
Nobuyoshi Nakada
1f6d2e77d9
Remove leading spaces from LIBPATHFLAG and RPATHFLAG
Join with a space in `MakeMakefile#libpathflag` instead.
2024-09-29 23:07:16 +09:00
Yuta Saito
8b55aaa85c [Feature #20345] Add --target-rbconfig option to mkmf
Introduce a new mkmf option `--target-rbconfig` to specify the RbConfig
file for the deployment target platform. This option is useful for
cross-compiling Ruby extensions without faking the global top-level
`RbConfig` constant.
2024-04-02 14:24:54 +09:00
Nobuyoshi Nakada
0fb39ab1b9
Clean intermediate files and debug info for each target
By replacing `ALLOBJS` suffix with intermediate file suffixes instead
of roughly removing by wildcards.  Made `cleanlibs` append `.dSYM`
suffix for each word in `TARGET_SO`, not the end of the entire list.
2024-03-10 22:12:00 +09:00
Hiroshi SHIBATA
8e27c01fbb Reapply "mkmf.rb: Define missing POSTLINK variable in generated Makefile"
This reverts commit 0ae0a0c1c3.
2024-03-05 17:03:30 +09:00
Hiroshi SHIBATA
0ae0a0c1c3 Revert "mkmf.rb: Define missing POSTLINK variable in generated Makefile"
This reverts commit 71d511615b.
2024-03-05 12:08:42 +09:00
Yuta Saito
71d511615b mkmf.rb: Define missing POSTLINK variable in generated Makefile
The `POSTLINK` variable had been used in the `LINK_SO` variable, which
is used to link shared extension libraries. However, the `POSTLINK`
variable had not been defined in the generated Makefile, so extension
libraries were not properly post-processed. It was not a critical issue
for the existing `POSTLINK` usage for darwin platforms, but it would be
a problem for Wasm/WASI platform, which requires *mandatory*
post-processing for shared extension libraries.
2024-03-02 17:07:37 +09:00
Yuta Saito
57f014b2fa Use configured LD for linking enc and ext libraries
"AR" was well propagated to the enc.mk and mkmf, but "LD" was not. This
caused the dynamic libraries to be linked with a linker found in the PATH,
which could be different from the one used in the Ruby build process.
This is especially important for cross-compilation, where the host
linker may not be compatible with the target system. (e.g. WebAssembly)
2024-03-01 03:16:23 +09:00
KJ Tsanaktsidis
1d467f2255 Burn default ASAN options into the built Ruby
* We always need use_sigaltstack=0 because Ruby registers sigaltstack
  handlers
* We also need to disable leak detection (unless RUBY_FREE_AT_EXIT is
  set - I might experiment later with automatically enabling leak
  detection if RUBY_FREE_AT_EXIT is set).

Burning it into the built ruby binary in this way avoids people needing
to remember to start their Ruby program with these flags all the time.

We also need a small fix in mkmf to make sure that test programs also
don't have leak detection enabled (this is never desirable)

[Bug #20256]
2024-02-12 10:51:46 +11:00
Nobuyoshi Nakada
1817d644ee mkmf.rb: use kwargs 2024-01-10 09:18:18 +09:00
Nobuyoshi Nakada
76c20b06aa Add MakeMakefile["C"] 2024-01-08 00:33:31 +09:00
Nobuyoshi Nakada
bca1493815
[DOC] Documentation of mkmf.rb 2024-01-07 21:49:47 +09:00
Nobuyoshi Nakada
4112585be5
Too much nestings make editors confused
Get rid of nested double quotes inside nested interpolations.  Also,
remove comments that are no longer needed by the documents.
2024-01-06 13:47:06 +09:00
Nobuyoshi Nakada
52709a4862 Fix dir_config cache for -include and -lib options
Set to "--with-" options, not "--without-" keys.
2023-10-12 17:46:01 +09:00
Nobuyoshi Nakada
1cef5f597d Include default values in dir_config cache keys
The extconf.rb in mysql2 gem repeats `dir_config('mysql')`, without
and with the default path.  The third call returns the former results
even with the default path.  Since it does not check the results of
the third call, that `nil` is passed to `find_library` as a path, and
fails with `NoMethodError`.
2023-10-12 17:46:01 +09:00
Nobuyoshi Nakada
2951e3d83b
Allow nmake to ignore errors
cmd.exe can redirect file descriptor other than STDOUT, while
command.com couldn't.
2023-07-10 19:21:47 +09:00
Nobuyoshi Nakada
c8d0470bb0
Use File::NULL instead of hard coded null device names 2023-07-10 19:21:47 +09:00
Jun Aruga
57459b83a9
mkmf: Add the extra option --with-verbose to enable verbose mode. (#7863)
This commit is to add an extra option to enable verbose mode (V=1) in the
generated `Makefile` at runtime of the Ruby to print compiler command lines by
the commands below when building native extensions. It's possible to enable the
verbose mode by setting the environment variable `MAKEFLAGS="V=1"`[1]
implemented in GNU make. However, I wanted to make a consistent user-interface
not depending on the specific make's implementation.

```
$ ruby /path/to/extconf.rb -- --with-verbose
```

You can also add the extra option via rake-compiler gem.

```
$ rake compiler -- --with-verbose
```

If the extra option is not given, the value of the
`RbConfig::CONFIG["MKMF_VERBOSE"]` enabled by the configure option below is
used.

```
$ ./configure --enable-mkmf-verbose
```

For the unit tests, updated the following files.

* The `test/mkmf/test_configuration.rb` was created to test the cases with the
  `configuration` method and this implementation.
* Updated the `TestMkmf#assert_separately` to set the extra
  arguments in `test/mkmf/base.rb`. Updated tests using the `assert_separately`.
* Added tests for `MakeMakefile#with_config` in the `test/mkmf/test_config.rb`.

[1] https://www.gnu.org/software/make/manual/html_node/Variables_002fRecursion.html

Fixes [Bug #19695]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-05-29 10:09:32 +02:00
Nobuyoshi Nakada
29dc9378d9 mkmf.rb: Refine message from pkg_config 2023-01-09 21:44:15 +09:00
Nobuyoshi Nakada
0d7bbfc941 mkmf.rb: Prefer caller_locations over parsing caller 2023-01-09 21:44:15 +09:00
Nobuyoshi Nakada
b94656147b mkmf.rb: Refactor splitting configure_args and remove duplicate code 2023-01-06 20:00:53 +09:00
Nobuyoshi Nakada
613fca0148 [Bug #19189] Fallback to the default "pkg-config" 2022-12-15 11:00:42 +09:00
Nobuyoshi Nakada
facb5cd4d5
Clean compiler intermediate files more 2022-12-05 17:09:49 +09:00
Nobuyoshi Nakada
612aa5c24a
Use class methods of File over Kernel.open and IO.read 2022-11-21 22:16:49 +09:00
Nobuyoshi Nakada
6700fa7f62
Set timestamp path for the target path to TARGET_SO_DIR_TIMESTAMP 2022-10-24 17:48:00 +09:00
Nobuyoshi Nakada
7f1ca66642
Fallback PKG_CONFIG to the configured pkg-config always 2022-10-02 15:19:14 +09:00
Nobuyoshi Nakada
6898984f1c
[Bug #19005] dynamic_lookup linker option in external libraries
The warning against `-undefined dynamic_lookup` is just a warning yet,
and many gems seem to pay no attention to warnings.  Until it fails
actually, keep it as a migration path, except for standard extension
libraries and bundled extension gems.
2022-09-17 12:09:34 +09:00
Alan Wu
e5a3f23256 Use $(bindir) for path to executable in mkmf
For the macOS -bundle_loader linker option, we need a path to the
Ruby exectuable. $(RUBY) is not necessarily a path since it could
be a command line invocation. That happens during build with
runruby.rb and can happen post installation if the user passes
the --ruby option to a extconf.rb. Use $(bindir) to locate
the executable instead.

Before installation, $(bindir) doesn't exist, so we need to be
able to override $(BUILTRUBY) in such situations so test-spec
and bundled extensions could build. Use a new mkmf global,
$builtruby, to do this; set it in fake.rb and in extmk.rb.

Our build system is quite complex...
2022-08-04 16:29:22 +09:00
Yuta Saito
50d81bfbc1 Link ext bundles with bundle loader option for newer ld64
ld64 shipped with Xcode 14 emits a warning when using `-undefined
dynamic_lookup`.

```
ld: warning: -undefined dynamic_lookup may not work with chained fixups
```

Actually, `-undefined dynamic_lookup` doesn't work when:

1. Link a *shared library* with the option
2. Link it with a program that uses the chained-fixup introduced from
   macOS 12 and iOS 15
because `-undefined dynamic_lookup` uses lazy-bindings and they won't be
bound while dyld fixes-up by traversing chained-fixup info.

However, we build exts as *bundles* and they are loaded only through
`dlopen`, so it's safe to use `-undefined dynamic_lookup` in theory.
So the warning produced by ld64 is false-positive, and it results
failure of option checking in configuration. Therefore, it would be an
option to ignore the warning during our configuration.

On the other hand, `-undefined dynamic_lookup` is already deprecated on
all darwin platforms except for macOS, so it's good time to get rid of
the option. ld64 also provides `-bundle_loader <executable>` option,
which allows to resolve symbols defined in the executable symtab while
linking. It behaves almost the same with `-undefined dynamic_lookup`,
but it makes the following changes:

1. Require that unresolved symbols among input objects must be defined
   in the executable.
2. Lazy symbol binding will lookup only the symtab of the bundle loader
   executable. (`-undefined dynamic_lookup` lookups all symtab as flat
   namespace)

This patch adds `-bundle_loader $(RUBY)` when non-EXTSTATIC
configuration by assuming ruby executable can be linked before building
exts.

See "New Features" subsection under "Linking" section for chained fixup
https://developer.apple.com/documentation/xcode-release-notes/xcode-13-release-notes
2022-08-04 16:29:22 +09:00
Jun Aruga
019cbded90 mkmf: Add a configure option to set verbose mode (V=1 or 0) in mkmf.rb.
Note this change is only for `configure.ac`, not for Windows using
`win32/configure.bat`.

```
$ ./configure --help | grep mkmf
  --enable-mkmf-verbose   enable verbose in mkmf
```

Run the following command to enable the mkmf verbose mode.

```
$ ./configure --enable-mkmf-verbose
$ grep MKMF_VERBOSE config.status
S["MKMF_VERBOSE"]="1"
```

In this mkmf verbose mode, when compiling a native extension, the
`rake compile` prints the compiling commands such as
"gcc -I. <...> path/to/file" instead of "compiling path/to/file".

```
$ git clone https://github.com/deivid-rodriguez/byebug.git
$ cd byebug
$ bundle install --standalone
$ bundle exec rake compile
...
gcc -I. <...> path/to/file
...
```
2022-05-12 12:36:10 +02:00
Kaíque Kandy Koga
bdb7345ce9 Use compiled instead of complied
Capitalize creates
2022-04-26 12:38:51 -07:00
Kazuhiro NISHIYAMA
e142bea799 Remove unnecessary sort
Because `Dir.[]` returns the sorted results since Ruby 3.0.
2022-04-23 11:59:20 +09:00
Alan Wu
2304cfa4c0 Document MakeMakefile#append_cflags
This method is at least 7 years old and is widely used in the wild.
Since we need to support it, let's document it to make it discoverable.
Add docs and move it out of the `# :stopdoc:` zone.
2022-04-05 12:57:55 -04:00
Nobuyoshi Nakada
6946263a29
[DOC] make internally used classes/methods nodoc
Empty class documents are generated even with `:stopdoc:`.
2022-03-20 14:26:20 +09:00
Nobuyoshi Nakada
329c89bb42
Make implicit function declaration error [Feature #18615]
Enable `-Werror=implicit-function-declaration` by default for
building C extensions for early failures.
2022-03-17 14:37:34 +09:00
Nobuyoshi Nakada
7672f6a423
mkmf: unify duplicate code in pkg_config 2022-01-29 15:29:46 +09:00
Mike Dalessio
b90e56e624 mkmf: pkg_config accepts multiple options 2022-01-29 15:22:52 +09:00
Nobuyoshi Nakada
30268d1de6
Prefer flat_map 2021-12-10 18:39:48 +09:00
Nobuyoshi Nakada
dff8d12226 mkmf: take PKG_CONFIG_PATH from dir_config library path
So that version dependent pkg-config files can override files in
the default locations.
2021-11-26 22:32:26 +09:00
Nobuyoshi Nakada
21a29844a3 mkmf: deal with environment variables in MakeMakefile#xpopen 2021-11-26 22:32:26 +09:00
Nobuyoshi Nakada
1c3d6d6cc9 mkmf: MakeMakefile#xpopen may be passed an option hash 2021-11-26 22:32:26 +09:00
Nobuyoshi Nakada
19beb028e7
Make explicit opening files 2021-10-15 19:59:14 +09:00
Nobuyoshi Nakada
ea64e742f5
Revert "mkmf.rb: try linking at try_var" [Bug #18235]
This reverts commit 524513be39,
which can return false positive by existing but unusable symbol,
including functions.
2021-10-03 18:23:39 +09:00
Nobuyoshi Nakada
cb5a41c0a0
Get rid of incompatible-pointer-types-discards-qualifiers warning 2021-09-02 08:47:47 +09:00
Nobuyoshi Nakada
524513be39
mkmf.rb: try linking at try_var
To check for variables accessible but not declared.
2021-07-08 18:18:35 +09:00