Skip to content

Commit 36e8732

Browse files
authored
Fixes for macos, add changelog (#2)
* update readme for macos sqlite3 .load issue * use full file path (with DLEXT) to fix macos issues * add a changelog * add macos and ruby 3.4 to ci * update gemspec, bump version
1 parent 3642894 commit 36e8732

File tree

7 files changed

+143
-19
lines changed

7 files changed

+143
-19
lines changed

.github/workflows/ruby.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
name: CI
22

33
on:
4-
push:
5-
branches: [ "main" ]
64
pull_request:
75
branches: [ "main" ]
86

9-
permissions:
10-
contents: read
11-
127
jobs:
138
test:
14-
runs-on: ubuntu-latest
9+
runs-on: ${{ matrix.os }}
1510
strategy:
1611
matrix:
17-
ruby-version: ['3.3']
12+
ruby-version: ['3.3', '3.4']
13+
os: [ubuntu-latest, macos-latest]
1814

1915
steps:
2016
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# sqlite_extensions-uuid
2+
3+
* Source code: https://github.com/jethrodaniel/sqlite_extensions-uuid
4+
* Ruby gem: https://rubygems.org/gems/sqlite_extensions-uuid
5+
6+
## [Unreleased]
7+
8+
## v1.0.2 - 2025-07-03
9+
10+
* Update `SqliteExtensions::UUID.to_path` to include the library's file extension.
11+
12+
When loading an extension without a filename (at least on MacOS and Linux),
13+
SQLite looks for a file ending in `.dylib` and `.so`, respectively.
14+
15+
As a result, if your extension is a `.bundle` file (on MacOS), then you
16+
need to pass the full path.
17+
18+
Passing the full path shouldn't be an issue on any platform anyway.
19+
20+
NOTE: we determine the extension using `RbConfig::CONFIG["DLEXT"]`, and we
21+
don't check if the file actually exists, we just construct the path.
22+
23+
* Internal cleanup: add a changelog, add MacOS to CI, update gemspec
24+
25+
26+
## v1.0.1 - 2025-03-20
27+
28+
* Add `SqliteExtensions::UUID::VERSION`, use RSpec for internal tests.
29+
30+
## v1.0.0 - 2024-12-07
31+
32+
* Require `sqlite3-ruby` 2.4+ so we can use `sqlite3-ruby`'s extension
33+
loading support.
34+
35+
Now that sqlite3-ruby natively supports loading extensions, we can load
36+
extensions in Rails apps without having to monkey-patch anything, like so:
37+
38+
```ruby
39+
gem "sqlite_extensions-uuid"
40+
```
41+
42+
```yaml
43+
development:
44+
adapter: sqlite3
45+
extensions:
46+
- <%= SqliteExtensions::UUID.to_path %>
47+
```

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,55 @@ It then exposes a method, `SqliteExtensions::UUID.to_path`, which returns the lo
7474

7575
This can be passed to [sqlite3](https://github.com/sparklemotion/sqlite3-ruby) in `Database.new(extensions: [])` or `Database#load_extension`.
7676

77+
## Issues
78+
79+
### Missing `.load` command
80+
81+
The default `sqlite3` on MacOS doesn't allow loading runtime extensions, so you'll need to use a version that does, e.g, from `brew` (`brew install sqlite3`).
82+
83+
```console
84+
% /usr/bin/sqlite3
85+
SQLite version 3.43.2 2023-10-10 13:08:14
86+
Enter ".help" for usage hints.
87+
Connected to a transient in-memory database.
88+
Use ".open FILENAME" to reopen on a persistent database.
89+
sqlite> .load
90+
Error: unknown command or invalid arguments: "load". Enter ".help" for help
91+
```
92+
93+
If using `brew`, you'll want to follow the suggestions from `brew info sqlite3`:
94+
95+
```console
96+
% brew info sqlite3
97+
...
98+
==> Caveats
99+
sqlite is keg-only, which means it was not symlinked into /opt/homebrew,
100+
because macOS already provides this software and installing another version in
101+
parallel can cause all kinds of trouble.
102+
103+
If you need to have sqlite first in your PATH, run:
104+
echo 'export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"' >> ~/.zshrc
105+
106+
For compilers to find sqlite you may need to set:
107+
export LDFLAGS="-L/opt/homebrew/opt/sqlite/lib"
108+
export CPPFLAGS="-I/opt/homebrew/opt/sqlite/include"
109+
110+
For pkg-config to find sqlite you may need to set:
111+
export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig"
112+
```
113+
114+
Afterwards, check that `.load` support works:
115+
116+
```console
117+
% sqlite3
118+
SQLite version 3.50.1 2025-06-06 14:52:32
119+
Enter ".help" for usage hints.
120+
Connected to a transient in-memory database.
121+
Use ".open FILENAME" to reopen on a persistent database.
122+
(ins)sqlite> .load
123+
Usage: .load FILE ?ENTRYPOINT?
124+
```
125+
77126
## Development
78127

79128
```shell

lib/sqlite_extensions/uuid.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# frozen_string_literal: true
22

3+
require "rbconfig"
4+
35
module SqliteExtensions
46
module UUID
57
def self.to_path
68
spec = Gem.loaded_specs["sqlite_extensions-uuid"]
7-
File.join(spec.require_path, "sqlite_extensions/uuid/uuid")
9+
path = File.join(spec.require_path, "sqlite_extensions/uuid/uuid")
10+
path + "." + RbConfig::CONFIG.fetch("DLEXT")
811
end
912
end
1013
end

lib/sqlite_extensions/uuid/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module SqliteExtensions
44
module UUID
5-
VERSION = "1.0.1"
5+
VERSION = "1.0.2"
66
end
77
end

spec/sqlite_extensions/uuid_spec.rb

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

33
RSpec.describe SqliteExtensions::UUID do
44
it "has a version" do
5-
expect(described_class::VERSION).to eq "1.0.1"
5+
expect(described_class::VERSION).to eq "1.0.2"
66
end
77

88
describe "#to_path" do
9+
subject { described_class.to_path }
10+
911
before do
1012
gemspec = instance_double(Gem::Specification, require_path: "foo")
1113
allow(Gem).to receive(:loaded_specs).and_return("sqlite_extensions-uuid" => gemspec)
1214
end
1315

14-
it "returns the path to the compiled extension" do
15-
path = described_class.to_path
16+
context "when linux" do
17+
before do
18+
allow(RbConfig::CONFIG).to receive(:fetch).with("DLEXT").and_return("so")
19+
end
20+
21+
it { is_expected.to eq "foo/sqlite_extensions/uuid/uuid.so" }
22+
end
23+
24+
context "when mac with .dylib extension" do
25+
before do
26+
allow(RbConfig::CONFIG).to receive(:fetch).with("DLEXT").and_return("dylib")
27+
end
28+
29+
it { is_expected.to eq "foo/sqlite_extensions/uuid/uuid.dylib" }
30+
end
31+
32+
context "when mac with .bundle extension" do
33+
before do
34+
allow(RbConfig::CONFIG).to receive(:fetch).with("DLEXT").and_return("bundle")
35+
end
1636

17-
expect(path).to eq "foo/sqlite_extensions/uuid/uuid"
37+
it { is_expected.to eq "foo/sqlite_extensions/uuid/uuid.bundle" }
1838
end
1939
end
2040

21-
it "has the correct gemspec info" do
41+
it "has the correct gemspec info" do # rubocop:disable RSpec/ExampleLength
2242
path = File.expand_path("../../sqlite_extensions-uuid.gemspec", __dir__)
2343
gemspec = Gem::Specification.load path
2444

2545
expect(gemspec).to have_attributes(
2646
name: "sqlite_extensions-uuid",
27-
version: Gem::Version.new("1.0.1"),
47+
version: Gem::Version.new("1.0.2"),
2848
files: %w[
2949
ext/sqlite_extensions/uuid/extconf.rb
3050
ext/sqlite_extensions/uuid/sqlite3.h
@@ -35,13 +55,18 @@
3555
lib/sqlite_extensions/uuid/version.rb
3656
],
3757
licenses: ["MIT"],
38-
metadata: {},
58+
metadata: {
59+
"allowed_push_host" => "https://rubygems.org",
60+
"changelog_uri" => "https://github.com/jethrodaniel/sqlite_extensions-uuid/blob/main/CHANGELOG.md",
61+
"homepage_uri" => "https://github.com/jethrodaniel/sqlite_extensions-uuid",
62+
"source_code_uri" => "https://github.com/jethrodaniel/sqlite_extensions-uuid"
63+
},
3964
required_ruby_version: Gem::Requirement.new([">= 3.0.0"]),
40-
summary: "SQLite's UUID v4 extension, packaged as a gem"
65+
summary: "SQLite's UUID v4 extension, packaged as a gem."
4166
)
4267
require_paths = gemspec.require_paths
4368
expect(require_paths.size).to eq 2
44-
expect(require_paths.first).to end_with "sqlite_extensions-uuid-1.0.1"
69+
expect(require_paths.first).to end_with "sqlite_extensions-uuid-1.0.2"
4570
expect(require_paths.last).to eq "lib"
4671
end
4772
end

sqlite_extensions-uuid.gemspec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ Gem::Specification.new do |spec|
88
spec.authors = ["Mark Delk"]
99
spec.email = ["[email protected]"]
1010

11-
spec.summary = "SQLite's UUID v4 extension, packaged as a gem"
11+
spec.summary = "SQLite's UUID v4 extension, packaged as a gem."
1212
spec.homepage = "https://github.com/jethrodaniel/sqlite_extensions-uuid"
1313
spec.license = "MIT"
1414
spec.required_ruby_version = ">= 3.0.0"
15+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
16+
spec.metadata["homepage_uri"] = spec.homepage
17+
spec.metadata["source_code_uri"] = spec.homepage
18+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
1519

1620
spec.files = Dir.glob("lib/**/*.rb") + Dir.glob("ext/**/*.{c,h}")
1721
spec.require_paths = ["lib"]

0 commit comments

Comments
 (0)