Skip to content

Commit dda3167

Browse files
committed
mostly applied
1 parent 609f595 commit dda3167

File tree

9 files changed

+176
-117
lines changed

9 files changed

+176
-117
lines changed

packages/cli/src/build/builder.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub(crate) struct Builder {
1919
pub krate: DioxusCrate,
2020
pub request: BuildRequest,
2121
pub build: tokio::task::JoinHandle<Result<AppBundle>>,
22-
pub bundle: tokio::task::JoinHandle<Result<AppBundle>>,
2322
pub tx: ProgressTx,
2423
pub rx: ProgressRx,
2524

@@ -49,13 +48,10 @@ impl Builder {
4948
request: request.clone(),
5049
stage: BuildStage::Initializing,
5150
build: tokio::spawn(async move {
52-
// On the first build, we want to verify the tooling
53-
// We wont bother verifying on subsequent builds
51+
// On the first build, we want to verify the tooling... don't bother on subsequent builds
5452
request.verify_tooling().await?;
55-
5653
request.build_all().await
5754
}),
58-
bundle: tokio::spawn(async move { futures_util::future::pending().await }),
5955
tx,
6056
rx,
6157
compiled_crates: 0,
@@ -186,7 +182,7 @@ impl Builder {
186182
self.abort_all();
187183

188184
// And then start a new build, resetting our progress/stage to the beginning and replacing the old tokio task
189-
let request = BuildRequest::new(self.krate.clone(), args, self.tx.clone(), BuildMode::Fat);
185+
let request = BuildRequest::new(self.krate.clone(), args, self.tx.clone(), BuildMode::Thin);
190186
self.request = request.clone();
191187
self.stage = BuildStage::Restarting;
192188

packages/cli/src/build/bundle.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ pub(crate) struct AppBundle {
9595
pub(crate) server_assets: Option<AssetManifest>,
9696
}
9797

98+
#[derive(Debug)]
99+
pub struct UnbundledApp {
100+
pub(crate) request: BuildRequest,
101+
pub(crate) app: BuildArtifacts,
102+
pub(crate) server: Option<BuildArtifacts>,
103+
}
104+
98105
/// The result of the `cargo rustc` including any additional metadata
99106
#[derive(Debug)]
100107
pub struct BuildArtifacts {
@@ -300,11 +307,6 @@ impl AppBundle {
300307
Ok(bundle)
301308
}
302309

303-
/// Apply this build as a patch to the given bundle
304-
pub(crate) async fn write_patch(&mut self, exe: &Path) -> Result<()> {
305-
Ok(())
306-
}
307-
308310
/// Traverse the target directory and collect all assets from the incremental cache
309311
///
310312
/// This uses "known paths" that have stayed relatively stable during cargo's lifetime.

packages/cli/src/build/patch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct PatchData {
3131
}
3232

3333
pub async fn attempt_partial_link(
34+
linker: PathBuf,
3435
work_dir: PathBuf,
3536
old_cache: PathBuf,
3637
new_cache: PathBuf,

packages/cli/src/build/request.rs

+119-68
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum BuildMode {
4343
Fat,
4444

4545
/// A "thin" build generated with `rustc` directly and dx as a custom linker
46-
Thin { rustc_args: Vec<String> },
46+
Thin,
4747
}
4848

4949
pub struct CargoBuildResult {
@@ -82,25 +82,21 @@ impl BuildRequest {
8282
);
8383

8484
let (app, server) = match self.build.force_sequential {
85-
true => self.build_sequential().await?,
86-
false => self.build_concurrent().await?,
85+
true => futures_util::future::try_join(self.cargo_build(), self.build_server()).await?,
86+
false => (self.cargo_build().await?, self.build_server().await?),
8787
};
8888

89-
AppBundle::new(self, app, server).await
90-
}
91-
92-
/// Run the build command with a pretty loader, returning the executable output location
93-
async fn build_concurrent(&self) -> Result<(BuildArtifacts, Option<BuildArtifacts>)> {
94-
let (app, server) =
95-
futures_util::future::try_join(self.cargo_build(), self.build_server()).await?;
89+
// let mut app_bundle = AppBundle::new {
90+
// app,
91+
// server,
92+
// build: self,
93+
// assets: Default::default(),
94+
// server_assets: Default::default(),
95+
// };
9696

97-
Ok((app, server))
98-
}
97+
// Ok(app_bundle)
9998

100-
async fn build_sequential(&self) -> Result<(BuildArtifacts, Option<BuildArtifacts>)> {
101-
let app = self.cargo_build().await?;
102-
let server = self.build_server().await?;
103-
Ok((app, server))
99+
todo!()
104100
}
105101

106102
pub(crate) async fn build_server(&self) -> Result<Option<BuildArtifacts>> {
@@ -235,58 +231,47 @@ impl BuildRequest {
235231

236232
pub(crate) async fn build_thin_rustc(&self) {}
237233

238-
// #[tracing::instrument(
239-
// skip(self),
240-
// level = "trace",
241-
// name = "BuildRequest::assemble_build_command"
242-
// )]
234+
#[tracing::instrument(
235+
skip(self),
236+
level = "trace",
237+
fields(dx_src = ?TraceSrc::Build)
238+
)]
243239
fn assemble_build_command(&self) -> Result<Command> {
244-
let mut cmd = match &self.mode {
245-
BuildMode::Fat | BuildMode::Base => {
246-
let mut cmd = Command::new("cargo");
247-
cmd.arg("rustc")
248-
.current_dir(self.krate.crate_dir())
249-
.arg("--message-format")
250-
.arg("json-diagnostic-rendered-ansi")
251-
.args(self.build_arguments())
252-
.envs(self.env_vars()?);
253-
cmd
254-
}
255-
BuildMode::Thin { rustc_args } => {
256-
let mut cmd = Command::new(rustc_args[0].clone());
257-
cmd.args(rustc_args[1..].iter())
258-
.env(
259-
LinkAction::ENV_VAR_NAME,
260-
LinkAction::FatLink {
261-
platform: self.build.platform(),
262-
linker: None,
263-
incremental_dir: self.incremental_cache_dir(),
264-
}
265-
.to_json(),
266-
)
267-
.stdout(Stdio::piped())
268-
.stderr(Stdio::piped());
269-
cmd
270-
}
271-
};
272-
273-
if let Some(target_dir) = self.custom_target_dir.as_ref() {
274-
cmd.env("CARGO_TARGET_DIR", target_dir);
275-
}
276-
277-
if self.build.platform() == Platform::Android {
278-
let ndk = self
279-
.krate
280-
.android_ndk()
281-
.context("Could not autodetect android linker")?;
282-
let arch = self.build.target_args.arch();
283-
let linker = arch.android_linker(&ndk);
284-
285-
cmd.env(
286-
LinkAction::ENV_VAR_NAME,
287-
LinkAction::LinkAndroid { linker }.to_json(),
288-
);
289-
}
240+
// let mut cmd = match &self.mode {
241+
// BuildMode::Fat | BuildMode::Base => {
242+
// let mut cmd = Command::new("cargo");
243+
// cmd.arg("rustc")
244+
// .current_dir(self.krate.crate_dir())
245+
// .arg("--message-format")
246+
// .arg("json-diagnostic-rendered-ansi")
247+
// .args(self.build_arguments())
248+
// .envs(self.env_vars()?);
249+
// cmd
250+
// } // BuildMode::Thin { rustc_args } => {
251+
// // let mut cmd = Command::new(rustc_args[0].clone());
252+
// // cmd.args(rustc_args[1..].iter())
253+
// // .env(
254+
// // LinkAction::ENV_VAR_NAME,
255+
// // LinkAction::FatLink {
256+
// // platform: self.build.platform(),
257+
// // linker: None,
258+
// // incremental_dir: self.incremental_cache_dir(),
259+
// // }
260+
// // .to_json(),
261+
// // )
262+
// // .stdout(Stdio::piped())
263+
// // .stderr(Stdio::piped());
264+
// // cmd
265+
// // }
266+
// };
267+
268+
let mut cmd = Command::new("cargo");
269+
cmd.arg("rustc")
270+
.current_dir(self.krate.crate_dir())
271+
.arg("--message-format")
272+
.arg("json-diagnostic-rendered-ansi")
273+
.args(self.build_arguments())
274+
.envs(self.env_vars()?);
290275

291276
Ok(cmd)
292277
}
@@ -372,14 +357,25 @@ impl BuildRequest {
372357

373358
cargo_args.push(self.krate.executable_name().to_string());
374359

360+
cargo_args.push("--".to_string());
361+
375362
// the bundle splitter needs relocation data
376363
// we'll trim these out if we don't need them during the bundling process
377364
// todo(jon): for wasm binary patching we might want to leave these on all the time.
378365
if self.build.platform() == Platform::Web && self.build.experimental_wasm_split {
379-
cargo_args.push("--".to_string());
380366
cargo_args.push("-Clink-args=--emit-relocs".to_string());
381367
}
382368

369+
match self.mode {
370+
BuildMode::Fat | BuildMode::Thin => cargo_args.push(format!(
371+
"-Clinker={}",
372+
dunce::canonicalize(std::env::current_exe().unwrap())
373+
.unwrap()
374+
.display()
375+
)),
376+
_ => {}
377+
}
378+
383379
tracing::debug!(dx_src = ?TraceSrc::Build, "cargo args: {:?}", cargo_args);
384380

385381
cargo_args
@@ -556,6 +552,57 @@ impl BuildRequest {
556552
// env_vars.push(("PATH", extended_path));
557553
};
558554

555+
let linker = match self.build.platform() {
556+
Platform::Web => todo!(),
557+
Platform::MacOS => todo!(),
558+
Platform::Windows => todo!(),
559+
Platform::Linux => todo!(),
560+
Platform::Ios => todo!(),
561+
Platform::Android => todo!(),
562+
Platform::Server => todo!(),
563+
Platform::Liveview => todo!(),
564+
};
565+
566+
let custom_linker = if self.build.platform() == Platform::Android {
567+
let ndk = self
568+
.krate
569+
.android_ndk()
570+
.context("Could not autodetect android linker")?;
571+
572+
let linker = self.build.target_args.arch().android_linker(&ndk);
573+
Some(linker)
574+
} else {
575+
None
576+
};
577+
578+
match &self.mode {
579+
BuildMode::Base | BuildMode::Fat => env_vars.push((
580+
LinkAction::ENV_VAR_NAME,
581+
LinkAction::BaseLink {
582+
platform: self.build.platform(),
583+
linker: "cc".into(),
584+
incremental_dir: self.incremental_cache_dir(),
585+
strip: matches!(self.mode, BuildMode::Base),
586+
}
587+
.to_json(),
588+
)),
589+
BuildMode::Thin => env_vars.push((
590+
LinkAction::ENV_VAR_NAME,
591+
LinkAction::ThinLink {
592+
platform: self.build.platform(),
593+
linker: "cc".into(),
594+
incremental_dir: self.incremental_cache_dir(),
595+
main_ptr: todo!(),
596+
patch_target: todo!(),
597+
}
598+
.to_json(),
599+
)),
600+
}
601+
602+
if let Some(target_dir) = self.custom_target_dir.as_ref() {
603+
env_vars.push(("CARGO_TARGET_DIR", target_dir.display().to_string()));
604+
}
605+
559606
// If this is a release build, bake the base path and title
560607
// into the binary with env vars
561608
if self.build.release {
@@ -988,4 +1035,8 @@ impl BuildRequest {
9881035

9891036
todo!()
9901037
}
1038+
1039+
pub(crate) fn is_patch(&self) -> bool {
1040+
matches!(&self.mode, BuildMode::Thin { .. })
1041+
}
9911042
}

packages/cli/src/cli/link.rs

+11-24
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ use tokio::process::Command;
55

66
#[derive(Debug, Serialize, Deserialize)]
77
pub enum LinkAction {
8-
LinkAndroid {
9-
linker: PathBuf,
10-
},
11-
FatLink {
8+
BaseLink {
9+
strip: bool,
1210
platform: Platform,
13-
linker: Option<PathBuf>,
11+
linker: PathBuf,
1412
incremental_dir: PathBuf,
1513
},
1614
ThinLink {
1715
platform: Platform,
1816
main_ptr: u64,
1917
patch_target: PathBuf,
18+
linker: PathBuf,
2019
incremental_dir: PathBuf,
2120
},
2221
}
@@ -45,30 +44,19 @@ impl LinkAction {
4544
let args = std::env::args().collect::<Vec<String>>();
4645

4746
match self {
48-
// Run the android linker passed to us via the env var
49-
LinkAction::LinkAndroid { linker } => {
50-
let mut cmd = std::process::Command::new(linker);
51-
cmd.args(std::env::args().skip(1));
52-
cmd.stderr(std::process::Stdio::piped())
53-
.stdout(std::process::Stdio::piped())
54-
.status()
55-
.expect("Failed to run android linker");
56-
}
57-
58-
// Run the system linker but keep any unused sections.
59-
//
60-
// This ensures our thin link will work against the binaries built here.
61-
LinkAction::FatLink {
47+
// Run the system linker but (maybe) keep any unused sections.
48+
LinkAction::BaseLink {
6249
platform,
6350
incremental_dir,
6451
linker,
52+
strip,
6553
} => {
6654
// Make sure we *don't* dead-strip the binary so every library symbol still exists.
6755
// This is required for thin linking to work correctly.
6856
let args = args
6957
.into_iter()
7058
.skip(1)
71-
.filter(|arg| arg != "-Wl,-dead_strip")
59+
.filter(|arg| arg != "-Wl,-dead_strip" && !strip)
7260
.collect::<Vec<String>>();
7361

7462
// Persist the cache of incremental files
@@ -82,15 +70,13 @@ impl LinkAction {
8270
);
8371

8472
// Run ld with the args
85-
let res = Command::new(linker.unwrap_or("cc".into()))
86-
.args(args)
87-
.output()
88-
.await?;
73+
let res = Command::new(linker).args(args).output().await?;
8974
let err = String::from_utf8_lossy(&res.stderr);
9075
}
9176

9277
// Run the linker but without rlibs
9378
LinkAction::ThinLink {
79+
linker,
9480
platform,
9581
patch_target,
9682
incremental_dir,
@@ -107,6 +93,7 @@ impl LinkAction {
10793
);
10894

10995
crate::build::attempt_partial_link(
96+
linker,
11097
incremental_dir.clone(),
11198
incremental_dir.join("old"),
11299
incremental_dir.join("new"),

0 commit comments

Comments
 (0)