< 返回版块

Gongwang666 发表于 2020-06-23 22:44

Tags:rust,编译,差异

main.rs

use actix_web::{web, App, Responder, HttpServer};

async fn index() -> impl Responder {
    "Hello world!"
}

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().service(
            web::scope("/app").route("/index.html", web::get().to(index)),
        )
    })
        .bind("127.0.0.1:8088")?
        .run()
        .await
}

Cargo.toml

[package]
name = "test1"
version = "0.1.0"
authors = ["123456"]
edition = "2018"




[dependencies]
actix-web = "=2.0.0"
actix-rt = "=1.0.0"

同一linux环境不同时间编译出release的二进制可执行文件,使用Beyond Compare对比二进制文件,发现存在差异。经过定位,差异是由actix-server-1.0.2中的service.rs文件中如下代码导致。

impl<F, Io> InternalServiceFactory for StreamNewService<F, Io>
where
    F: ServiceFactory<Io>,
    Io: FromStream + Send + 'static,
{
    fn name(&self, _: Token) -> &str {
        &self.name
    }

    fn clone_factory(&self) -> Box<dyn InternalServiceFactory> {
        Box::new(Self {
            name: self.name.clone(),
            inner: self.inner.clone(),
            token: self.token,
            addr: self.addr,
            _t: PhantomData,
        })
    }

    fn create(&self) -> LocalBoxFuture<'static, Result<Vec<(Token, BoxedServerService)>, ()>> {
        let token = self.token;
        self.inner
            .create()
            .new_service(())
            .map_err(|_| ())
            .map_ok(move |inner| {
                let service: BoxedServerService = Box::new(StreamService::new(inner));
                vec![(token, service)]
            })
            .boxed_local()
    }
}

其中的let service: BoxedServerService = Box::new(StreamService::new(inner));会导致编译出的二进制文件出现差异。 请问各位大神,为什么会导致编译出的二进制文件出现差异。

评论区

写评论
Nalleyer 2020-06-26 09:53

路过mark一下,等大佬解答

1 共 1 条评论, 1 页