orm: cross compile pg to linux; openssl: make cross compile work

This commit is contained in:
Alexander Medvednikov 2024-10-28 17:36:41 +03:00
parent 986ed33deb
commit 27ff2f1628
5 changed files with 27 additions and 6 deletions

View File

@ -43,7 +43,9 @@ For a list of all features and fixes, check out the changelog.
- [x] Lambdas: `a.sort(|a, b| a > b)` - [x] Lambdas: `a.sort(|a, b| a > b)`
- [ ] Custom attributes - [ ] Custom attributes
- [ ] Contexts that are passed implicitly (e.g. for custom allocation/memory management) - [ ] Contexts that are passed implicitly (e.g. for custom allocation/memory management)
- [x] Implicit Veb contexts passed to requests
- [ ] Direct C/C++ interop without generating wrappers - [ ] Direct C/C++ interop without generating wrappers
- [ ] Make ORM work without installing developer libs (libpq-dev etc)
## [Version 0.6] ## [Version 0.6]

View File

@ -12,6 +12,7 @@ $if $pkgconfig('libpq') {
#flag -lpq #flag -lpq
} }
#flag linux -I/usr/include/postgresql #flag linux -I/usr/include/postgresql
//#flag linux -Ipostgresql // cross compiling to linux
#flag darwin -I/opt/local/include/postgresql11 #flag darwin -I/opt/local/include/postgresql11
#flag darwin -L/opt/local/lib/postgresql11 #flag darwin -L/opt/local/lib/postgresql11
@ -32,12 +33,19 @@ $if $pkgconfig('libpq') {
#flag freebsd -L/usr/local/lib #flag freebsd -L/usr/local/lib
} }
$if cross_compile ? && linux {
#include <libpq/libpq-fe.h>
#include <libpq/pg_config.h>
//#flag -lpq // libpq.a is located in LINUXROOT/lib/x86_64-linux-gnu/libpq.a
} $else {
// PostgreSQL Source Code // PostgreSQL Source Code
// https://doxygen.postgresql.org/libpq-fe_8h.html // https://doxygen.postgresql.org/libpq-fe_8h.html
#include <libpq-fe.h> #include <libpq-fe.h>
// for PG_VERSION_NUM, which is defined everywhere at least since PG 9.5 // for PG_VERSION_NUM, which is defined everywhere at least since PG 9.5
#include <pg_config.h> #include <pg_config.h>
}
// for orm // for orm
$if windows { $if windows {

View File

@ -1,5 +1,7 @@
module openssl module openssl
#define OPENSSL_API_COMPAT 0x30000000L
// On Linux, prefer a locally built openssl, because it is // On Linux, prefer a locally built openssl, because it is
// much more likely for it to be newer, than the system // much more likely for it to be newer, than the system
// openssl from libssl-dev. If there is no local openssl, // openssl from libssl-dev. If there is no local openssl,
@ -116,6 +118,8 @@ fn C.SSL_set_cipher_list(ctx &SSL, str &char) int
fn C.SSL_get_peer_certificate(ssl &SSL) &C.X509 fn C.SSL_get_peer_certificate(ssl &SSL) &C.X509
// fn C.SSL_get1_peer_certificate(ssl &SSL) &C.X509
fn C.X509_free(const_cert &C.X509) fn C.X509_free(const_cert &C.X509)
fn C.ERR_clear_error() fn C.ERR_clear_error()

View File

@ -105,7 +105,9 @@ pub fn (cflags []CFlag) c_options_without_object_files() []string {
pub fn (cflags []CFlag) c_options_only_object_files() []string { pub fn (cflags []CFlag) c_options_only_object_files() []string {
mut args := []string{} mut args := []string{}
for flag in cflags { for flag in cflags {
if flag.value.ends_with('.o') || flag.value.ends_with('.obj') { // TODO figure out a better way to copy cross compiling flags to the linker
if flag.value.ends_with('.o') || flag.value.ends_with('.obj')
|| (flag.name == '-l' && flag.value == 'pq') {
args << flag.format() args << flag.format()
} }
} }

View File

@ -138,6 +138,11 @@ pub fn (mut p Preferences) fill_with_defaults() {
} }
rpath_name := os.file_name(rpath) rpath_name := os.file_name(rpath)
p.building_v = !p.is_repl && (rpath_name == 'v' || rpath_name == 'vfmt.v') p.building_v = !p.is_repl && (rpath_name == 'v' || rpath_name == 'vfmt.v')
if p.os == .linux {
$if !linux {
p.parse_define('cross_compile')
}
}
if p.output_cross_c { if p.output_cross_c {
// avoid linking any GC related code, since the target may not have an usable GC system // avoid linking any GC related code, since the target may not have an usable GC system
p.gc_mode = .no_gc p.gc_mode = .no_gc