Skip to content

Conversation

@nomisRev
Copy link

@nomisRev nomisRev commented Oct 16, 2022

Fixes #3
by using Setup PostgreSQL for Linux/macOS/Windows for running PostgreSQL service on both ubuntu-latest and macos-latest.

Copy link
Owner

@hfhbd hfhbd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nice, thank you!

@hfhbd hfhbd enabled auto-merge (squash) October 16, 2022 19:53
@nomisRev
Copy link
Author

Hey @hfhbd,

My pleasure! I find this a super interesting endeavour, and seems like a good point for me to contribute a bit to the SqlDelight Postgres efforts. I am having some issues building locally on my M1 machine, do you perhaps have any idea? This would be great so I can debug locally, instead of having to run builds on my repo's Github Actions 😅

I am seeing the following issue, but Googling hasn't yield any results after install brew install libpq. I've tried all different kind of brew link and setting the recommended environment and path option from brew but without any change in the result.

ld.lld: error: undefined symbol: PQsetdbLogin
>>> referenced by out
>>>               /var/folders/qs/9sb020z91_z1_f50v18bnmf00000gn/T/konan_temp7434751582350192226/result.o:(libpq_PQsetdbLogin_wrapper5)
>>> did you mean: _PQsetdbLogin
>>> defined in: /opt/homebrew/opt/libpq/lib/libpq.a

@nomisRev
Copy link
Author

The row number 0 is out of range 0..-1 is also what I've seen on my CI setup, but not sure yet if it's something wrong yet with the introduced Github Action or a bug we're seeing now in contrast to the previous CI setup 🤔

Googling that error turned up it's related to incorrect libpq code, but it's curious that you didn't run into it before...
Since I cannot build locally I've not been able to test against a docker-compose postgres server.

There are other options to run Postgres on MacOs that we can try, but I hoped to use this simpler action to not introduce more complex scripts such as this: https://gist.github.com/jaredh159/634285e52456fefc9f04fb2b4bd3af28

@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

Hey @nomisRev
I have a M1 mac too and yes, I have the same errors, but only sometimes. I don't know if you need a clean build... Did you install libpq with the correct linker and compiler env? homebrew usually echoes the config after installing libpq.

compilerOpts = -I/home/linuxbrew/.linuxbrew/opt/libpq/include -I/opt/homebrew/opt/libpq/include -I/usr/local/opt/libpq/include

Locally I just use docker: docker run -e POSTGRES_PASSWORD=password -p 5432:5432 postgres to test the driver. I get this error locally too: row number 0 is out of range 0..-1, but the test and the code do work.

@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

I mean this:

If you need to have libpq first in your PATH, run:
  echo 'export PATH="/home/linuxbrew/.linuxbrew/opt/libpq/bin:$PATH"' >> /home/runner/.bash_profile
For compilers to find libpq you may need to set:
  export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/libpq/lib"
  export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/libpq/include"

@nomisRev
Copy link
Author

nomisRev commented Oct 17, 2022

Hmm strange. I have following in at the bottom of my.zprofile.

export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"

and it seems to match what you have in postgres-native-sqldelight/postgres-native-sqldelight-driver/src/nativeInterop/cinterop/libpq.def

I am consistently getting this error. I even tried deleting .konan and using --no-daemon clean build 😕

@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

The test wrongCredentials failed. I guess, the new action setup does not reject wrong credentials.

@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

Hm, I have this in my .zshrc:

export PATH="/opt/homebrew/opt/libpq/bin:$PATH"

@nomisRev
Copy link
Author

nomisRev commented Oct 17, 2022

Okay, I think I got it to work. Some thoughts/findings:

  • I can run the tests from IDEA but running ./gradlew test doesn't run the test. So I assume ./gradlew build doesn't either, but running ./gradlew :testing:macosArm64Test does, so maybe tests are currently not running on CI since we run ./gradlew assemble and ./gradlew build.

  • Running ./gradlew build doesn't work locally, so perhaps we should document in the README.MD or CONTRIBUTIONS.MD how to setup your machine for this project, and what command you need to run for which machine you're building on. Alternatively, we can perhaps dynamically only enable the targets for the platform you're building on. I.e. I cannot build linuxX64 or macosX64 on my Arm64 machine. Which commands do you run locally?

I'm happy to create PRs with the relevant changes depending on your thoughts ☺️

@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

🤯 Thanks for the investigation. Indeed, I only run macosArm64Test locally... Interesting, building the arm artifacts on macosX64 works (the artifacts are published and works on arm)

But at least on ubuntu-latest, which uses linuxX64, .gradlew build does work, otherwise, the wrong credential test won't fail :D

Feel free to add it to the README.md (or I can take it too).
But in the end, this is a Kotlin error, so one of us should create a youtrack ticket.

@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

I created a ticket for the wrong rejected credentials.

Until this bug is fixed, let's keep the current behavior and test linux only.

  1. I will add a short description of how to set up your machine and which tests do work.
  2. @nomisRev Do you want to create the youtrack ticket? Otherwise, I can take it too.

@nomisRev
Copy link
Author

Interesting, building the arm artifacts on macosX64 works (the artifacts are published and works on arm)

It seems this works, but not the other way around. At least on my aarch64 machine :/

But in the end, this is a Kotlin error, so one of us should create a YouTrack ticket.

Okay, I think I found what the bug is with ./gradlew build in the Kotlin Gradle Plugin. At least for me, could you perhaps verify this before we create a ticket on YT?

When I run ./gradlew build on my Mac M1 it runs the test the first time, but if they FAILED they're cached and won't run again unless you clean or --rerun-tasks so this results in a false positive.

@nomisRev
Copy link
Author

nomisRev commented Oct 17, 2022

Sounds good! I can create the YouTrack issue. Thanks for looking into this with me @hfhbd 🙏 I now also figured out how to setup CI and local dev for my own project, and can continue testing this driver in a "real-life" project 🙌

@nomisRev nomisRev closed this Oct 17, 2022
auto-merge was automatically disabled October 17, 2022 12:48

Pull request was closed

@nomisRev nomisRev deleted the nomisRev-3-macos-ci branch October 17, 2022 12:48
@hfhbd
Copy link
Owner

hfhbd commented Oct 17, 2022

Okay, I think I found what the bug is with ./gradlew build in the Kotlin Gradle Plugin. At least for me, could you perhaps verify this before we create a ticket on YT?

When I run ./gradlew build on my Mac M1 it runs the test the first time, but if they FAILED they're cached and won't run again unless you clean or --rerun-tasks so this results in a false positive.

What do you mean?
If I run ./gradlew clean ./gradlew build it fails on M1 mac because of X64 linking problems. Running ./gradlew build again still fails.

@nomisRev
Copy link
Author

nomisRev commented Oct 17, 2022

Sorry, I was talking about a separate issue that I am experiencing when only having macosArm64 configured. I temporarily disabled the other targets locally while investigating the issues with ./gradlew build.

I created two separate YouTrack issues:

https://youtrack.jetbrains.com/issue/KT-54505/Build-macosX64-from-macosArm64
https://youtrack.jetbrains.com/issue/KT-54506/Incorrect-cached-macosArm64Test-task-resulting-in-false-positive

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.

macOS CI

2 participants