Skip to content

Commit 6912786

Browse files
committed
update how to cross compile and publish native gems
1 parent d999cc6 commit 6912786

File tree

2 files changed

+66
-44
lines changed

2 files changed

+66
-44
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
bcrypt_pbkdf is a ruby gem implementing bcrypt_pbkdf from OpenBSD. This is currently used by net-ssh to read password encrypted Ed25519 keys.
44

5-
[![Build Status](https://travis-ci.org/mfazekas/bcrypt_pbkdf-ruby.png?branch=master)](https://travis-ci.org/mfazekas/bcrypt_pbkdf-ruby)
5+
[![Build Status](https://github.com/net-ssh/bcrypt_pbkdf-ruby/actions/workflows/ci.yml/badge.svg?branch=master&event=push)](https://github.com/net-ssh/bcrypt_pbkdf-ruby/actions/workflows/ci.yml)
66

7-
# Acknowledgements
7+
## Acknowledgements
88

99
* The gut of the code is based on OpenBSD's bcrypt_pbkdf.c implementation
1010
* Some ideas/code were taken adopted bcrypt-ruby: https://github.com/codahale/bcrypt-ruby
1111

12-
# Links:
12+
## Links
1313

14-
http://www.tedunangst.com/flak/post/bcrypt-pbkdf
15-
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libutil/bcrypt_pbkdf.c?rev=1.13&content-type=text/x-cvsweb-markup
14+
* http://www.tedunangst.com/flak/post/bcrypt-pbkdf
15+
* http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libutil/bcrypt_pbkdf.c?rev=1.13&content-type=text/x-cvsweb-markup
1616

17-
# Building
17+
## Building
1818

19-
For windows cross build make sure you checked out the gem source under the home directory
19+
For windows and osx cross build make sure you checked out the gem source under the home directory and have docker installed.
2020

2121
```sh
2222
gem install rake-compiler-dock
@@ -26,7 +26,7 @@ gem install rake-compiler-dock
2626
bundle exec rake compile
2727
bundle exec rake test
2828
bundle exec rake clean clobber
29-
bundle exec rake gem:windows
29+
bundle exec rake gem:all
3030
bundle exec rake release
31-
bundle exec rake gem:windows:release
31+
bundle exec rake gem:release
3232
```

Rakefile

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,19 @@ require 'rake/extensiontask'
55
require 'rake/clean'
66
require 'rdoc/task'
77
require 'benchmark'
8+
require 'rake_compiler_dock'
89

10+
CLEAN.add("{ext,lib}/**/*.{o,so}", "pkg")
911

10-
CLEAN.include(
11-
"tmp",
12-
"lib/2.0",
13-
"lib/2.1",
14-
"lib/2.2",
15-
"lib/2.3",
16-
"lib/2.4",
17-
"lib/2.5",
18-
"lib/2.6",
19-
"lib/2.7",
20-
"lib/3.0",
21-
"lib/bcrypt_pbkdf_ext.so"
22-
)
23-
CLOBBER.include(
24-
"doc",
25-
"pkg"
26-
)
27-
28-
task 'gem:windows' do
29-
require 'rake_compiler_dock'
30-
sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.
31-
RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0"
32-
end
33-
34-
task 'gem:windows:release' do
35-
version = Gem::Specification::load("bcrypt_pbkdf.gemspec").version
36-
sh "gem push pkg/bcrypt_pbkdf-#{version}-x86-mingw32.gem"
37-
sh "gem push pkg/bcrypt_pbkdf-#{version}-x64-mingw32.gem"
38-
end
12+
cross_rubies = ["3.3.0", "3.2.0", "3.1.0", "3.0.0", "2.7.0"]
13+
cross_platforms = [
14+
"arm64-darwin",
15+
"x64-mingw-ucrt",
16+
"x64-mingw32",
17+
"x86-mingw32",
18+
"x86_64-darwin",
19+
]
20+
ENV["RUBY_CC_VERSION"] = cross_rubies.join(":")
3921

4022
GEMSPEC = Gem::Specification.load("bcrypt_pbkdf.gemspec")
4123

@@ -59,13 +41,53 @@ RDoc::Task.new do |rdoc|
5941
rdoc.rdoc_files.include(*GEMSPEC.extra_rdoc_files)
6042
end
6143

62-
Gem::PackageTask.new(GEMSPEC) do |pkg|
63-
pkg.need_zip = true
64-
pkg.need_tar = true
65-
end
66-
6744
Rake::ExtensionTask.new("bcrypt_pbkdf_ext", GEMSPEC) do |ext|
6845
ext.ext_dir = 'ext/mri'
6946
ext.cross_compile = true
70-
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
47+
ext.cross_platform = cross_platforms
48+
ext.cross_config_options << "--enable-cross-build" # so extconf.rb knows we're cross-compiling
49+
end
50+
51+
namespace "gem" do
52+
cross_platforms.each do |platform|
53+
desc "build native gem for #{platform}"
54+
task platform do
55+
RakeCompilerDock.sh(<<~EOF, platform: platform, verbose: true)
56+
gem install bundler --no-document &&
57+
BUNDLE_IGNORE_CONFIG=1 BUNDLE_PATH=.bundle/#{platform} bundle &&
58+
BUNDLE_IGNORE_CONFIG=1 BUNDLE_PATH=.bundle/#{platform} bundle exec rake gem:#{platform}:buildit
59+
EOF
60+
end
61+
62+
namespace platform do
63+
# this runs in the rake-compiler-dock docker container
64+
task "buildit" do
65+
# use Task#invoke because the pkg/*gem task is defined at runtime
66+
Rake::Task["native:#{platform}"].invoke
67+
Rake::Task["pkg/#{GEMSPEC.full_name}-#{Gem::Platform.new(platform)}.gem"].invoke
68+
end
69+
70+
task "release" do
71+
sh "gem push pkg/#{GEMSPEC.full_name}-#{Gem::Platform.new(platform)}.gem"
72+
end
73+
end
74+
end
75+
76+
desc "build native gem for all platforms"
77+
task "all" do
78+
cross_platforms.each do |platform|
79+
Rake::Task["gem:#{platform}"].invoke
80+
end
81+
end
82+
83+
desc "release native gem for all platforms"
84+
task "release" do
85+
cross_platforms.each do |platform|
86+
Rake::Task["gem:#{platform}:release"].invoke
87+
end
88+
end
7189
end
90+
91+
task "package" => cross_platforms.map { |p| "gem:#{p}" } # "package" task for all the native platforms
92+
93+
Rake::Task["package"].prerequisites.prepend("compile")

0 commit comments

Comments
 (0)