Skip to content

Don't let the build script overwrite TYPST_VERSION - #154

Merged
laurmaedje merged 2 commits into
typst:mainfrom
figsoda:version
Mar 25, 2023
Merged

laurmaedje merged 2 commits into
typst:mainfrom
figsoda:version

Conversation

@figsoda

@figsoda figsoda commented Mar 22, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@CGMossa

CGMossa commented Mar 22, 2023

Copy link
Copy Markdown
Contributor

Why is this useful? It is only set in the build.rs for the cli project, and nowhere else.

@figsoda

figsoda commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

I am trying to package typst for nixpkgs, and .git is not available by default, so this is what I ended up doing: https://github.com/nixos/nixpkgs/blob/f8cee53499c6caf3ec07d0e607121474d9f191ed/pkgs/tools/typesetting/typst/default.nix#L39-L47

@figsoda figsoda mentioned this pull request Mar 22, 2023
4 tasks done

@CGMossa CGMossa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to write this in a way, that makes the version stuff and this one unified "unit". Build scripts tend to build up fast, and having things in succinct units does help.

@figsoda

figsoda commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

Could you elaborate on the unit concept? I don't quite understand what should be done.

I tried to make the least amount of changes possible to make the nix package simpler while not affecting what's already here.

@CGMossa

CGMossa commented Mar 22, 2023

Copy link
Copy Markdown
Contributor

Suggested edit:

diff --git a/cli/build.rs b/cli/build.rs
index 1b37602f..515349ad 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -2,16 +2,17 @@ use std::process::Command;
 
 fn main() {
     println!("cargo:rerun-if-env-changed=TYPST_VERSION");
-    if option_env!("TYPST_VERSION").is_some() {
-        return;
-    }
+    let version = if let Some(version) = option_env!("TYPST_VERSION") {
+        version.into()
+    } else {
+        Command::new("git")
+            .args(&["rev-parse", "HEAD"])
+            .output()
+            .ok()
+            .and_then(|output| output.status.success().then(|| output))
+            .and_then(|output| String::from_utf8(output.stdout[..8].into()).ok())
+            .unwrap_or_else(|| "(unknown version)".into())
+    };
 
-    let version = Command::new("git")
-        .args(&["rev-parse", "HEAD"])
-        .output()
-        .ok()
-        .and_then(|output| output.status.success().then(|| output))
-        .and_then(|output| String::from_utf8(output.stdout[..8].into()).ok())
-        .unwrap_or_else(|| "(unknown version)".into());
     println!("cargo:rustc-env=TYPST_VERSION={version}");
 }

@CGMossa

CGMossa commented Mar 22, 2023

Copy link
Copy Markdown
Contributor

Damn.. I'm not sure this is strictly better... But it is a suggestion atleast 🤷‍♂️

@figsoda

figsoda commented Mar 22, 2023 •

Copy link
Copy Markdown
Contributor Author

Either way is fine with me, also applied some clippy suggestions since we are now touching that part of the code

@CGMossa CGMossa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I feel the need to point out, that I'm not part of the team.

@laurmaedje

laurmaedje commented Mar 25, 2023 •

Copy link
Copy Markdown
Member

I think the original version with return was fine and more readable. Regarding the clean up: The better version is probably:

.filter(|output| output.status.success())

The general change seems good, if it allows more flexibility for packaging, I'm all for it.

@laurmaedje
laurmaedje merged commit e70ec5f into typst:main Mar 25, 2023
@figsoda
figsoda deleted the version branch March 25, 2023 14:43
yipinliu pushed a commit to yipinliu/typst that referenced this pull request Mar 27, 2023
* 'main' of https://github.com/typst/typst: (22 commits)
  Added IPA pronunciation (typst#349)
  Cache eviction helps
  Pronunciation
  Don't let the build script overwrite TYPST_VERSION (typst#154)
  Document behaviour of dictionary.insert() when key exists (typst#282)
  Add custom font search path support for typst cli (typst#270)
  Added return type to methods of colors in docs (typst#291)
  change page numbering for outline (typst#284)
  Newton's notation for derivatives (typst#281)
  Use correct smart quotes for Norwegian Bokmål language code (typst#278)
  Fix fill color obstructing page header and background (typst#277)
  Simplify heading block example
  Fix index out of bounds error in build script (typst#173)
  Replace infinite repeat layout panic with error (typst#235)
  Changed "ColorChoice::Always" to "ColorChoice::Auto" to honour user setting of TERM / NO_COLOR (typst#230)
  Fixed Typo (typst#227)
  Fix descriptions of some types (typst#206)
  Fix import syntax in tutorial (typst#205)
  Make alignment actually centered (typst#176)
  strip cli target (typst#143)
  ...
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants