mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2325e8fa4c | |||
| 6906d63013 | |||
| 16de2a2cc0 | |||
| 108a4fe336 | |||
| 83396db5de | |||
| 839138c02e | |||
| e03c90c2ac |
@@ -149,37 +149,6 @@ runs:
|
||||
- name: Setup sccache
|
||||
uses: https://git.tomfos.tr/tom/sccache-action@v1
|
||||
|
||||
- name: Cache dependencies
|
||||
id: deps-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
target/**/.fingerprint
|
||||
target/**/deps
|
||||
target/**/*.d
|
||||
target/**/.cargo-lock
|
||||
target/**/CACHEDIR.TAG
|
||||
target/**/.rustc_info.json
|
||||
/timelord/
|
||||
# Dependencies cache - based on Cargo.lock, survives source code changes
|
||||
key: >-
|
||||
continuwuity-deps-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
continuwuity-deps-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-
|
||||
|
||||
- name: Cache incremental compilation
|
||||
id: incremental-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
target/**/incremental
|
||||
# Incremental cache - based on source code changes
|
||||
key: >-
|
||||
continuwuity-incremental-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-${{ hashFiles('**/*.rs', '**/Cargo.toml') }}
|
||||
restore-keys: |
|
||||
continuwuity-incremental-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-
|
||||
continuwuity-incremental-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ steps.rust-setup.outputs.version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-
|
||||
|
||||
- name: End build cache restore group
|
||||
shell: bash
|
||||
run: echo "::endgroup::"
|
||||
|
||||
@@ -20,7 +20,7 @@ jobs:
|
||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||
|
||||
- name: Install Lix
|
||||
uses: https://github.com/samueldr/lix-gha-installer-action@7b7f14d320d6aacfb65bd1ef761566b3b69e474c
|
||||
uses: https://github.com/samueldr/lix-gha-installer-action@f5e94192f565f53d84f41a056956dc0d3183b343
|
||||
with:
|
||||
extra_nix_config: experimental-features = nix-command flakes flake-self-attrs
|
||||
|
||||
|
||||
Generated
+13
@@ -948,10 +948,12 @@ dependencies = [
|
||||
"conduwuit_build_metadata",
|
||||
"conduwuit_core",
|
||||
"conduwuit_database",
|
||||
"conduwuit_macros",
|
||||
"conduwuit_router",
|
||||
"conduwuit_service",
|
||||
"console-subscriber",
|
||||
"const-str",
|
||||
"ctor",
|
||||
"hardened_malloc-rs",
|
||||
"log",
|
||||
"opentelemetry",
|
||||
@@ -981,6 +983,7 @@ dependencies = [
|
||||
"conduwuit_macros",
|
||||
"conduwuit_service",
|
||||
"const-str",
|
||||
"ctor",
|
||||
"futures",
|
||||
"lettre",
|
||||
"log",
|
||||
@@ -1003,8 +1006,10 @@ dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"conduwuit_core",
|
||||
"conduwuit_macros",
|
||||
"conduwuit_service",
|
||||
"const-str",
|
||||
"ctor",
|
||||
"futures",
|
||||
"hmac",
|
||||
"http",
|
||||
@@ -1030,6 +1035,7 @@ name = "conduwuit_build_metadata"
|
||||
version = "0.5.7-alpha.1"
|
||||
dependencies = [
|
||||
"built",
|
||||
"cargo_metadata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1102,7 +1108,9 @@ version = "0.5.7-alpha.1"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"conduwuit_core",
|
||||
"conduwuit_macros",
|
||||
"const-str",
|
||||
"ctor",
|
||||
"futures",
|
||||
"log",
|
||||
"minicbor",
|
||||
@@ -1118,6 +1126,7 @@ dependencies = [
|
||||
name = "conduwuit_macros"
|
||||
version = "0.5.7-alpha.1"
|
||||
dependencies = [
|
||||
"cargo_toml",
|
||||
"itertools 0.14.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1136,9 +1145,11 @@ dependencies = [
|
||||
"conduwuit_admin",
|
||||
"conduwuit_api",
|
||||
"conduwuit_core",
|
||||
"conduwuit_macros",
|
||||
"conduwuit_service",
|
||||
"conduwuit_web",
|
||||
"const-str",
|
||||
"ctor",
|
||||
"futures",
|
||||
"http",
|
||||
"http-body-util",
|
||||
@@ -1169,7 +1180,9 @@ dependencies = [
|
||||
"bytes",
|
||||
"conduwuit_core",
|
||||
"conduwuit_database",
|
||||
"conduwuit_macros",
|
||||
"const-str",
|
||||
"ctor",
|
||||
"either",
|
||||
"futures",
|
||||
"governor",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Added admin commands to get build information and features. Contributed by @Jade
|
||||
@@ -0,0 +1 @@
|
||||
Fixed restricted joins not being signed when we are being used as an authorising server. Contributed by @nex, reported by [vel](matrix:u/vel:nhjkl.com?action=chat).
|
||||
@@ -527,13 +527,13 @@
|
||||
# which users must agree to when registering an account.
|
||||
#
|
||||
# Example:
|
||||
# ```
|
||||
# ```ignore
|
||||
# [global.registration_terms.privacy_policy]
|
||||
# en = { name = "Privacy Policy", url = "https://homeserver.example/en/privacy_policy.html" }
|
||||
# es = { name = "Política de Privacidad", url = "https://homeserver.example/es/privacy_policy.html" }
|
||||
# ```
|
||||
#
|
||||
#registration_terms = false
|
||||
#registration_terms = {}
|
||||
|
||||
# Controls whether encrypted rooms and events are allowed.
|
||||
#
|
||||
|
||||
@@ -133,6 +133,18 @@ pusher service
|
||||
|
||||
Returns all the pushers for the user
|
||||
|
||||
### `!admin query pusher delete-pusher`
|
||||
|
||||
Deletes a specific pusher by ID
|
||||
|
||||
### `!admin query pusher delete-all-user`
|
||||
|
||||
Deletes all pushers for a user
|
||||
|
||||
### `!admin query pusher delete-all-device`
|
||||
|
||||
Deletes all pushers associated with a device ID
|
||||
|
||||
## `!admin query short`
|
||||
|
||||
short service
|
||||
|
||||
@@ -47,3 +47,11 @@ Restart the server
|
||||
## `!admin server shutdown`
|
||||
|
||||
Shutdown the server
|
||||
|
||||
## `!admin server list-features`
|
||||
|
||||
List features built into the server
|
||||
|
||||
## `!admin server build-info`
|
||||
|
||||
Build information
|
||||
|
||||
@@ -157,3 +157,7 @@ Force joins all local users to the specified room.
|
||||
At least 1 server admin must be in the room to reduce abuse.
|
||||
|
||||
Requires the `--yes-i-want-to-do-this` flag.
|
||||
|
||||
## `!admin users reset-push-rules`
|
||||
|
||||
Resets the push-rules (notification settings) of the target user to the server defaults
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_admin"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -79,6 +80,7 @@ conduwuit-database.workspace = true
|
||||
conduwuit-macros.workspace = true
|
||||
conduwuit-service.workspace = true
|
||||
const-str.workspace = true
|
||||
ctor.workspace = true
|
||||
futures.workspace = true
|
||||
lettre.workspace = true
|
||||
log.workspace = true
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#![allow(clippy::enum_glob_use)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
pub(crate) mod admin;
|
||||
pub(crate) mod context;
|
||||
pub(crate) mod processor;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::{fmt::Write, path::PathBuf, sync::Arc};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Result,
|
||||
@@ -153,3 +153,97 @@ pub(super) async fn shutdown(&self) -> Result {
|
||||
|
||||
self.write_str("Shutting down server...").await
|
||||
}
|
||||
|
||||
#[admin_command]
|
||||
pub(super) async fn list_features(&self) -> Result {
|
||||
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.iter()
|
||||
.flat_map(|(_, f)| f.iter())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
enabled_features.sort_unstable();
|
||||
enabled_features.dedup();
|
||||
|
||||
let mut available_features = conduwuit::build_metadata::WORKSPACE_FEATURES
|
||||
.iter()
|
||||
.flat_map(|(_, f)| f.iter())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
available_features.sort_unstable();
|
||||
available_features.dedup();
|
||||
|
||||
let mut features = String::new();
|
||||
|
||||
for feature in available_features {
|
||||
let active = enabled_features.contains(&feature);
|
||||
let emoji = if active { "✅" } else { "❌" };
|
||||
let remark = if active { "[enabled]" } else { "" };
|
||||
writeln!(features, "{emoji} {feature} {remark}")?;
|
||||
}
|
||||
|
||||
self.write_str(&features).await
|
||||
}
|
||||
|
||||
#[admin_command]
|
||||
pub(super) async fn build_info(&self) -> Result {
|
||||
use conduwuit::build_metadata::built;
|
||||
|
||||
let mut info = String::new();
|
||||
|
||||
// Version information
|
||||
writeln!(info, "# Build Information\n")?;
|
||||
writeln!(info, "**Version:** {}", built::PKG_VERSION)?;
|
||||
writeln!(info, "**Package:** {}", built::PKG_NAME)?;
|
||||
writeln!(info, "**Description:** {}", built::PKG_DESCRIPTION)?;
|
||||
|
||||
// Git information
|
||||
writeln!(info, "\n## Git Information\n")?;
|
||||
if let Some(hash) = conduwuit::build_metadata::GIT_COMMIT_HASH {
|
||||
writeln!(info, "**Commit Hash:** {hash}")?;
|
||||
}
|
||||
if let Some(hash) = conduwuit::build_metadata::GIT_COMMIT_HASH_SHORT {
|
||||
writeln!(info, "**Commit Hash (short):** {hash}")?;
|
||||
}
|
||||
if let Some(url) = conduwuit::build_metadata::GIT_REMOTE_WEB_URL {
|
||||
writeln!(info, "**Repository:** {url}")?;
|
||||
}
|
||||
if let Some(url) = conduwuit::build_metadata::GIT_REMOTE_COMMIT_URL {
|
||||
writeln!(info, "**Commit URL:** {url}")?;
|
||||
}
|
||||
|
||||
// Build environment
|
||||
writeln!(info, "\n## Build Environment\n")?;
|
||||
writeln!(info, "**Profile:** {}", built::PROFILE)?;
|
||||
writeln!(info, "**Optimization Level:** {}", built::OPT_LEVEL)?;
|
||||
writeln!(info, "**Debug:** {}", built::DEBUG)?;
|
||||
writeln!(info, "**Target:** {}", built::TARGET)?;
|
||||
writeln!(info, "**Host:** {}", built::HOST)?;
|
||||
|
||||
// Rust compiler information
|
||||
writeln!(info, "\n## Compiler Information\n")?;
|
||||
writeln!(info, "**Rustc Version:** {}", built::RUSTC_VERSION)?;
|
||||
if !built::RUSTDOC_VERSION.is_empty() {
|
||||
writeln!(info, "**Rustdoc Version:** {}", built::RUSTDOC_VERSION)?;
|
||||
}
|
||||
|
||||
// Target configuration
|
||||
writeln!(info, "\n## Target Configuration\n")?;
|
||||
writeln!(info, "**Architecture:** {}", built::CFG_TARGET_ARCH)?;
|
||||
writeln!(info, "**OS:** {}", built::CFG_OS)?;
|
||||
writeln!(info, "**Family:** {}", built::CFG_FAMILY)?;
|
||||
writeln!(info, "**Endianness:** {}", built::CFG_ENDIAN)?;
|
||||
writeln!(info, "**Pointer Width:** {} bits", built::CFG_POINTER_WIDTH)?;
|
||||
if !built::CFG_ENV.is_empty() {
|
||||
writeln!(info, "**Environment:** {}", built::CFG_ENV)?;
|
||||
}
|
||||
|
||||
// CI information
|
||||
if let Some(ci) = built::CI_PLATFORM {
|
||||
writeln!(info, "\n## CI Platform\n")?;
|
||||
writeln!(info, "**Platform:** {ci}")?;
|
||||
}
|
||||
|
||||
self.write_str(&info).await
|
||||
}
|
||||
|
||||
@@ -52,4 +52,10 @@ pub enum ServerCommand {
|
||||
|
||||
/// Shutdown the server
|
||||
Shutdown,
|
||||
|
||||
/// List features built into the server
|
||||
ListFeatures,
|
||||
|
||||
/// Build information
|
||||
BuildInfo,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_api"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -76,8 +77,10 @@ axum.workspace = true
|
||||
base64.workspace = true
|
||||
bytes.workspace = true
|
||||
conduwuit-core.workspace = true
|
||||
conduwuit-macros.workspace = true
|
||||
conduwuit-service.workspace = true
|
||||
const-str.workspace = true
|
||||
ctor.workspace = true
|
||||
futures.workspace = true
|
||||
hmac.workspace = true
|
||||
http.workspace = true
|
||||
|
||||
+25
-56
@@ -1,9 +1,7 @@
|
||||
use std::iter::once;
|
||||
|
||||
use axum::extract::State;
|
||||
use axum_client_ip::InsecureClientIp;
|
||||
use conduwuit::{
|
||||
Err, Event, Result, RoomVersion, err, info,
|
||||
Err, Event, Result, err, info,
|
||||
utils::{
|
||||
TryFutureExtExt,
|
||||
math::Expected,
|
||||
@@ -32,14 +30,12 @@ use ruma::{
|
||||
events::{
|
||||
StateEventType,
|
||||
room::{
|
||||
create::RoomCreateEventContent,
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
||||
},
|
||||
},
|
||||
uint,
|
||||
};
|
||||
use tokio::join;
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
@@ -343,63 +339,36 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||
})
|
||||
}
|
||||
|
||||
/// Checks whether the given user ID is allowed to publish the target room to
|
||||
/// the server's public room directory. Users are allowed to publish rooms if
|
||||
/// they are server admins, room creators (in v12), or have the power level to
|
||||
/// send `m.room.canonical_alias`.
|
||||
/// Check whether the user can publish to the room directory via power levels of
|
||||
/// room history visibility event or room creator
|
||||
async fn user_can_publish_room(
|
||||
services: &Services,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
if services.users.is_admin(user_id).await {
|
||||
// Server admins can always publish to their own room directory.
|
||||
return Ok(true);
|
||||
}
|
||||
let (create_event, room_version, power_levels_content) = join!(
|
||||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, ""),
|
||||
services.rooms.state.get_room_version(room_id),
|
||||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get_content::<RoomPowerLevelsEventContent>(
|
||||
room_id,
|
||||
&StateEventType::RoomPowerLevels,
|
||||
""
|
||||
)
|
||||
);
|
||||
let room_version = room_version
|
||||
.as_ref()
|
||||
.map_err(|_| err!(Request(NotFound("Unknown room"))))?;
|
||||
let create_event = create_event.map_err(|_| err!(Request(NotFound("Unknown room"))))?;
|
||||
if RoomVersion::new(room_version)
|
||||
.expect("room version must be supported")
|
||||
.explicitly_privilege_room_creators
|
||||
match services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomPowerLevels, "")
|
||||
.await
|
||||
{
|
||||
let create_content: RoomCreateEventContent =
|
||||
serde_json::from_str(create_event.content().get())
|
||||
.map_err(|_| err!(Database("Invalid event content for m.room.create")))?;
|
||||
let is_creator = create_content
|
||||
.additional_creators
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.chain(once(create_event.sender().to_owned()))
|
||||
.any(|sender| sender == user_id);
|
||||
if is_creator {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
match power_levels_content.map(RoomPowerLevels::from) {
|
||||
| Ok(pl) => Ok(pl.user_can_send_state(user_id, StateEventType::RoomCanonicalAlias)),
|
||||
| Err(e) =>
|
||||
if e.is_not_found() {
|
||||
Ok(create_event.sender() == user_id)
|
||||
} else {
|
||||
Err!(Database("Invalid event content for m.room.power_levels: {e}"))
|
||||
},
|
||||
| Ok(event) => serde_json::from_str(event.content().get())
|
||||
.map_err(|_| err!(Database("Invalid event content for m.room.power_levels")))
|
||||
.map(|content: RoomPowerLevelsEventContent| {
|
||||
RoomPowerLevels::from(content)
|
||||
.user_can_send_state(user_id, StateEventType::RoomHistoryVisibility)
|
||||
}),
|
||||
| _ => {
|
||||
match services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")
|
||||
.await
|
||||
{
|
||||
| Ok(event) => Ok(event.sender() == user_id),
|
||||
| _ => Err!(Request(Forbidden("User is not allowed to publish this room"))),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
extern crate conduwuit_core as conduwuit;
|
||||
extern crate conduwuit_service as service;
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
pub mod client;
|
||||
pub mod router;
|
||||
pub mod server;
|
||||
|
||||
@@ -71,7 +71,7 @@ async fn create_join_event(
|
||||
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
||||
|
||||
trace!("Generating event ID and converting to canonical json");
|
||||
let Ok((event_id, value)) = gen_event_id_canonical_json(pdu, &room_version_id) else {
|
||||
let Ok((event_id, mut value)) = gen_event_id_canonical_json(pdu, &room_version_id) else {
|
||||
// Event could not be converted to canonical json
|
||||
return Err!(Request(BadJson("Could not convert event to canonical json.")));
|
||||
};
|
||||
@@ -187,6 +187,13 @@ async fn create_join_event(
|
||||
"Joining user did not pass restricted room's rules."
|
||||
)));
|
||||
}
|
||||
|
||||
services
|
||||
.server_keys
|
||||
.hash_and_sign_event(&mut value, &room_version_id)
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam(warn!("Failed to sign send_join event: {e}"))))
|
||||
})?;
|
||||
}
|
||||
|
||||
let mutex_lock = services
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_build_metadata"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -27,6 +28,6 @@ crate-type = [
|
||||
|
||||
[build-dependencies]
|
||||
built = { version = "0.8", features = [] }
|
||||
|
||||
cargo_metadata = { version = "0.23.1" }
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use std::process::Command;
|
||||
use std::{
|
||||
collections::BTreeMap, env, fmt::Write as FmtWrite, fs, io::Write, path::Path,
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use cargo_metadata::MetadataCommand;
|
||||
fn run_git_command(args: &[&str]) -> Option<String> {
|
||||
Command::new("git")
|
||||
.args(args)
|
||||
@@ -11,12 +15,60 @@ fn run_git_command(args: &[&str]) -> Option<String> {
|
||||
.filter(|s| !s.is_empty())
|
||||
}
|
||||
fn get_env(env_var: &str) -> Option<String> {
|
||||
match std::env::var(env_var) {
|
||||
match env::var(env_var) {
|
||||
| Ok(val) if !val.is_empty() => Some(val),
|
||||
| _ => None,
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=Cargo.toml");
|
||||
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); // Cargo.toml path
|
||||
let manifest_path = Path::new(&manifest_dir).join("Cargo.toml");
|
||||
|
||||
let metadata = MetadataCommand::new()
|
||||
.manifest_path(&manifest_path)
|
||||
.no_deps()
|
||||
.exec()
|
||||
.expect("failed to parse `cargo metadata`");
|
||||
|
||||
let workspace_packages = metadata
|
||||
.workspace_members
|
||||
.iter()
|
||||
.map(|package| {
|
||||
let package = metadata.packages.iter().find(|p| p.id == *package).unwrap();
|
||||
println!("cargo:rerun-if-changed={}", package.manifest_path.as_str());
|
||||
package
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Extract available features from workspace packages
|
||||
let mut available_features: BTreeMap<String, Vec<String>> = BTreeMap::new();
|
||||
for package in &workspace_packages {
|
||||
let crate_name = package
|
||||
.name
|
||||
.trim_start_matches("conduwuit-")
|
||||
.replace('-', "_");
|
||||
let features: Vec<String> = package.features.keys().cloned().collect();
|
||||
if !features.is_empty() {
|
||||
available_features.insert(crate_name, features);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate Rust code for available features
|
||||
let features_code = generate_features_code(&available_features);
|
||||
let features_dst =
|
||||
Path::new(&env::var("OUT_DIR").expect("OUT_DIR not set")).join("available_features.rs");
|
||||
let mut features_file = fs::File::create(features_dst).unwrap();
|
||||
features_file.write_all(features_code.as_bytes()).unwrap();
|
||||
|
||||
let dst = Path::new(&env::var("OUT_DIR").expect("OUT_DIR not set")).join("pkg.json");
|
||||
|
||||
let mut out_file = fs::File::create(dst).unwrap();
|
||||
out_file
|
||||
.write_all(format!("{workspace_packages:?}").as_bytes())
|
||||
.unwrap();
|
||||
|
||||
// built gets the default crate from the workspace. Not sure if this is intended
|
||||
// behavior, but it's what we want.
|
||||
built::write_built_file().expect("Failed to acquire build-time information");
|
||||
@@ -91,3 +143,30 @@ fn main() {
|
||||
println!("cargo:rerun-if-env-changed=GIT_REMOTE_URL");
|
||||
println!("cargo:rerun-if-env-changed=GIT_REMOTE_COMMIT_URL");
|
||||
}
|
||||
|
||||
fn generate_features_code(features: &BTreeMap<String, Vec<String>>) -> String {
|
||||
let mut code = String::from(
|
||||
r#"
|
||||
/// All available features for workspace crates
|
||||
pub const WORKSPACE_FEATURES: &[(&str, &[&str])] = &[
|
||||
"#,
|
||||
);
|
||||
|
||||
for (crate_name, feature_list) in features {
|
||||
write!(code, " (\"{crate_name}\", &[").unwrap();
|
||||
for (i, feature) in feature_list.iter().enumerate() {
|
||||
if i > 0 {
|
||||
code.push_str(", ");
|
||||
}
|
||||
write!(code, "\"{feature}\"").unwrap();
|
||||
}
|
||||
code.push_str("]),\n");
|
||||
}
|
||||
|
||||
code.push_str(
|
||||
r#"];
|
||||
"#,
|
||||
);
|
||||
|
||||
code
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ pub mod built {
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
}
|
||||
|
||||
// Include generated available features
|
||||
// This provides: pub const WORKSPACE_FEATURES: &[(&str, &[&str])]
|
||||
include!(concat!(env!("OUT_DIR"), "/available_features.rs"));
|
||||
|
||||
pub static GIT_COMMIT_HASH: Option<&str> = option_env!("GIT_COMMIT_HASH");
|
||||
|
||||
pub static GIT_COMMIT_HASH_SHORT: Option<&str> = option_env!("GIT_COMMIT_HASH_SHORT");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_core"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
//! Information about features the crates were compiled with.
|
||||
//! Only available for crates that have called the `introspect_crate` macro
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub static ENABLED_FEATURES: std::sync::Mutex<BTreeMap<&str, &[&str]>> =
|
||||
std::sync::Mutex::new(BTreeMap::new());
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod introspection;
|
||||
pub mod room_version;
|
||||
pub mod version;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ pub use ::smallstr;
|
||||
pub use ::smallvec;
|
||||
pub use ::toml;
|
||||
pub use ::tracing;
|
||||
pub use conduwuit_build_metadata as build_metadata;
|
||||
pub use config::Config;
|
||||
pub use error::Error;
|
||||
pub use info::{
|
||||
@@ -34,6 +35,8 @@ pub use utils::{implement, result, result::Result};
|
||||
|
||||
pub use crate as conduwuit_core;
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
#[cfg(any(not(conduwuit_mods), not(feature = "conduwuit_mods")))]
|
||||
pub mod mods {
|
||||
#[macro_export]
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_database"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -54,7 +55,9 @@ bindgen-runtime = [
|
||||
[dependencies]
|
||||
async-channel.workspace = true
|
||||
conduwuit-core.workspace = true
|
||||
conduwuit-macros.workspace = true
|
||||
const-str.workspace = true
|
||||
ctor.workspace = true
|
||||
futures.workspace = true
|
||||
log.workspace = true
|
||||
minicbor.workspace = true
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
extern crate conduwuit_core as conduwuit;
|
||||
extern crate rust_rocksdb as rocksdb;
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
conduwuit::mod_ctor! {}
|
||||
conduwuit::mod_dtor! {}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_macros"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -17,6 +18,7 @@ syn.workspace = true
|
||||
quote.workspace = true
|
||||
proc-macro2.workspace = true
|
||||
itertools.workspace = true
|
||||
cargo_toml.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::Result;
|
||||
|
||||
pub(super) fn introspect(_args: TokenStream) -> Result<TokenStream> {
|
||||
let cargo_crate_name = std::env::var("CARGO_CRATE_NAME").unwrap();
|
||||
let crate_name = cargo_crate_name.trim_start_matches("conduwuit_");
|
||||
let is_core = cargo_crate_name == "conduwuit_core";
|
||||
|
||||
let flags = std::env::args().collect::<Vec<_>>();
|
||||
|
||||
let mut enabled_features = Vec::new();
|
||||
append_features(&mut enabled_features, flags);
|
||||
|
||||
let enabled_count = enabled_features.len();
|
||||
|
||||
let import_path = if is_core {
|
||||
quote! { use crate::conduwuit_core; }
|
||||
} else {
|
||||
quote! { use ::conduwuit_core; }
|
||||
};
|
||||
|
||||
let ret = quote! {
|
||||
#[doc(hidden)]
|
||||
mod __compile_introspection {
|
||||
#import_path
|
||||
|
||||
/// Features that were enabled when this crate was compiled
|
||||
const ENABLED: [&str; #enabled_count] = [#( #enabled_features ),*];
|
||||
|
||||
const CRATE_NAME: &str = #crate_name;
|
||||
|
||||
/// Register this crate's features with the global registry during static initialization
|
||||
#[::ctor::ctor]
|
||||
fn register() {
|
||||
conduwuit_core::info::introspection::ENABLED_FEATURES.lock().unwrap().insert(#crate_name, &ENABLED);
|
||||
}
|
||||
#[::ctor::dtor]
|
||||
fn unregister() {
|
||||
conduwuit_core::info::introspection::ENABLED_FEATURES.lock().unwrap().remove(#crate_name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
fn append_features(features: &mut Vec<String>, flags: Vec<String>) {
|
||||
let mut next_is_cfg = false;
|
||||
for flag in flags {
|
||||
let is_cfg = flag == "--cfg";
|
||||
let is_feature = flag.starts_with("feature=");
|
||||
if std::mem::replace(&mut next_is_cfg, is_cfg) && is_feature {
|
||||
if let Some(feature) = flag
|
||||
.split_once('=')
|
||||
.map(|(_, feature)| feature.trim_matches('"'))
|
||||
{
|
||||
features.push(feature.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
mod admin;
|
||||
mod build_info;
|
||||
mod config;
|
||||
mod debug;
|
||||
mod implement;
|
||||
@@ -44,6 +45,13 @@ pub fn config_example_generator(args: TokenStream, input: TokenStream) -> TokenS
|
||||
attribute_macro::<ItemStruct, _>(args, input, config::example_generator)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn introspect_crate(input: TokenStream) -> TokenStream {
|
||||
build_info::introspect(input.into())
|
||||
.unwrap_or_else(|e| e.to_compile_error())
|
||||
.into()
|
||||
}
|
||||
|
||||
fn attribute_macro<I, F>(args: TokenStream, input: TokenStream, func: F) -> TokenStream
|
||||
where
|
||||
F: Fn(I, &[Meta]) -> Result<TokenStream>,
|
||||
|
||||
@@ -207,8 +207,10 @@ conduwuit-database.workspace = true
|
||||
conduwuit-router.workspace = true
|
||||
conduwuit-service.workspace = true
|
||||
conduwuit-build-metadata.workspace = true
|
||||
conduwuit-macros.workspace = true
|
||||
|
||||
clap.workspace = true
|
||||
ctor.workspace = true
|
||||
console-subscriber.optional = true
|
||||
console-subscriber.workspace = true
|
||||
const-str.workspace = true
|
||||
|
||||
@@ -4,6 +4,8 @@ use std::sync::{Arc, atomic::Ordering};
|
||||
|
||||
use conduwuit_core::{debug_info, error};
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
mod clap;
|
||||
mod deadlock;
|
||||
mod logging;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_router"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -99,9 +100,11 @@ bytes.workspace = true
|
||||
conduwuit-admin.workspace = true
|
||||
conduwuit-api.workspace = true
|
||||
conduwuit-core.workspace = true
|
||||
conduwuit-macros.workspace = true
|
||||
conduwuit-service.workspace = true
|
||||
conduwuit-web.workspace = true
|
||||
const-str.workspace = true
|
||||
ctor.workspace = true
|
||||
futures.workspace = true
|
||||
http.workspace = true
|
||||
http-body-util.workspace = true
|
||||
|
||||
@@ -8,6 +8,8 @@ mod serve;
|
||||
|
||||
extern crate conduwuit_core as conduwuit;
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
use std::{panic::AssertUnwindSafe, pin::Pin, sync::Arc};
|
||||
|
||||
use conduwuit::{Error, Result, Server};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_service"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
@@ -88,7 +89,9 @@ base64.workspace = true
|
||||
bytes.workspace = true
|
||||
conduwuit-core.workspace = true
|
||||
conduwuit-database.workspace = true
|
||||
conduwuit-macros.workspace = true
|
||||
const-str.workspace = true
|
||||
ctor.workspace = true
|
||||
either.workspace = true
|
||||
futures.workspace = true
|
||||
governor.workspace = true
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
extern crate conduwuit_core as conduwuit;
|
||||
extern crate conduwuit_database as database;
|
||||
|
||||
conduwuit_macros::introspect_crate! {}
|
||||
|
||||
mod manager;
|
||||
mod migrations;
|
||||
mod service;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "conduwuit_web"
|
||||
description.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
Reference in New Issue
Block a user