@@ -25,12 +25,26 @@ struct Opt {
25
25
#[ arg( short, long) ]
26
26
#[ allow( dead_code) ]
27
27
jack : bool ,
28
+ /// Use the Pipewire host
29
+ #[ cfg( all(
30
+ any(
31
+ target_os = "linux" ,
32
+ target_os = "dragonfly" ,
33
+ target_os = "freebsd" ,
34
+ target_os = "netbsd"
35
+ ) ,
36
+ feature = "pipewire"
37
+ ) ) ]
38
+ #[ allow( dead_code) ]
39
+ pipewire : bool ,
28
40
}
29
41
30
42
fn main ( ) -> anyhow:: Result < ( ) > {
31
43
let opt = Opt :: parse ( ) ;
32
44
33
45
// Conditionally compile with jack if the feature is specified.
46
+ // Manually check for flags. Can be passed through cargo with -- e.g.
47
+ // cargo run --release --example beep --features jack -- --jack
34
48
#[ cfg( all(
35
49
any(
36
50
target_os = "linux" ,
@@ -40,8 +54,6 @@ fn main() -> anyhow::Result<()> {
40
54
) ,
41
55
feature = "jack"
42
56
) ) ]
43
- // Manually check for flags. Can be passed through cargo with -- e.g.
44
- // cargo run --release --example beep --features jack -- --jack
45
57
let host = if opt. jack {
46
58
cpal:: host_from_id ( cpal:: available_hosts ( )
47
59
. into_iter ( )
@@ -53,14 +65,37 @@ fn main() -> anyhow::Result<()> {
53
65
cpal:: default_host ( )
54
66
} ;
55
67
68
+ // Conditionally compile with PipeWire if the feature is specified.
69
+ #[ cfg( all(
70
+ any(
71
+ target_os = "linux" ,
72
+ target_os = "dragonfly" ,
73
+ target_os = "freebsd" ,
74
+ target_os = "netbsd"
75
+ ) ,
76
+ feature = "pipewire"
77
+ ) ) ]
78
+ // Manually check for flags. Can be passed through cargo with -- e.g.
79
+ // cargo run --release --example beep --features pipewire -- --pipewire
80
+ let host = if opt. pipewire {
81
+ cpal:: host_from_id ( cpal:: available_hosts ( )
82
+ . into_iter ( )
83
+ . find ( |id| * id == cpal:: HostId :: PipeWire )
84
+ . expect (
85
+ "make sure --features pipewire is specified. only works on OSes where PipeWire is available" ,
86
+ ) ) . expect ( "PipeWire host unavailable" )
87
+ } else {
88
+ cpal:: default_host ( )
89
+ } ;
90
+
56
91
#[ cfg( any(
57
92
not( any(
58
93
target_os = "linux" ,
59
94
target_os = "dragonfly" ,
60
95
target_os = "freebsd" ,
61
96
target_os = "netbsd"
62
97
) ) ,
63
- not( feature = "jack" )
98
+ not( any ( feature = "jack" , feature = "pipewire" ) )
64
99
) ) ]
65
100
let host = cpal:: default_host ( ) ;
66
101
0 commit comments