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

refactor: allow specific sqlite engine for OpenBSD #780

Merged
merged 15 commits into from
May 2, 2024

Conversation

pacoesteban
Copy link
Contributor

OpenBSD will be removing direct access to syscall(2) soon. Shiori will stop working because of this, as some of its dependencies rely heavily on the use of syscall.Syscall*, which ends up using syscall(2). This commit removes those dependencies by reverting back to use github.com/mattn/go-sqlite3 instead of modernc.org/sqlite to deal with the sqlite database backend.

OpenBSD will be removing direct access to `syscall(2)` soon.
Shiori will stop working because of this, as some of its dependencies
rely heavily on the use of `syscall.Syscall*`, which ends up using
`syscall(2)`.  This commit removes those dependencies by reverting back
to use github.com/mattn/go-sqlite3 instead of modernc.org/sqlite to deal
with the sqlite database backend.
@fmartingr
Copy link
Member

Thanks for looking into this! As we discussed, there were going to be some roadblocks before moving forward and the CI just found the first one. If you give me permissions to your branch I can also work on this when I have some spare time.

That said, expect work on this after 1.6.0 is released. I don't want to include more breaking changes in the same release.

@pacoesteban
Copy link
Contributor Author

Thanks for looking into this! As we discussed, there were going to be some roadblocks before moving forward and the CI just found the first one. If you give me permissions to your branch I can also work on this when I have some spare time.

Yep, sure. I gave you permissions there.
As I mentioned, we could fix this with conditional compilation, so it does not have any impact on the CI as you do not ship binaries for OpenBSD (and they are kind of pointless too if there's a port), but I don't know how to do it without having duplicated files which would be ugly and difficult to maintain in the future ...

That said, expect work on this after 1.6.0 is released. I don't want to include more breaking changes in the same release.

Sure. No problem.

@fmartingr
Copy link
Member

Hey @pacoesteban, I've pushed a draft using build tags and different files. Didn't test it more than running the server locally in my machine, but can't test the openbsd part. It is supposed to build properly for openbsd using a second sqlite implementation file. Can you take a look when you have some time and let me know?

Copy link

codecov bot commented Dec 27, 2023

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 30.77%. Comparing base (595cb45) to head (74bbee7).
Report is 21 commits behind head on master.

Files Patch % Lines
internal/database/sqlite_noncgo.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #780      +/-   ##
==========================================
+ Coverage   25.58%   30.77%   +5.19%     
==========================================
  Files          47       62      +15     
  Lines        5628     4461    -1167     
==========================================
- Hits         1440     1373      -67     
+ Misses       3989     2866    -1123     
- Partials      199      222      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pacoesteban
Copy link
Contributor Author

Hey @pacoesteban, I've pushed a draft using build tags and different files. Didn't test it more than running the server locally in my machine, but can't test the openbsd part. It is supposed to build properly for openbsd using a second sqlite implementation file. Can you take a look when you have some time and let me know?

I built it with your changes on a recent snapshot of -current, but I still get a segfault at runtime because of modernc.org/libc dependency. Either I'm doing something wrong, the conditional compilation is not taking place or there is something else that is introducing the dependency on the modernc libraries.

I tried to update go module versions as I saw some "downgrades" in the diff between master and this branch, but no luck.

I'll take a deeper look tomorrow.

@fmartingr
Copy link
Member

Hey @pacoesteban, I've pushed a draft using build tags and different files. Didn't test it more than running the server locally in my machine, but can't test the openbsd part. It is supposed to build properly for openbsd using a second sqlite implementation file. Can you take a look when you have some time and let me know?

I built it with your changes on a recent snapshot of -current, but I still get a segfault at runtime because of modernc.org/libc dependency. Either I'm doing something wrong, the conditional compilation is not taking place or there is something else that is introducing the dependency on the modernc libraries.

I tried to update go module versions as I saw some "downgrades" in the diff between master and this branch, but no luck.

I'll take a deeper look tomorrow.

Tried real quick to run in a VM but it didn't load the image at all. Haven't used VMs properly in macOS for years so I will need to investigate this a little more. Thing is, I can cross-compile and it gives me no errors so I assumed the go toolchain was smart enough to ignore dependencies that didn't need. I need to investigate more.

@pacoesteban
Copy link
Contributor Author

Tried real quick to run in a VM but it didn't load the image at all. Haven't used VMs properly in macOS for years so I will need to investigate this a little more. Thing is, I can cross-compile and it gives me no errors so I assumed the go toolchain was smart enough to ignore dependencies that didn't need. I need to investigate more.

The error happens at run time. If I understand correctly, at this stage of the process (syscall elimination I mean), the symbols are there but are just NOOPs. So one can build an link against them but they fail at run time, which is what I'm seeing.

I can bring up again the test machine I prepared and grant you access if you want. Just let me know.

@fmartingr
Copy link
Member

I can bring up again the test machine I prepared and grant you access if you want. Just let me know.

I tried some guides around the internet but I had no luck even installing it in a VM under Apple's ARM virtualization layer (and I was testing latest stable release). I don't want to bother you with this and the energy consumption of it considering I'm going to use it only a few moments every now and then. Is there a way you can share a prebuilt VM I can run? I have a Linux laptop I can use.

@fmartingr
Copy link
Member

I still need to do proper testing, but it seems that the golang-migrate library uses modernc.org/sqlite underneath as well:

$ ag modernc.org vendor/**/*.go | grep -v vendor/modernc.org
vendor/github.com/golang-migrate/migrate/v4/database/sqlite/sqlite.go:16:       _ "modernc.org/sqlite"

@fmartingr
Copy link
Member

PR #876 should be the last thing needed for this.

@fmartingr fmartingr force-pushed the syscall-removal branch 6 times, most recently from 4ba2ac5 to d8806dd Compare April 27, 2024 06:25
@fmartingr fmartingr changed the title remove dependencies that use syscall.Syscall* refactor: allow custom sqlite engine for OpenBSD Apr 27, 2024
@fmartingr fmartingr changed the title refactor: allow custom sqlite engine for OpenBSD refactor: allow specific sqlite engine for OpenBSD Apr 27, 2024
@fmartingr
Copy link
Member

fmartingr commented Apr 27, 2024

Hey @pacoesteban can you test this? It should be ready to work on OpenBSD. I tried adding custom CI to run the tests on OpenBSD but I couldn't make it work. Is there some way for us to automate or get notified if we break openbsd support? We are only offering it best-effort and making no promises, but it would be good to know early in the process and not when the changes are already released.

@fmartingr fmartingr modified the milestones: 1.6.5, 1.6.4, 1.8.0, 1.7.0 Apr 27, 2024
@pacoesteban
Copy link
Contributor Author

Hey @pacoesteban can you test this? It should be ready to work on OpenBSD. I tried adding custom CI to run the tests on OpenBSD but I couldn't make it work. Is there some way for us to automate or get notified if we break openbsd support? We are only offering it best-effort and making no promises, but it would be good to know early in the process and not when the changes are already released.

yep, this seems to work in all my tests.

About the CI, I think it's because -race is not supported on OpenBSD. If I run the unittest Makefile target removing -race from GO_TEST_FLAGS, then tests pass. I don't really use GH actions much outside of work (nor do I want to go anywhere near them if I don't have to), so I have no idea if there will be other problems derived from the way the test machines are built.
Maybe we could override that variable when testing on OpenBSD and give it a try, if you're ok with it.

@fmartingr
Copy link
Member

Success? :)

@fmartingr fmartingr merged commit 02247b2 into go-shiori:master May 2, 2024
12 checks passed
truecharts-admin referenced this pull request in truecharts/public Jun 8, 2024
…0@85a47b2 by renovate (#23111)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/go-shiori/shiori](https://togithub.com/go-shiori/shiori) |
minor | `v1.6.3` -> `v1.7.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>go-shiori/shiori (ghcr.io/go-shiori/shiori)</summary>

###
[`v1.7.0`](https://togithub.com/go-shiori/shiori/releases/tag/v1.7.0)

[Compare
Source](https://togithub.com/go-shiori/shiori/compare/v1.6.3...v1.7.0)

**Always remember to backup your data before updating.**

#### Notable changes

##### System Theme
([@&#8203;Monirzadeh](https://togithub.com/Monirzadeh))
[#&#8203;924](https://togithub.com/go-shiori/shiori/issues/924)

Shiori now allows you to change the theme to light/dark or follow the
system configuration.

![Screenshot 2024-06-03 at 13 19
39](https://togithub.com/go-shiori/shiori/assets/812088/76e3e062-e36c-4118-84d5-563ad48334cb)

##### New migrations backend
([@&#8203;fmartingr](https://togithub.com/fmartingr))
[#&#8203;876](https://togithub.com/go-shiori/shiori/issues/876)

The underlying migrations system has been rewritten to custom code
removing the [go-migrate
dependency](https://togithub.com/golang-migrate/migrate).

This not only removes one more dependency but also allows for more
control over the migrations process by letting us add run code in a
migration, for example, to update the database schema.

This should be transparent for all users but if you find any problems
please [report
it](https://togithub.com/go-shiori/shiori/issues/new/choose)

##### OpenBSD support
([@&#8203;pacoesteban](https://togithub.com/pacoesteban))
[#&#8203;780](https://togithub.com/go-shiori/shiori/issues/780)

This has been in the works for several months since we broke it around
1.5 but thanks to the above migration changes and some custom database
engine backend for OpenBSD, we are now able to support OpenBSD again. We
added a CI step to get early warnings if we introduce something that
breaks support.

#### What's Changed

- feat: new migration system by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/876](https://togithub.com/go-shiori/shiori/pull/876)
- chore(deps): bump the all group across 1 directory with 4 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/go-shiori/shiori/pull/895](https://togithub.com/go-shiori/shiori/pull/895)
- refactor: allow specific sqlite engine for OpenBSD by
[@&#8203;pacoesteban](https://togithub.com/pacoesteban) in
[https://github.com/go-shiori/shiori/pull/780](https://togithub.com/go-shiori/shiori/pull/780)
- chore(deps): bump the all group across 1 directory with 4 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/go-shiori/shiori/pull/900](https://togithub.com/go-shiori/shiori/pull/900)
- chore(deps): bump the all group with 4 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/go-shiori/shiori/pull/902](https://togithub.com/go-shiori/shiori/pull/902)
- fix: not checking for nil-pointer errors on migrations by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/906](https://togithub.com/go-shiori/shiori/pull/906)
- ci: unify local and ci docker workflows by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/907](https://togithub.com/go-shiori/shiori/pull/907)
- fix: ensure tmp folder is present on docker container by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/910](https://togithub.com/go-shiori/shiori/pull/910)
- deps: update golang dependencies by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/915](https://togithub.com/go-shiori/shiori/pull/915)
- chore(deps): bump the all group with 3 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/go-shiori/shiori/pull/908](https://togithub.com/go-shiori/shiori/pull/908)
- chore(deps): bump the all group with 2 updates by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/go-shiori/shiori/pull/917](https://togithub.com/go-shiori/shiori/pull/917)
- feat: Home button clear search query by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[https://github.com/go-shiori/shiori/pull/916](https://togithub.com/go-shiori/shiori/pull/916)
- chore(deps): bump codecov/codecov-action from 4.4.0 to 4.4.1 in the
all group by [@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/go-shiori/shiori/pull/922](https://togithub.com/go-shiori/shiori/pull/922)
- chore: check for avx2 processor feature when trying to run bun by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[https://github.com/go-shiori/shiori/pull/920](https://togithub.com/go-shiori/shiori/pull/920)
- ci: fix codecov action by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/928](https://togithub.com/go-shiori/shiori/pull/928)
- fix: incorrect original link in archive page by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/931](https://togithub.com/go-shiori/shiori/pull/931)
- fix : wrong response type for readable endpoint documentation by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[https://github.com/go-shiori/shiori/pull/932](https://togithub.com/go-shiori/shiori/pull/932)
- feat: allow selecting light/dark/follow themes in the webui by
[@&#8203;Monirzadeh](https://togithub.com/Monirzadeh) in
[https://github.com/go-shiori/shiori/pull/924](https://togithub.com/go-shiori/shiori/pull/924)
- fix: add version to goreleaser archive filename by
[@&#8203;fmartingr](https://togithub.com/fmartingr) in
[https://github.com/go-shiori/shiori/pull/934](https://togithub.com/go-shiori/shiori/pull/934)

#### New Contributors

- [@&#8203;pacoesteban](https://togithub.com/pacoesteban) made their
first contribution in
[https://github.com/go-shiori/shiori/pull/780](https://togithub.com/go-shiori/shiori/pull/780)

**Full Changelog**:
go-shiori/shiori@v1.6.3...v1.7.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zOTkuMyIsInVwZGF0ZWRJblZlciI6IjM3LjM5OS4zIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbImF1dG9tZXJnZSIsInVwZGF0ZS9kb2NrZXIvZ2VuZXJhbC9ub24tbWFqb3IiXX0=-->
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

Successfully merging this pull request may close these issues.

2 participants