Skip to content

Commit

Permalink
compile on OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Oct 12, 2024
1 parent 05cbfe5 commit 63af524
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
10 changes: 10 additions & 0 deletions doc/dev-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ pkgin install python311
ln -s /usr/pkg/bin/python3.11 /usr/pkg/bin/python3
```
### OpenBSD
```shell
pkg_add rust
pkg_add libcares
pkg_add lua
ln -s /usr/local/lib/pkgconfig/lua54.pc /usr/local/lib/pkgconfig/lua5.4.pc
pkg_add python
```
## Development Libraries
For *g3proxy*:
Expand Down
4 changes: 2 additions & 2 deletions g3keymess/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/

use std::path::PathBuf;
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "openbsd")))]
use std::str::FromStr;
use std::sync::OnceLock;

use anyhow::{anyhow, Context};
use clap::{value_parser, Arg, ArgAction, Command, ValueHint};
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "openbsd")))]
use log::info;

use g3_compat::CpuAffinity;
Expand Down
17 changes: 16 additions & 1 deletion lib/g3-socket/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,33 @@ pub fn new_std_socket_to(
let peer_family = AddressFamily::from(&peer_ip);
let socket = new_tcp_socket(peer_family)?;
bind.bind_for_connect(&socket, peer_family)?;
#[cfg(windows)]
if keepalive.is_enabled() {
// set keepalive_idle
let mut setting = TcpKeepalive::new().with_time(keepalive.idle_time());
if let Some(interval) = keepalive.probe_interval() {
setting = setting.with_interval(interval);
}
socket.set_tcp_keepalive(&setting)?;
}
#[cfg(all(unix, not(target_os = "openbsd")))]
if keepalive.is_enabled() {
// set keepalive_idle
let mut setting = TcpKeepalive::new().with_time(keepalive.idle_time());
if let Some(interval) = keepalive.probe_interval() {
setting = setting.with_interval(interval);
}
#[cfg(unix)]
if let Some(count) = keepalive.probe_count() {
setting = setting.with_retries(count);
}
socket.set_tcp_keepalive(&setting)?;
}
#[cfg(target_os = "openbsd")]
if keepalive.is_enabled() {
// set keepalive_idle
let setting = TcpKeepalive::new().with_time(keepalive.idle_time());
socket.set_tcp_keepalive(&setting)?;
}
RawSocket::from(&socket).set_tcp_misc_opts(misc_opts, default_set_nodelay)?;
Ok(std::net::TcpStream::from(socket))
}
Expand Down
4 changes: 2 additions & 2 deletions lib/g3-yaml/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ mod quinn;
#[cfg(feature = "quinn")]
pub use quinn::as_quinn_transport_config;

#[cfg(all(unix, feature = "sched"))]
#[cfg(all(unix, not(target_os = "openbsd"), feature = "sched"))]
mod sched;
#[cfg(all(unix, feature = "sched"))]
#[cfg(all(unix, not(target_os = "openbsd"), feature = "sched"))]
pub use sched::*;

#[cfg(feature = "sched")]
Expand Down
6 changes: 3 additions & 3 deletions lib/g3-yaml/src/value/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use g3_runtime::unaided::UnaidedRuntimeConfig;
pub fn as_unaided_runtime_config(v: &Yaml) -> anyhow::Result<UnaidedRuntimeConfig> {
if let Yaml::Hash(map) = v {
let mut config = UnaidedRuntimeConfig::default();
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "openbsd")))]
let mut set_mapped_sched_affinity = false;

crate::foreach_kv(map, |k, v| match crate::key::normalize(k).as_str() {
Expand All @@ -37,7 +37,7 @@ pub fn as_unaided_runtime_config(v: &Yaml) -> anyhow::Result<UnaidedRuntimeConfi
config.set_thread_stack_size(value);
Ok(())
}
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "openbsd")))]
"sched_affinity" => {
if let Yaml::Hash(map) = v {
for (ik, iv) in map.iter() {
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn as_unaided_runtime_config(v: &Yaml) -> anyhow::Result<UnaidedRuntimeConfi
_ => Err(anyhow!("invalid key {k}")),
})?;

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "openbsd")))]
if set_mapped_sched_affinity {
config
.set_mapped_sched_affinity()
Expand Down

0 comments on commit 63af524

Please sign in to comment.