Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Makefiles use GNU make specific syntax #299

Open
jeremyevans opened this issue Dec 29, 2023 · 4 comments
Open

Generated Makefiles use GNU make specific syntax #299

jeremyevans opened this issue Dec 29, 2023 · 4 comments

Comments

@jeremyevans
Copy link

Ruby's mkmf is designed to support both GNU make and BSD make (and Ruby itself can be built with both GNU make and BSD make), and it would be nice if the Makefiles produced by create_rust_makefile worked with both.

Example (using commonmarker gem, attempting to build on OpenBSD):

$ cat extconf.rb
require "mkmf"
require "rb_sys/mkmf"

create_rust_makefile("commonmarker/commonmarker")
$ ruby extconf.rb
checking for cc... yes
checking for c++... yes
checking for ar... yes
$ make
*** Parse error in /usr/obj/ports/commonmarker-1.0.3-ruby32/gem-tmp/.gem/ruby/3.2/gems/commonmarker-1.0.3/ext/commonmarker: Missing dependency operator (Makefile:8)
*** Parse error: Need an operator in 'endif' (Makefile:10)
*** Parse error: Missing dependency operator (Makefile:20)
*** Parse error: Need an operator in 'else' (Makefile:22)
*** Parse error: Need an operator in 'endif' (Makefile:24)
*** Parse error: Missing dependency operator (Makefile:31)
*** Parse error: Need an operator in 'else' (Makefile:33)
*** Parse error: Need an operator in 'endif' (Makefile:35)
*** Parse error: Missing dependency operator (Makefile:265)
*** Parse error: Need an operator in 'endif' (Makefile:267)
*** Parse error: Missing dependency operator (Makefile:523)
*** Parse error: Missing dependency operator (Makefile:528)
*** Parse error: Need an operator in 'endif' (Makefile:530)
*** Parse error: Missing dependency operator (Makefile:534)
*** Parse error: Need an operator in 'else' (Makefile:536)
*** Parse error: Need an operator in 'endif' (Makefile:538)
*** Parse error: Need an operator in 'endif' (Makefile:557)
$ gmake
generating target/release/libcommonmarker.so (release)
cargo rustc  --manifest-path ./Cargo.toml --target-dir target --lib --profile release -- -C linker=cc -L native=/usr/local/lib -L native=/usr/local/lib -C link-arg=-lm -C link-arg=-pthread
...
@stanhu
Copy link
Contributor

stanhu commented Jan 2, 2024

As far as I can tell, Ruby's mkmf doesn't generate Makefiles with conditional expressions, which seems to be the main source of issues above.

I think Ruby also uses autotools to generate the Makefile, which is why it works both on GNU and BSD make.

If we added support for BSD make, I think mkmf.rb would have to:

  1. Detect whether BSD make was being used. As far as I can tell, there's no -v or --version argument that makes it obvious that BSD make is used:
# gmake -v
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# bmake -h
usage: bmake [-BeikNnqrstWwX]
            [-C directory] [-D variable] [-d flags] [-f makefile]
            [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]
            [-V variable] [-v variable] [variable=value] [target ...]
  1. Update the conditional expressions for BSD make.

I'm not sure it's worth it to do this. It might be better just to document that MAKE=gmake can be set in the environment.

@mfechner
Copy link

mfechner commented Jan 2, 2024

Maybe something similar to this can be used:
https://github.com/redis/hiredis-rb/blob/master/ext/hiredis_ext/extconf.rb#L19-L27

stanhu added a commit to stanhu/rubygems that referenced this issue Jan 2, 2024
The BSD `make` is not compatible with many directives in GNU make.
For FreeBSD and Solaris systems, default to `gmake` so that native gem
builds work without having to specify `MAKE=gmake` in the environment.

Relates to:
* oxidize-rb/rb-sys#299
* redis/hiredis-rb#23
@stanhu
Copy link
Contributor

stanhu commented Jan 2, 2024

That could work. I submitted rubygems/rubygems#7348.

stanhu added a commit to stanhu/rubygems that referenced this issue Jan 2, 2024
The BSD `make` is not compatible with many directives in GNU make.
For FreeBSD and Solaris systems, default to `gmake` so that native gem
builds work without having to specify `MAKE=gmake` in the environment.

Relates to:
* oxidize-rb/rb-sys#299
* redis/hiredis-rb#23
@ianks
Copy link
Collaborator

ianks commented May 30, 2024

I think the ultimate solution will be to compile to a generic-enough Make syntax to not break... tedious change though. Maybe in the meantime we can add a warning / better error message @stanhu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants